rpc

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RPCendpoint = map[string]RPCMethod{
	"ClientVersion":       {"web3_clientVersion", "GET"},
	"Sha3":                {"web3_sha3", "POST"},
	"NetworkId":           {"net_id", "GET"},
	"MostRecentBlock":     {"eth_blockNumber", "POST"},
	"GetBalance":          {"eth_getBalance", "POST"},
	"GetStorageAt":        {"eth_getStorageAt", "GET"},
	"GetTransactionCount": {"eth_getTransactionCount", "GET"},
	"GetCode":             {"eth_getCode", "GET"},
	"GetBlockByHash":      {"eth_getBlockByHash", "GET"},

	"Sign":                  {"eth_sign", "POST"},
	"SignTransaction":       {"eth_signTransaction", "POST"},
	"SendTransaction":       {"eth_sendTransaction", "POST"},
	"SendRawTransaction":    {"eth_sendRawTransaction", "POST"},
	"GasPrice":              {"eth_gasPrice", "GET"},
	"Coinbase":              {"eth_coinbase", "GET"},
	"GetTransactionByHash":  {"eth_getTransactionByHash", "POST"},
	"GetBlockReceipts":      {"eth_getBlockReceipts", "POST"},
	"GetTransactionReceipt": {"eth_getTransactionReceipt", "POST"},
	"Call":                  {"eth_call", "POST"},

	"Account":                          {"eth_accounts", "GET"},
	"EstimateGas":                      {"eth_estimateGas", "GET"},
	"FeeHistory":                       {"eth_feeHistory", "GET"},
	"GetBlockByNumber":                 {"eth_getBlockByNumber", "GET"},
	"GetBlockTransactionCountByHash":   {"eth_getBlockTransactionCountByhash", "GET"},
	"GetBlockTransactionCountByNumber": {"eth_getBlockTransactionCountByNumber", "GET"},
	"GetProof":                         {"eth_getProof", "GET"},
}

https://ethereum.github.io/execution-apis/api-documentation/

Functions

This section is empty.

Types

type ContractCreationTr added in v0.6.0

type ContractCreationTr struct {
	From  string `json:"from"`
	Value string `json:"value"`
	Input string `json:"data"`
}

Represent the transaction to create a contract When creating a contract, the TO field should be absent

type Endpoint

type Endpoint struct {
	ParsedURL *url.URL
	// contains filtered or unexported fields
}

represent the endpoint used as the entry point to the network. This can be a public endpoint as well as a personal node

func ConnectEndpoint

func ConnectEndpoint(Rawurl string) (*Endpoint, error)

Initialize the endpoint.

func (*Endpoint) Call

func (ep *Endpoint) Call(tr Transaction) (*RPCResponse, error)

func (*Endpoint) ClientVersion

func (ep *Endpoint) ClientVersion() (*RPCResponse, error)

func (*Endpoint) DeployContract added in v0.6.0

func (ep *Endpoint) DeployContract(sender string, contractByteCodePath string) (*TransactionReceiptResponse, error)

DeployContract deploy a contract to the blockchain it takes the account which is deploying the contract as first argument The second argument is the path to the compiled contract it return a TransactionReceipt struct (which contain the contract address) upon successfull completion if an error occur, return nil and an error

func (*Endpoint) GetBalance

func (ep *Endpoint) GetBalance(address string) (*RPCResponse, error)

func (*Endpoint) GetBlockReceipts

func (ep *Endpoint) GetBlockReceipts(blockNumber string) (*RPCResponse, error)

func (*Endpoint) GetCode

func (ep *Endpoint) GetCode(address string) (*RPCResponse, error)

func (*Endpoint) GetCoinbase

func (ep *Endpoint) GetCoinbase() (*RPCResponse, error)

func (*Endpoint) GetGasPrice

func (ep *Endpoint) GetGasPrice() (*RPCResponse, error)

func (*Endpoint) GetStorageAt

func (ep *Endpoint) GetStorageAt(contractAdress string, storageAddr int) (*RPCResponse, error)

func (*Endpoint) GetTransactionByHash

func (ep *Endpoint) GetTransactionByHash(transactionHash string) (*RPCResponse, error)

func (*Endpoint) GetTransactionCount

func (ep *Endpoint) GetTransactionCount(address string) (*RPCResponse, error)

func (*Endpoint) GetTransactionReceipt

func (ep *Endpoint) GetTransactionReceipt(transactionHash string) (*TransactionReceiptResponse, error)

GetTransactionReceipt query the receipt of a transaction based on the hash of the transaction. Upon successful completion, it return a pointer to a TransactionReceiptResponse struct In case of failure, return nil and an appropriate error

func (*Endpoint) HttpRequest

func (ep *Endpoint) HttpRequest(httpMethod string, RPCjson []byte) (*RPCResponse, error)

* Used when connecting to the endpoint via http * return an RPCResponse if everything goes well and nil and an error otherwise

func (*Endpoint) MostRecentBlock

func (ep *Endpoint) MostRecentBlock() (*RPCResponse, error)

func (*Endpoint) NetworkId added in v0.2.0

func (ep *Endpoint) NetworkId() (*RPCResponse, error)

func (*Endpoint) Request added in v0.3.0

func (ep *Endpoint) Request(Params []Parameters, rpcDetail RPCMethod) (*RPCResponse, error)

func (*Endpoint) SendRawTransaction

func (ep *Endpoint) SendRawTransaction(rawSignedTransaction string) (*RPCResponse, error)

func (*Endpoint) SendTransaction

func (ep *Endpoint) SendTransaction(transaction interface{}) (*RPCResponse, error)

func (*Endpoint) Sha3

func (ep *Endpoint) Sha3(data string) (*RPCResponse, error)

func (*Endpoint) SignTransaction

func (ep *Endpoint) SignTransaction(transaction Transaction) (*RPCResponse, error)

func (*Endpoint) UnixSocketRequest added in v0.3.0

func (ep *Endpoint) UnixSocketRequest(RPCjson []byte) (*RPCResponse, error)

* Used when trying to dialog with the node via UnixSocket * Return an RPCResponse structure with the structure or an error if something went wrong * note that if the RPC request went wrong, this function return a RPCResponse with an RPCERROR in it

type Parameters

type Parameters interface{}

Represent the parameters to allow multiple type

type RPCError added in v0.3.0

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type RPCMethod

type RPCMethod struct {
	Method     string
	HTTPMethod string
}

type RPCResponse added in v0.3.0

type RPCResponse struct {
	Jsonrpc string    `json:"jsonrpc"`
	Id      int       `json:"id"`
	Result  any       `json:"result"`
	Error   *RPCError `json:"error"`
}

type RPCTransaction

type RPCTransaction struct {
	Jsonrpc string       `json:"jsonrpc"`
	Method  string       `json:"method"`
	Params  []Parameters `json:"params"`
	Id      int          `json:"id"` //not sure what this is used for, seems like it can be anything.
}

The structure of the RPC call made to the endpoint

type Transaction

type Transaction struct {
	From  string `json:"from"`
	To    string `json:"to"`
	Value string `json:"value"`
	Input string `json:"data"`
}

Represent the transaction

func BuildTransaction

func BuildTransaction(from string, to string, value string, input string) Transaction

type TransactionReceiptResponse added in v0.6.0

type TransactionReceiptResponse struct {
	BlockHash         string `json:"blockHash"`
	BlockNumber       string `json:"blockNumber"`
	ContractAddress   string `json:"contractAddress"`
	CumulativeGasUser string `json:"cumulativeGasUser"`
	EffectiveGasPrice string `json:"effectiveGasPrice"`
	From              string `json:"from"`
	GasUsed           string `json:"gasUsed"`
	LogsBloom         string `json:"logsBloom"`
	Status            string `json:"status"`
	To                string `json:"to"`
	TransactionHash   string `json:"transactionHash"`
	TransactionIndex  string `json:"transactionIndex"`
	Type              string `json:"type"`
}

TransactionReceiptResponse represent the Response when querying the receipt of a transaction

Jump to

Keyboard shortcuts

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