ethclient

package module
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2024 License: GPL-3.0 Imports: 21 Imported by: 0

README

ethclient

Description

Extension ethclient.

Prerequisites

golang

Feautres

  • Schedule message
  • Sequence message
  • Protect message
  • Nonce management
  • Multiple rpc url supported

Quick Start

package main

import (
	"fmt"
	"time"

	"github.com/ivanzzeth/ethclient"
	"github.com/ivanzzeth/ethclient/message"
	"github.com/ivanzzeth/ethclient/tests/helper"
)

func main() {
	client, err := ethclient.Dial("http://localhost:8545")
	if err != nil {
		panic(err)
	}
	defer client.Close()

	go func() {
		client.ScheduleMsg((&message.Request{
			From:      helper.Addr,
			To:        &helper.Addr,
			StartTime: time.Now().Add(5 * time.Second).UnixNano(),
		}).SetRandomId())

		client.ScheduleMsg((&message.Request{
			From: helper.Addr,
			To:   &helper.Addr,
			// StartTime:      time.Now().Add(5 * time.Second).UnixNano(),
			ExpirationTime: time.Now().UnixNano() - int64(5*time.Second),
		}).SetRandomId())

		client.ScheduleMsg((&message.Request{
			From:           helper.Addr,
			To:             &helper.Addr,
			ExpirationTime: time.Now().Add(10 * time.Second).UnixNano(),
			Interval:       2 * time.Second,
		}).SetRandomId())

		time.Sleep(20 * time.Second)
		client.CloseSendMsg()
	}()

	for resp := range client.Response() {
		fmt.Println("execution resp: ", resp)
	}
}

Setup local node for testing

you should install foundry before running the script below:

./cmd/run_test_node.sh

License

The ethclient library is licensed under the GNU General Public License v3.0, also included in our repository in the COPYING.LESSER file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDialer added in v0.0.2

func SetDialer(d Dialer)

Types

type Client

type Client struct {
	*ethclient.Client

	subscriber.Subscriber
	// contains filtered or unexported fields
}

func Dial

func Dial(rawurl string) (*Client, error)

func NewClient

func NewClient(c *rpc.Client) *Client

func NewEthClient added in v0.1.0

func NewEthClient(
	c *rpc.Client,
	accRegistry account.Registry,
	msgStore message.Storage,
	nonceManager nonce.Manager,
	msgManager message.Manager,
	subscriber subscriber.Subscriber,
	sequencer message.Sequencer,
) (*Client, error)

func (*Client) AddABI

func (c *Client) AddABI(intf abi.ABI)

Trying to decode some data using the abi if specific

func (*Client) CallContract

func (c *Client) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)

func (*Client) CallContractAtHash

func (c *Client) CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error)

func (*Client) CallContractWithAccountOverride added in v0.1.0

func (c *Client) CallContractWithAccountOverride(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int, overrides *map[common.Address]gethclient.OverrideAccount) ([]byte, error)

func (*Client) CallMsg

func (c *Client) CallMsg(ctx context.Context, msg message.Request, blockNumber *big.Int) (returnData []byte, err error)

func (*Client) Close

func (c *Client) Close()

func (*Client) CloseSendMsg

func (c *Client) CloseSendMsg()

func (*Client) DebugTransactionOnChain

func (c *Client) DebugTransactionOnChain(ctx context.Context, txHash common.Hash) ([]byte, error)

func (*Client) DecodeJsonRpcError

func (c *Client) DecodeJsonRpcError(err error) error

func (*Client) EstimateGas

func (c *Client) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)

func (*Client) FilterLogs

func (c *Client) FilterLogs(ctx context.Context, q ethereum.FilterQuery) (logs []types.Log, err error)

func (*Client) GetMsg

func (c *Client) GetMsg(msgId common.Hash) (message.Message, error)

func (*Client) GetNonce added in v0.1.0

func (c *Client) GetNonce(msgId common.Hash) (uint64, error)

func (*Client) GetSigner

func (c *Client) GetSigner() bind.SignerFn

func (*Client) HasMsg added in v0.1.0

func (c *Client) HasMsg(msgId common.Hash) bool

func (*Client) MessageToTransactOpts

func (c *Client) MessageToTransactOpts(ctx context.Context, msg message.Request) (*bind.TransactOpts, error)

MessageToTransactOpts . NOTE: You must provide private key for signature.

func (*Client) NewMethodData

func (c *Client) NewMethodData(a abi.ABI, methodName string, args ...interface{}) ([]byte, error)

func (*Client) PendingCallContract

func (c *Client) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)

func (*Client) PendingNonceAt

func (c *Client) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

func (*Client) RawClient

func (c *Client) RawClient() *ethclient.Client

RawClient returns underlying ethclient

func (*Client) RegisterPrivateKey

func (c *Client) RegisterPrivateKey(ctx context.Context, key *ecdsa.PrivateKey) error

Registers the private key used for signing txs.

func (*Client) RegisterSigner

func (c *Client) RegisterSigner(signerFn bind.SignerFn)

func (*Client) ReplayMsg

func (c *Client) ReplayMsg(msgId common.Hash) (newMsgId common.Hash, err error)

func (*Client) Response added in v0.1.0

func (c *Client) Response() <-chan message.Response

func (*Client) ScheduleMsg

func (c *Client) ScheduleMsg(req *message.Request)

func (*Client) SetMsgBuffer

func (c *Client) SetMsgBuffer(buffer int)

func (*Client) SetNonceManager

func (c *Client) SetNonceManager(nm nonce.Manager)

func (*Client) SetSubscriber

func (c *Client) SetSubscriber(s subscriber.Subscriber)

func (*Client) SubscribeFilterLogs

func (c *Client) SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)

func (*Client) SubscribeNewHead

func (c *Client) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)

func (*Client) SuggestGasPrice

func (c *Client) SuggestGasPrice(ctx context.Context) (gasPrice *big.Int, err error)

func (*Client) WaitMsgReceipt added in v0.1.0

func (c *Client) WaitMsgReceipt(msgId common.Hash, confirmations uint64, timeout time.Duration) (*message.Receipt, bool)

func (*Client) WaitMsgResponse added in v0.1.0

func (c *Client) WaitMsgResponse(msgId common.Hash, timeout time.Duration) (*message.Response, bool)

func (*Client) WaitTxReceipt

func (c *Client) WaitTxReceipt(txHash common.Hash, confirmations uint64, timeout time.Duration) (*types.Receipt, bool)

type Dialer added in v0.0.2

type Dialer = func(rawurl string) (EthClientInterface, error)

type EthClientInterface added in v0.0.2

type EthClientInterface interface {
	bind.ContractBackend
	bind.DeployBackend
	bind.PendingContractCaller
	ethereum.ChainReader
	ethereum.TransactionReader
	ethereum.ChainStateReader
	ethereum.ContractCaller
	ethereum.LogFilterer
	ethereum.TransactionSender
	ethereum.GasPricer
	ethereum.GasPricer1559
	ethereum.FeeHistoryReader
	ethereum.PendingStateReader
	ethereum.PendingContractCaller
	ethereum.GasEstimator
	ethereum.BlockNumberReader
	ethereum.ChainIDReader
}

func DialOnce added in v0.0.2

func DialOnce(url string) EthClientInterface

Jump to

Keyboard shortcuts

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