icon

package
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2022 License: Apache-2.0 Imports: 32 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultSendTransactionRetryInterval        = 3 * time.Second         //3sec
	DefaultGetTransactionResultPollingInterval = 1500 * time.Millisecond //1.5sec
)
View Source
const (
	HeaderKeyIconOptions = "Icon-Options"
	IconOptionsDebug     = "debug"
	IconOptionsTimeout   = "timeout"
)
View Source
const (
	CodeBTP      errors.Code = 0
	CodeBMC      errors.Code = 10
	CodeBMV      errors.Code = 25
	CodeBSH      errors.Code = 40
	CodeReserved errors.Code = 55
)
View Source
const (
	BMCRevert = CodeBMC + iota
	BMCRevertUnauthorized
	BMCRevertInvalidSN
	BMCRevertAlreadyExistsBMV
	BMCRevertNotExistsBMV
	BMCRevertAlreadyExistsBSH
	BMCRevertNotExistsBSH
	BMCRevertAlreadyExistsLink
	BMCRevertNotExistsLink
	BMCRevertUnreachable
	BMCRevertNotExistsPermission
)
View Source
const (
	BMVRevert = CodeBMV + iota
	BMVRevertInvalidMPT
	BMVRevertInvalidVotes
	BMVRevertInvalidSequence
	BMVRevertInvalidBlockUpdate
	BMVRevertInvalidBlockProof
	BMVRevertInvalidBlockWitness
	BMVRevertInvalidSequenceHigher
	BMVRevertInvalidBlockUpdateHigher
	BMVRevertInvalidBlockUpdateLower
	BMVRevertInvalidBlockProofHigher
	BMVRevertInvalidBlockWitnessOld
)
View Source
const (
	EventSignature      = "Message(str,int,bytes)"
	EventIndexSignature = 0
	EventIndexNext      = 1
	EventIndexSequence  = 2
	RPCCallRetry        = 5
)
View Source
const (
	VoteTypePrevote types.VoteType = iota
	VoteTypePrecommit
)
View Source
const (
	MonitorBlockMaxConcurrency = 300
)
View Source
const RECONNECT_ON_UNEXPECTED_HEIGHT = "Unexpected Block Height. Should Reconnect"

Variables

View Source
var (
	ErrConnectFail            = fmt.Errorf("fail to connect")
	ErrSendFailByExpired      = fmt.Errorf("reject by expired")
	ErrSendFailByFuture       = fmt.Errorf("reject by future")
	ErrSendFailByOverflow     = fmt.Errorf("reject by overflow")
	ErrGetResultFailByPending = fmt.Errorf("fail to getresult by pending")
)
View Source
var (
	BMCRevertCodeNames = map[errors.Code]string{
		BMCRevert:                    "BMCRevert",
		BMCRevertUnauthorized:        "BMCRevertUnauthorized",
		BMCRevertInvalidSN:           "BMCRevertInvalidSN",
		BMCRevertAlreadyExistsBMV:    "BMCRevertAlreadyExistsBMV",
		BMCRevertNotExistsBMV:        "BMCRevertNotExistsBMV",
		BMCRevertAlreadyExistsBSH:    "BMCRevertAlreadyExistsBSH",
		BMCRevertNotExistsBSH:        "BMCRevertNotExistsBSH",
		BMCRevertAlreadyExistsLink:   "BMCRevertAlreadyExistsLink",
		BMCRevertNotExistsLink:       "BMCRevertNotExistsLink",
		BMCRevertUnreachable:         "BMCRevertUnreachable",
		BMCRevertNotExistsPermission: "BMCRevertNotExistsPermission",
	}
)
View Source
var (
	BMVRevertCodeNames = map[errors.Code]string{
		BMVRevert:                         "BMVRevert",
		BMVRevertInvalidMPT:               "BMVRevertInvalidMPT",
		BMVRevertInvalidVotes:             "BMVRevertInvalidVotes",
		BMVRevertInvalidSequence:          "BMVRevertInvalidSequence",
		BMVRevertInvalidBlockUpdate:       "BMVRevertInvalidBlockUpdate",
		BMVRevertInvalidBlockProof:        "BMVRevertInvalidBlockProof",
		BMVRevertInvalidBlockWitness:      "BMVRevertInvalidBlockWitness",
		BMVRevertInvalidSequenceHigher:    "BMVRevertInvalidSequenceHigher",
		BMVRevertInvalidBlockUpdateHigher: "BMVRevertInvalidBlockUpdateHigher",
		BMVRevertInvalidBlockUpdateLower:  "BMVRevertInvalidBlockUpdateLower",
		BMVRevertInvalidBlockProofHigher:  "BMVRevertInvalidBlockProofHigher",
		BMVRevertInvalidBlockWitnessOld:   "BMVRevertInvalidBlockWitnessOld",
	}
)

Functions

func NewReceiver

func NewReceiver(src, dst chain.BTPAddress,
	urls []string, rawOpts json.RawMessage, l log.Logger) (chain.Receiver, error)

func NewRevertError

func NewRevertError(code int) error

func NewSender

func NewSender(
	src, dst chain.BTPAddress,
	urls []string, w wallet.Wallet,
	rawOpts json.RawMessage, l log.Logger) (chain.Sender, error)

NewSender ... returns a new sender client for icon

func SerializeJSON

func SerializeJSON(s []byte, in map[string]bool, exclude map[string]bool) ([]byte, error)

func SerializeMap

func SerializeMap(d map[string]interface{}, i map[string]bool, e map[string]bool) ([]byte, error)

Types

type BlockHeaderResult

type BlockHeaderResult struct {
	StateHash        []byte
	PatchReceiptHash []byte
	ReceiptHash      common.HexBytes
	ExtensionData    []byte
}

type Client

type Client struct {
	*jsonrpc.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(uri string, l log.Logger) *Client

func (*Client) Call

func (c *Client) Call(p *types.CallParam, r interface{}) error

func (*Client) CloseAllMonitor

func (c *Client) CloseAllMonitor()

func (*Client) CloseMonitor

func (c *Client) CloseMonitor(conn *websocket.Conn)

func (*Client) GetBalance

func (c *Client) GetBalance(param *types.AddressParam) (*big.Int, error)

func (*Client) GetBlockByHeight

func (c *Client) GetBlockByHeight(p *types.BlockHeightParam) (*types.Block, error)

func (*Client) GetBlockHeaderByHeight

func (c *Client) GetBlockHeaderByHeight(height int64) (*types.BlockHeader, error)

func (*Client) GetBlockHeaderBytesByHeight

func (c *Client) GetBlockHeaderBytesByHeight(p *types.BlockHeightParam) ([]byte, error)

func (*Client) GetCommitVoteListByHeight

func (c *Client) GetCommitVoteListByHeight(height int64) (*types.CommitVoteList, error)

func (*Client) GetDataByHash

func (c *Client) GetDataByHash(p *types.DataHashParam) ([]byte, error)

func (*Client) GetLastBlock

func (c *Client) GetLastBlock() (*types.Block, error)

func (*Client) GetProofForEvents

func (c *Client) GetProofForEvents(p *types.ProofEventsParam) ([][][]byte, error)

func (*Client) GetProofForResult

func (c *Client) GetProofForResult(p *types.ProofResultParam) ([][]byte, error)

func (*Client) GetTransactionResult

func (c *Client) GetTransactionResult(p *types.TransactionHashParam) (*types.TransactionResult, error)

func (*Client) GetValidatorsByHash

func (c *Client) GetValidatorsByHash(hash common.HexHash) ([]common.Address, error)

func (*Client) GetVotesByHeight

func (c *Client) GetVotesByHeight(p *types.BlockHeightParam) ([]byte, error)

func (*Client) Monitor

func (c *Client) Monitor(ctx context.Context, reqUrl string, reqPtr, respPtr interface{}, cb types.WsReadCallback) error

func (*Client) MonitorBlock

func (c *Client) MonitorBlock(ctx context.Context, p *types.BlockRequest, cb func(conn *websocket.Conn, v *types.BlockNotification) error, scb func(conn *websocket.Conn), errCb func(*websocket.Conn, error)) error

func (*Client) MonitorEvent

func (c *Client) MonitorEvent(ctx context.Context, p *types.EventRequest, cb func(conn *websocket.Conn, v *types.EventNotification) error, errCb func(*websocket.Conn, error)) error

func (*Client) SendTransaction

func (c *Client) SendTransaction(p *types.TransactionParam) (*types.HexBytes, error)

func (*Client) SendTransactionAndGetResult

func (c *Client) SendTransactionAndGetResult(p *types.TransactionParam) (*types.HexBytes, *types.TransactionResult, error)

func (*Client) SendTransactionAndWait

func (c *Client) SendTransactionAndWait(p *types.TransactionParam) (*types.HexBytes, error)

func (*Client) SignTransaction

func (c *Client) SignTransaction(w Wallet, p *types.TransactionParam) error

func (*Client) WaitForResults

func (c *Client) WaitForResults(ctx context.Context, thp *types.TransactionHashParam) (txh *types.HexBytes, txr *types.TransactionResult, err error)

func (*Client) WaitTransactionResult

func (c *Client) WaitTransactionResult(p *types.TransactionHashParam) (*types.TransactionResult, error)

type IClient

type IClient interface {
	Call(p *types.CallParam, r interface{}) error
	GetBalance(param *types.AddressParam) (*big.Int, error)
	GetBlockByHeight(p *types.BlockHeightParam) (*types.Block, error)
	GetBlockHeaderBytesByHeight(p *types.BlockHeightParam) ([]byte, error)
	GetVotesByHeight(p *types.BlockHeightParam) ([]byte, error)
	GetDataByHash(p *types.DataHashParam) ([]byte, error)
	GetProofForResult(p *types.ProofResultParam) ([][]byte, error)
	GetProofForEvents(p *types.ProofEventsParam) ([][][]byte, error)
	MonitorBlock(ctx context.Context, p *types.BlockRequest, cb func(conn *websocket.Conn, v *types.BlockNotification) error, scb func(conn *websocket.Conn), errCb func(*websocket.Conn, error)) error
	MonitorEvent(ctx context.Context, p *types.EventRequest, cb func(conn *websocket.Conn, v *types.EventNotification) error, errCb func(*websocket.Conn, error)) error
	Monitor(ctx context.Context, reqUrl string, reqPtr, respPtr interface{}, cb types.WsReadCallback) error
	CloseAllMonitor()
	CloseMonitor(conn *websocket.Conn)

	GetLastBlock() (*types.Block, error)
	GetBlockHeaderByHeight(height int64) (*types.BlockHeader, error)
	GetCommitVoteListByHeight(height int64) (*types.CommitVoteList, error)
	GetValidatorsByHash(hash common.HexHash) ([]common.Address, error)
}

type IVerifier

type IVerifier interface {
	Next() int64
	Verify(blockHeader *types.BlockHeader, votes []byte) (ok bool, err error)
	Update(blockHeader *types.BlockHeader, nextValidators []common.Address) (err error)
	Validators(nextValidatorsHash common.HexBytes) []common.Address
}

type IconOptions

type IconOptions map[string]string

func NewIconOptionsByHeader

func NewIconOptionsByHeader(h http.Header) IconOptions

func (IconOptions) Del

func (opts IconOptions) Del(key string)

func (IconOptions) Get

func (opts IconOptions) Get(key string) string

func (IconOptions) GetBool

func (opts IconOptions) GetBool(key string) (bool, error)

func (IconOptions) GetInt

func (opts IconOptions) GetInt(key string) (int64, error)

func (IconOptions) Set

func (opts IconOptions) Set(key, value string)

func (IconOptions) SetBool

func (opts IconOptions) SetBool(key string, value bool)

func (IconOptions) SetInt

func (opts IconOptions) SetInt(key string, v int64)

func (IconOptions) ToHeaderValue

func (opts IconOptions) ToHeaderValue() string

type Receiver

type Receiver struct {
	Client IClient
	// contains filtered or unexported fields
}

func (*Receiver) Subscribe

func (r *Receiver) Subscribe(
	ctx context.Context, msgCh chan<- *chain.Message,
	opts chain.SubscribeOptions) (errCh <-chan error, err error)

type ReceiverCore

type ReceiverCore struct {
	Log      log.Logger
	Cl       *Client
	Opts     ReceiverOptions
	BlockReq types.BlockRequest
}

func (*ReceiverCore) ReceiveLoop

func (r *ReceiverCore) ReceiveLoop(ctx context.Context, startHeight, startSeq uint64, callback func(txrs []*TxResult) error) (err error)

type ReceiverOptions

type ReceiverOptions struct {
	SyncConcurrency uint64                 `json:"syncConcurrency"`
	Verifier        *types.VerifierOptions `json:"verifier"`
}

type SerializeError

type SerializeError struct {
	// contains filtered or unexported fields
}

func (*SerializeError) Error

func (s *SerializeError) Error() string

type TxResult

type TxResult struct {
	Status             int64
	To                 []byte
	CumulativeStepUsed []byte
	StepUsed           []byte
	StepPrice          []byte
	LogsBloom          []byte
	EventLogs          []types.EventLog
	ScoreAddress       []byte
	EventLogsHash      common.HexBytes
	TxIndex            types.HexInt
	BlockHeight        types.HexInt
}

type Verifier

type Verifier struct {
	// contains filtered or unexported fields
}

func (*Verifier) Next

func (vr *Verifier) Next() int64

func (*Verifier) Update

func (vr *Verifier) Update(blockHeader *types.BlockHeader, nextValidators []common.Address) (err error)

func (*Verifier) Validators

func (vr *Verifier) Validators(nextValidatorsHash common.HexBytes) []common.Address

func (*Verifier) Verify

func (vr *Verifier) Verify(blockHeader *types.BlockHeader, votes []byte) (ok bool, err error)

type Wallet

type Wallet interface {
	Sign(data []byte) ([]byte, error)
	Address() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL