chainclient

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: MIT Imports: 13 Imported by: 1

README

chainclient

blockchain client context interfaces, and the implementations based on ethereum

install

go get github.com/bglmmz/chainclient@latest_commitID

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitMockWallet

func InitMockWallet()

Types

type Context

type Context interface {
	SetPrivateKey(*ecdsa.PrivateKey)
	GetPrivateKey() *ecdsa.PrivateKey
	GetPublicKey() *ecdsa.PublicKey
	GetAddress() ethcommon.Address
	GetClient() *ethclient.Client
	BlockNumber(timeoutCtx context.Context) (uint64, error)
	PendingNonceAt(timeoutCtx context.Context) (uint64, error)
	SuggestGasPrice(timeoutCtx context.Context) (*big.Int, error)

	EstimateGas(timeoutCtx context.Context, to ethcommon.Address, data []byte) (uint64, error)
	CallContract(timeoutCtx context.Context, to ethcommon.Address, data []byte) ([]byte, error)

	BuildTxOpts(value, gasLimit uint64) (*bind.TransactOpts, error)
	WaitReceipt(timeoutCtx context.Context, txHash ethcommon.Hash, interval time.Duration) *ethtypes.Receipt
	GetLog(timeoutCtx context.Context, toAddr ethcommon.Address, blockNo *big.Int) ([]ethtypes.Log, error)
}

type EthContext

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

func NewEthClientContext

func NewEthClientContext(chainUrl string, hrp string, wallet WalletWrapper) *EthContext

func (*EthContext) BlockNumber

func (ctx *EthContext) BlockNumber(timeoutCtx context.Context) (uint64, error)

func (*EthContext) BuildTxOpts

func (ctx *EthContext) BuildTxOpts(value, gasLimit uint64) (*bind.TransactOpts, error)

func (*EthContext) CallContract

func (ctx *EthContext) CallContract(timeoutCtx context.Context, to ethcommon.Address, input []byte) ([]byte, error)

func (*EthContext) EstimateGas

func (ctx *EthContext) EstimateGas(timeoutCtx context.Context, to ethcommon.Address, input []byte) (uint64, error)

EstimateGas uses context's walletWrapper address as the caller (from)

func (*EthContext) GetAddress

func (ctx *EthContext) GetAddress() ethcommon.Address

func (*EthContext) GetClient

func (ctx *EthContext) GetClient() *ethclient.Client

func (*EthContext) GetLog

func (ctx *EthContext) GetLog(timeoutCtx context.Context, toAddr ethcommon.Address, blockNo *big.Int) ([]ethtypes.Log, error)

func (*EthContext) GetPrivateKey

func (ctx *EthContext) GetPrivateKey() *ecdsa.PrivateKey

func (*EthContext) GetPublicKey

func (ctx *EthContext) GetPublicKey() *ecdsa.PublicKey

func (*EthContext) PendingNonceAt

func (ctx *EthContext) PendingNonceAt(timeoutCtx context.Context) (uint64, error)

func (*EthContext) SetPrivateKey

func (ctx *EthContext) SetPrivateKey(privateKey *ecdsa.PrivateKey)

func (*EthContext) SuggestGasPrice

func (ctx *EthContext) SuggestGasPrice(timeoutCtx context.Context) (*big.Int, error)

func (*EthContext) WaitReceipt

func (ctx *EthContext) WaitReceipt(timeoutCtx context.Context, txHash ethcommon.Hash, interval time.Duration) *ethtypes.Receipt

type MockWallet

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

func MockWalletInstance

func MockWalletInstance() *MockWallet

func (*MockWallet) GetAddress

func (m *MockWallet) GetAddress() ethcommon.Address

GetAddress returns the organization wallet address

func (*MockWallet) GetPrivateKey

func (m *MockWallet) GetPrivateKey() *ecdsa.PrivateKey

GetPrivateKey returns the organization private key

func (*MockWallet) GetPublicKey

func (m *MockWallet) GetPublicKey() *ecdsa.PublicKey

GetPrivateKey returns the organization private key

func (*MockWallet) SetPrivateKey

func (m *MockWallet) SetPrivateKey(privateKey *ecdsa.PrivateKey)

GetPrivateKey returns the organization private key

type WalletWrapper

type WalletWrapper interface {
	SetPrivateKey(privateKey *ecdsa.PrivateKey)
	GetPrivateKey() *ecdsa.PrivateKey
	GetPublicKey() *ecdsa.PublicKey
	GetAddress() ethcommon.Address
}

Jump to

Keyboard shortcuts

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