icon

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSendTransactionRetryInterval        = 3 * time.Second        // 3sec
	DefaultGetTransactionResultPollingInterval = 500 * time.Millisecond // 1.5sec
	JsonrpcApiVersion                          = 3
)
View Source
const (
	HeaderKeyIconOptions = "Icon-Options"
	IconOptionsDebug     = "debug"
	IconOptionsTimeout   = "timeout"
)

Variables

View Source
var (
	MethodSendMessage = "sendMessage"
	MethodRecvMessage = "recvMessage"
	MethodGetReceipts = "getReceipts"
)
View Source
var EmitMessage = "Message(str,int,bytes)"

All the events

View Source
var EventNameToType = map[string]string{
	EmitMessage: events.EmitMessage,
}
View Source
var MonitorEventsList []string = []string{

	EmitMessage,
}

Functions

func Base64ToData

func Base64ToData(encoded string, v interface{}) ([]byte, error)

func GetMonitorEventFilters

func GetMonitorEventFilters(address string, eventsList []string) []*types.EventFilter

func MptProve

func MptProve(key types.HexInt, proofs [][]byte, hash []byte) ([]byte, error)

Types

type CallParamOption

type CallParamOption func(*types.CallParam)

type Client

type Client struct {
	*client.JsonRpcClient
	DebugEndPoint string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(uri string, l *zap.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) EstimateStep

func (c *Client) EstimateStep(param *types.TransactionParamForEstimate) (*types.HexInt, error)

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) 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) SendTransactionAndWait

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

func (*Client) SignTransaction

func (c *Client) SignTransaction(w module.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)
	GetValidatorsByHash(hash common.HexHash) ([]common.Address, error)
}

type IconMessage

type IconMessage struct {
	Params interface{}
	Method string
}

func (*IconMessage) MsgBytes

func (im *IconMessage) MsgBytes() ([]byte, error)

func (*IconMessage) Type

func (im *IconMessage) Type() string

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 IconProvider

type IconProvider struct {
	PCfg *IconProviderConfig
	// contains filtered or unexported fields
}

func (*IconProvider) AddressFromKeyStore

func (p *IconProvider) AddressFromKeyStore(keystorePath, password string) (string, error)

func (*IconProvider) ChainName

func (p *IconProvider) ChainName() string

func (*IconProvider) FinalityBlock

func (p *IconProvider) FinalityBlock(ctx context.Context) uint64

func (*IconProvider) GenerateMessage

func (*IconProvider) Init

func (p *IconProvider) Init(ctx context.Context, homepath string, kms kms.KMS) error

func (*IconProvider) Listener

func (icp *IconProvider) Listener(ctx context.Context, lastSavedHeight uint64, incoming chan providerTypes.BlockInfo) error

TODO: check for balance and if the balance is low show info balance is low starting listener

func (*IconProvider) LogFailedTx

func (icp *IconProvider) LogFailedTx(method string, result *types.TransactionResult, err error)

func (*IconProvider) LogSuccessTx

func (icp *IconProvider) LogSuccessTx(method string, result *types.TransactionResult)

func (*IconProvider) MakeIconMessage

func (icp *IconProvider) MakeIconMessage(message *providerTypes.Message) (IconMessage, error)

func (*IconProvider) MessageReceived

func (ip *IconProvider) MessageReceived(ctx context.Context, messageKey providerTypes.MessageKey) (bool, error)

func (*IconProvider) NID

func (p *IconProvider) NID() string

func (*IconProvider) NewIconMessage

func (icp *IconProvider) NewIconMessage(msg interface{}, method string) IconMessage

func (*IconProvider) NewKeyStore

func (p *IconProvider) NewKeyStore(dir, password string) (string, error)

func (*IconProvider) ProviderConfig

func (p *IconProvider) ProviderConfig() provider.ProviderConfig

func (*IconProvider) QueryBalance

func (ip *IconProvider) QueryBalance(ctx context.Context, addr string) (*providerTypes.Coin, error)

func (*IconProvider) QueryLatestHeight

func (ip *IconProvider) QueryLatestHeight(ctx context.Context) (uint64, error)

func (*IconProvider) QueryTransactionReceipt

func (icp *IconProvider) QueryTransactionReceipt(ctx context.Context, txHash string) (*providerTypes.Receipt, error)

QueryTransactionReceipt -> TxHash should be in hex string

func (*IconProvider) RestoreKeyStore

func (p *IconProvider) RestoreKeyStore(ctx context.Context, homePath string, client kms.KMS) error

func (*IconProvider) RevertMessage

func (icp *IconProvider) RevertMessage(ctx context.Context, sn *big.Int) error

func (*IconProvider) Route

func (icp *IconProvider) Route(ctx context.Context, message *providerTypes.Message, callback providerTypes.TxResponseFunc) error

func (*IconProvider) SendTransaction

func (icp *IconProvider) SendTransaction(
	ctx context.Context,
	msg IconMessage,
) ([]byte, error)

func (*IconProvider) SetAdmin

func (ip *IconProvider) SetAdmin(ctx context.Context, admin string) error

SetAdmin sets the admin address of the bridge contract

func (*IconProvider) ShouldReceiveMessage

func (ip *IconProvider) ShouldReceiveMessage(ctx context.Context, messagekey providerTypes.Message) (bool, error)

func (*IconProvider) ShouldSendMessage

func (ip *IconProvider) ShouldSendMessage(ctx context.Context, messageKey providerTypes.Message) (bool, error)

func (*IconProvider) StartFromHeight

func (icp *IconProvider) StartFromHeight(ctx context.Context, lastSavedHeight uint64) (int64, error)

func (*IconProvider) Type

func (p *IconProvider) Type() string

func (*IconProvider) WaitForTxResult

func (icp *IconProvider) WaitForTxResult(
	ctx context.Context,
	txHash []byte,
	messageKey providerTypes.MessageKey,
	method string,
	callback providerTypes.TxResponseFunc,
)

TODO: review try to remove wait for Tx from packet-transfer and only use this for client and connection creation

func (*IconProvider) Wallet

func (p *IconProvider) Wallet() (module.Wallet, error)

type IconProviderConfig

type IconProviderConfig struct {
	ChainName       string `json:"-" yaml:"-"`
	RPCUrl          string `json:"rpc-url" yaml:"rpc-url"`
	KeyStore        string `json:"keystore" yaml:"keystore"`
	Password        string `json:"password" yaml:"password"`
	StartHeight     uint64 `json:"start-height" yaml:"start-height"` // would be of highest priority
	ContractAddress string `json:"contract-address" yaml:"contract-address"`
	NetworkID       uint   `json:"network-id" yaml:"network-id"`
	NID             string `json:"nid" yaml:"nid"`
}

func (*IconProviderConfig) GetWallet

func (p *IconProviderConfig) GetWallet() string

func (*IconProviderConfig) NewProvider

func (c *IconProviderConfig) NewProvider(log *zap.Logger, homepath string, debug bool, chainName string) (provider.ChainProvider, error)

NewProvider returns new Icon provider

func (*IconProviderConfig) SetWallet

func (p *IconProviderConfig) SetWallet(addr string)

func (*IconProviderConfig) Validate

func (pp *IconProviderConfig) Validate() error

type OnlyAddr

type OnlyAddr struct {
	Address string `json:"address"`
}

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