construction

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConstructContractCallDataGeneric added in v0.0.7

func ConstructContractCallDataGeneric(methodSig string, methodArgs interface{}) ([]byte, error)

ConstructContractCallDataGeneric constructs the data field of a transaction. The methodArgs can be already in ABI encoded format in case of a single string It can also be passed in as a slice of args, which requires further encoding.

func EthTransaction added in v0.0.7

func EthTransaction(tx *client.Transaction) *types.Transaction

Types

type APIService

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

APIService implements /construction/* endpoints

func NewAPIService

func NewAPIService(
	cfg *configuration.Configuration,
	types *sdkTypes.Types,
	errors []*types.Error,
	client Client,
) *APIService

NewAPIService creates a new instance of a APIService.

func (*APIService) ConstructionCombine

ConstructionCombine implements /construction/combine endpoint.

Combine creates a network-specific Transaction from an unsigned Transaction and an array of provided signatures. The signed Transaction returned from this method will be sent to the /construction/submit endpoint by the caller.

func (*APIService) ConstructionDerive

ConstructionDerive implements the /construction/derive endpoint.

func (*APIService) ConstructionHash

ConstructionHash implements /construction/hash endpoint.

TransactionHash returns the network-specific Transaction hash for a signed Transaction.

func (APIService) ConstructionMetadata

ConstructionMetadata implements /construction/metadata endpoint.

Get any information required to construct a transaction for a specific network. Metadata returned here could be a recent hash to use, an account sequence number, or even arbitrary chain state. The request used when calling this endpoint is created by calling /construction/preprocess in an offline environment.

func (*APIService) ConstructionParse

ConstructionParse implements the /construction/parse endpoint.

func (*APIService) ConstructionPayloads

ConstructionPayloads implements /construction/payloads endpoint

Payloads is called with an array of operations and the response from /construction/Metadata. It returns an unsigned Transaction blob and a collection of payloads that must be signed by particular AccountIdentifiers using a certain SignatureType. The array of operations provided in Transaction construction often times can not specify all "effects" of a Transaction (consider invoked transactions in Ethereum). However, they can deterministically specify the "intent" of the Transaction, which is sufficient for construction. For this reason, parsing the corresponding Transaction in the Data API (when it lands on chain) will contain a superset of whatever operations were provided during construction.

func (*APIService) ConstructionPreprocess

ConstructionPreprocess implements /construction/preprocess endpoint.

Preprocess is called prior to /construction/payloads to construct a request for any metadata that is needed for transaction construction given (i.e. account nonce).

func (*APIService) ConstructionSubmit

ConstructionSubmit implements /construction/submit endpoint.

Submit a pre-signed Transaction to the node.

func (*APIService) CreateOperationDescription

func (s *APIService) CreateOperationDescription(
	operations []*types.Operation,
	isContractCall bool,
) ([]*parser.OperationDescription, error)

func (*APIService) CreateOperationDescriptionContractCall

func (s *APIService) CreateOperationDescriptionContractCall() []*parser.OperationDescription

func (*APIService) CreateOperationDescriptionERC20

func (s *APIService) CreateOperationDescriptionERC20(
	contractAddress string, currencyInfo *types.Currency,
) []*parser.OperationDescription

func (*APIService) CreateOperationDescriptionNative

func (s *APIService) CreateOperationDescriptionNative() []*parser.OperationDescription

type Client

type Client interface {
	// Status returns the current status of the network
	Status(
		context.Context,
	) (*RosettaTypes.BlockIdentifier,
		int64,
		*RosettaTypes.SyncStatus,
		[]*RosettaTypes.Peer,
		error,
	)

	// Balance is to fetch the state of an account based on the provided currencies
	Balance(
		context.Context,
		*RosettaTypes.AccountIdentifier,
		*RosettaTypes.PartialBlockIdentifier,
		[]*RosettaTypes.Currency,
	) (*RosettaTypes.AccountBalanceResponse, error)

	// Submit is to submit a pre-signed transaction to the blockchain
	Submit(context.Context, *EthTypes.Transaction) error

	// GetNonce returns the account nonce of the given account
	// The given account is the from address in Options input
	GetNonce(context.Context, evmClient.Options) (uint64, error)

	// GetGasPrice retrieves the currently suggested gas price
	GetGasPrice(context.Context, evmClient.Options) (*big.Int, error)

	// GetGasTipCap returns gas tip cap for EIP-1559 support
	GetGasTipCap(context.Context, evmClient.Options) (*big.Int, error)

	// GetGasFeeCap returns gas fee cap for EIP-1559 support
	GetGasFeeCap(context.Context, evmClient.Options, *big.Int) (*big.Int, error)

	// GetBaseFee returns base fee for EIP-1559 support
	GetBaseFee(ctx context.Context) (*big.Int, error)

	// GetL1DataFee returns L1 data fee
	GetL1DataFee(ctx context.Context, ethTxBytes []byte) (*big.Int, error)

	// GetRosettaConfig returns the Rosetta config we defined for the network
	GetRosettaConfig() configuration.RosettaConfig

	// TraceBlockByHash returns all traces for each transaction in the block
	// by calling geth debug_traceBlockByHash JSON RPC.
	// The output is map which key is transaction hash, and the value is list of
	// FlatCall. Each Flatcall is populated from one single trace.
	TraceBlockByHash(
		context.Context,
		common.Hash,
		[]evmClient.RPCTransaction,
	) (map[string][]*evmClient.FlatCall, error)

	// TraceTransaction returns all traces for one transaction
	// by calling geth debug_traceTransaction JSON RPC.
	// The output is a list of FlatCall. Each Flatcall is populated from one single trace.
	TraceTransaction(ctx context.Context, hash common.Hash) (json.RawMessage, []*evmClient.FlatCall, error)

	// BlockRewardTransaction returns the block reward Rosetta transaction for the miner
	BlockRewardTransaction(
		blockIdentifier *RosettaTypes.BlockIdentifier,
		miner string,
		uncles []*EthTypes.Header,
	) *RosettaTypes.Transaction

	// GetLoadedTransaction populates the LoadedTransaction which used by Rosetta data APIs
	GetLoadedTransaction(
		ctx context.Context,
		request *RosettaTypes.BlockTransactionRequest,
	) (*evmClient.LoadedTransaction, error)

	// BlockAuthor returns the block author
	BlockAuthor(ctx context.Context, blockIndex int64) (string, error)

	// GetUncles calls eth_getUncleByBlockHashAndIndex eth RPC to load uncle blocks
	GetUncles(
		ctx context.Context,
		head *EthTypes.Header,
		body *evmClient.RPCBlock,
	) ([]*EthTypes.Header, error)

	// TraceReplayBlockTransactions returns all traces for each transaction in the block
	// by calling open ethereum trace_replayBlockTransactions JSON RPC.
	// The output is map which key is transaction hash, and the value is list of
	// FlatCall. Each Flatcall is populated from one single trace.
	TraceReplayBlockTransactions(
		ctx context.Context,
		hsh string,
	) (map[string][]*evmClient.FlatCall, error)

	// TraceTransaction returns all traces for one transaction
	// by calling open ethereum trace_replayTransaction JSON RPC.
	// The output is a list of FlatCall. Each Flatcall is populated from one single trace.
	TraceReplayTransaction(ctx context.Context, hsh string) (json.RawMessage, []*evmClient.FlatCall, error)

	// PopulateCrossChainTransactions populates all the bridge transactions for the block
	// This method is used for blockchain that supports bridging function
	PopulateCrossChainTransactions(
		*EthTypes.Block,
		[]*evmClient.LoadedTransaction,
	) ([]*RosettaTypes.Transaction, error)

	// GetContractCurrency returns the ERC20 currency into for a specific token contract address
	GetContractCurrency(addr common.Address, erc20 bool) (*evmClient.ContractCurrency, error)

	// CallContext performs a JSON-RPC call with the given arguments.
	// The method is used by the JSON RPC Client, which is the interface
	// for accessing go-ethereum's JSON RPC endpoint.
	CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error

	// BatchCall sends all given requests as a single batch and waits for the server
	// to return a response for all of them. The wait duration is bounded by the
	// context's deadline.
	// The method is used by the JSON RPC Client, which is the interface
	// for accessing go-ethereum's JSON RPC endpoint.
	BatchCallContext(ctx context.Context, b []rpc.BatchElem) error

	// GetBlockReceipts returns a list of transaction receipts, used by Rosetta block api
	GetBlockReceipts(
		ctx context.Context,
		blockHash common.Hash,
		txs []evmClient.RPCTransaction,
		baseFee *big.Int,
	) ([]*evmClient.RosettaTxReceipt, error)

	// GetTransactionReceipt returns the Rosetta transaction receipt, used by Rosetta
	// block/transaction api
	GetTransactionReceipt(
		ctx context.Context,
		tx *evmClient.LoadedTransaction,
	) (*evmClient.RosettaTxReceipt, error)

	// GetNativeTransferGasLimit returns the estimated gas limit for the native currency transfer
	// This method is used by Rosetta construction/metadata api
	GetNativeTransferGasLimit(
		ctx context.Context,
		toAddress string,
		fromAddress string,
		value *big.Int,
	) (uint64, error)

	// GetErc20TransferGasLimit returns the estimated gas limit for the ERC20 token transfer
	// This method is used by Rosetta construction/metadata api
	GetErc20TransferGasLimit(
		ctx context.Context,
		toAddress string,
		fromAddress string,
		value *big.Int,
		currency *RosettaTypes.Currency,
	) (uint64, error)

	// GetErc20TransferGasLimit returns the estimated gas limit for the ERC20 token transfer
	// This method is used by Rosetta construction/metadata api
	GetContractCallGasLimit(
		ctx context.Context,
		toAddress string,
		fromAddress string,
		value *big.Int,
		data []byte,
	) (uint64, error)

	// ParseOps returns a list of operations
	ParseOps(
		tx *evmClient.LoadedTransaction,
	) ([]*RosettaTypes.Operation, error)
}

Client contains all the methods required to interact with go-ethereum based blockchain

Jump to

Keyboard shortcuts

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