feeder

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package feeder represent a client for the Feeder Gateway connection. For more details of the implementation, see this client https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py.

Index

Constants

This section is empty.

Variables

View Source
var ErrorBlockNotFound = fmt.Errorf("block not found")

Functions

func TxnIdentifier

func TxnIdentifier(txHash, txId string) map[string]string

Types

type BlockNumber

type BlockNumber int64

BlockNumber represents the `block_number` field in the StarkNet block structure. The BlockNumber is an int64, but in StarkNet the value can be an integer or the string "pending", so to check if the BlockNumber is pending the BlockNumber type implements the boolean function IsPending()

See https://docs.starknet.io/docs/Blocks/header#block-header

func (*BlockNumber) IsPending

func (x *BlockNumber) IsPending() bool

func (*BlockNumber) UnmarshalJSON

func (x *BlockNumber) UnmarshalJSON(data []byte) error

type Client

type Client struct {
	BaseURL            *url.URL
	BaseAPI, UserAgent string
	// contains filtered or unexported fields
}

Client represents a client for the StarkNet feeder gateway.

func NewClient

func NewClient(baseURL, baseAPI string, client *HttpClient) *Client

NewClient returns a new Client.

func (Client) CallContract

func (c Client) CallContract(invokeFunc InvokeFunction, blockHash, blockNumber string) (*map[string][]string, error)

CallContract creates a new request to call a contract using the gateway.

func (Client) CallEstimateFeeWithBody

func (c Client) CallEstimateFeeWithBody(blockIdentifier map[string]string, reqBody map[string]interface{}) (*EstimateFeeResponse, error)

func (Client) EstimateTransactionFee

func (c Client) EstimateTransactionFee(contractAddress, entryPointSelector, callData, signature string) (*EstimateFeeResponse, error)

EstimateFee makes a POST request to retrieve expected fee from a given transaction

func (Client) GetBlock

func (c Client) GetBlock(blockHash, blockNumber string) (*StarknetBlock, error)

GetBlock creates a new request to get a block from the gateway. The block number can be either a number or a hash. Response is a Block object. If there is any error, the response is nil. If the block fetched is not found, the response is nil and the error is of type ErrorBlockNotFound.

func (Client) GetBlockHashById

func (c Client) GetBlockHashById(blockID string) (*string, error)

GetBlockHashById creates a new request to get block hash by on ID.

func (Client) GetBlockIDByHash

func (c Client) GetBlockIDByHash(blockHash string) (*string, error)

GetBlockIDByHash creates a new request to get the block ID by hash. notest

func (Client) GetCode

func (c Client) GetCode(contractAddress, blockHash, blockNumber string) (*CodeInfo, error)

GetCode creates a new request to get the code of a contract

func (Client) GetContractAddresses

func (c Client) GetContractAddresses() (*ContractAddresses, error)

GetContractAddresses creates a new request to get contract addresses from the gateway.

func (Client) GetFullContract

func (c Client) GetFullContract(contractAddress, blockHash, blockNumber string) (map[string]interface{}, error)

GetFullContract creates a new request to get the full state of a contract.

func (Client) GetFullContractRaw

func (c Client) GetFullContractRaw(contractAddress, blockHash, blockNumber string) (*json.RawMessage, error)

GetFullContractRaw creates a new request to get the full state of a contract and returns the raw message.

func (Client) GetStateUpdate

func (c Client) GetStateUpdate(blockHash, blockNumber string) (*StateUpdateResponse, error)

GetStateUpdate creates a new request to get the state Update of a given block from the gateway.

func (Client) GetStorageAt

func (c Client) GetStorageAt(contractAddress, key, blockHash, blockNumber string) (*StorageInfo, error)

GetStorageAt creates a new request to get contract storage.

func (Client) GetTransaction

func (c Client) GetTransaction(txHash, txID string) (*TransactionInfo, error)

GetTransaction creates a new request to get a TransactionInfo.

func (Client) GetTransactionHashByID

func (c Client) GetTransactionHashByID(txID string) (*string, error)

GetTransactionHashByID creates a new request to get a transaction hash by ID.

func (Client) GetTransactionIDByHash

func (c Client) GetTransactionIDByHash(txHash string) (*string, error)

GetTransactionIDByHash creates a new request to get a transaction ID by hash.

func (Client) GetTransactionReceipt

func (c Client) GetTransactionReceipt(txHash, txID string) (*TransactionReceipt, error)

GetTransactionReceipt creates a new request to get a TransactionReceipt.

func (Client) GetTransactionStatus

func (c Client) GetTransactionStatus(txHash, txID string) (*TransactionStatus, error)

GetTransactionStatus creates a new request to get the transaction status.

func (Client) GetTransactionTrace

func (c Client) GetTransactionTrace(txHash, txID string) (*TransactionTrace, error)

GetTransactionTrace creates a new request to get the transaction trace (internal call information). notest

type CodeInfo

type CodeInfo struct {
	Bytecode []string   `json:"bytecode"`
	Abi      feeder.Abi `json:"abi"`
}

CodeInfo struct for code type

type ContractAddresses

type ContractAddresses struct {
	GpsStatementVerifier string `json:"GpsStatementVerifier"`
	Starknet             string `json:"Starknet"`
}

ContractAddresses represent the response for Starknet contract address details.

type DeployedContract

type DeployedContract struct {
	Address      string `json:"address"`
	ContractHash string `json:"class_hash"`
}

type EstimateFeeResponse

type EstimateFeeResponse struct {
	TransactionFailureReason
	Fee
}

type Event

type Event struct {
	FromAddress string   `json:"from_address"`
	Keys        []string `json:"keys"`
	Data        []string `json:"data"`
}

Event Represents a StarkNet event; contains all the fields that will be included in the block hash.

type ExecutionResources

type ExecutionResources struct {
	NSteps                 int64            `json:"n_steps"`
	BuiltinInstanceCounter map[string]int64 `json:"builtin_instance_counter"`
	NMemoryHoles           int64            `json:"n_memory_holes"`
}

ExecutionResources Indicates how many steps the program should run, how many memory cells are used from each builtin, and how many holes there are in the memory address space.

type Fee

type Fee struct {
	Amount     int    `json:"amount"` // DEPRECATED
	OverallFee int    `json:"overall_fee,omitempty"`
	Unit       string `json:"unit,omitempty"`
	GasPrice   int    `json:"gas_price,omitempty"`
	GasUsage   int    `json:"gas_usage,omitempty"`
}

Fee represents the fee paid for executing a transaction on StarkNet. NOTE: it includes Amount, which should stop working after StarkNet 0.9.1.

type HttpClient

type HttpClient interface {
	Do(*http.Request) (*http.Response, error)
}

type InvokeFunction

type InvokeFunction struct {
	CallerAddress      string   `json:"caller_address"`
	ContractAddress    string   `json:"contract_address"`
	CodeAddress        string   `json:"code_address"`
	Calldata           []string `json:"calldata"`
	CallType           string   `json:"call_type"`
	ClassHash          string   `json:"class_hash"`
	EntryPointSelector string   `json:"entry_point_selector"`
	Selector           string   `json:"selector"`
	EntryPointType     string   `json:"entry_point_type"`
	Result             []string `json:"result"`
	// Additional information given by the caller that represents the
	// signature of the transaction. The exact way this field is handled
	// is defined by the called contract's function, like calldata.
	ExecutionResources `json:"execution_resources"`
	// The transaction is not valid if its version is lower than the current version,
	// defined by the SN OS.
	Version       int      `json:"version"`
	Signature     []int    `json:"signature"`
	InternalCalls []string `json:"internal_calls"`
	Events        []Event  `json:"events"`
	Messages      []string `json:"messages"`
	// The maximal fee to be paid in Wei for executing invoked function.
	MaxFee string `json:"max_fee"`
}

InvokeFunction represents a transaction in the StarkNet network that is an invocation of a Cairo contract function.

type KV

type KV struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

KV represents a key-value pair.

type L1ToL2Message

type L1ToL2Message struct {
	FromAddress string   `json:"from_address"`
	ToAddress   string   `json:"to_address"`
	Selector    string   `json:"selector"`
	Payload     []string `json:"payload"`
	Nonce       string   `json:"nonce"`
}

L1ToL2Message Represents a StarkNet L1-to-L2 message.

type L2ToL1Message

type L2ToL1Message struct {
	FromAddress string   `json:"from_address"`
	ToAddress   string   `json:"to_address"`
	Payload     []string `json:"payload"`
}

L2ToL1Message Represents a StarkNet L2-to-L1 message.

type StarknetBlock

type StarknetBlock struct {
	BlockHash           string                 `json:"block_hash"`
	ParentBlockHash     string                 `json:"parent_block_hash"`
	BlockNumber         BlockNumber            `json:"block_number"`
	GasPrice            string                 `json:"gas_price"`
	SequencerAddress    string                 `json:"sequencer_address"`
	StateRoot           string                 `json:"state_root"`
	Status              string                 `json:"status"`
	OldStateRoot        string                 `json:"old_state_root"`
	Transactions        []TxnSpecificInfo      `json:"transactions"`
	Timestamp           int64                  `json:"timestamp"`
	TransactionReceipts []TransactionExecution `json:"transaction_receipts"`
}

StarknetBlock Represents a response StarkNet block.

type StarknetGeneralConfig

type StarknetGeneralConfig struct {
	ChainID                             string `json:"chain_id"`
	ContractStorageCommitmentTreeHeight int64  `json:"contract_storage_commitment_tree_height"`
	GlobalStateCommitmentTreeHeight     int64  `json:"global_state_commitment_tree_height"`
	InvokeTxMaxNSteps                   int64  `json:"invoke_tx_max_n_steps"`
	// StarkNet sequencer address.
	SequencerAddress int64 `json:"sequencer_address"`
	// Height of Patricia tree of the transaction commitment in a block.
	TxCommitmentTreeHeight int `json:"tx_commitment_tree_height"`
	// Height of Patricia tree of the event commitment in a block.
	EventCommitmentTreeHeight int `json:"event_commitment_tree_height"`
	// A mapping from a Cairo usage resource to its coefficient in this
	// transaction fee calculation.
	CairoUsageResourceFeeWeights map[string]float64 `json:"cairo_usage_resource_fee_weights"`
}

StarknetGeneralConfig represent StarkNet general configuration.

type StateDiff

type StateDiff struct {
	StorageDiffs      map[string][]KV    `json:"storage_diffs"`
	DeployedContracts []DeployedContract `json:"deployed_contracts"`
}

type StateUpdateResponse

type StateUpdateResponse struct {
	BlockHash string    `json:"block_hash"`
	NewRoot   string    `json:"new_root"`
	OldRoot   string    `json:"old_root"`
	StateDiff StateDiff `json:"state_diff"`
}

StateUpdateResponse represents the response of a StarkNet state update.

type StorageInfo

type StorageInfo string

StorageInfo struct to store Storage info

type TransactionExecution

type TransactionExecution struct {
	// The index of the transaction within the block.
	TransactionIndex int64 `json:"transaction_index"`
	// A unique identifier of the transaction.
	TransactionHash string `json:"transaction_hash"`
	// L2-to-L1 messages.
	L2ToL1Messages []L2ToL1Message `json:"l2_to_l1_messages"`
	// L1-to-L2 messages.
	L1ToL2Message *L1ToL2Message `json:"l1_to_l2_consumed_message,omitempty"`
	// Events emitted during the execution of the transaction.
	Events []Event `json:"events"`
	// The resources needed by the transaction.
	ExecutionResources ExecutionResources `json:"execution_resources"`
	// Fee paid for executing the transaction.
	ActualFee string `json:"actual_fee"`
}

TransactionExecution Represents a receipt of an executed transaction.

type TransactionFailureReason

type TransactionFailureReason struct {
	TxID     int64  `json:"tx_id,omitempty"`
	Code     string `json:"code,omitempty"`
	ErrorMsg string `json:"message,omitempty"`
}

TransactionFailureReason store reason of failure in transactions.

type TransactionInBlockInfo

type TransactionInBlockInfo struct {
	// The reason for the transaction failure, if applicable.
	TransactionFailureReason `json:"transaction_failure_reason,omitempty"`
	TransactionStatus
	// The sequence number of the block corresponding to block_hash, which
	// is the number of blocks prior to it in the active chain.
	BlockNumber int64 `json:"block_number"`
	//	The index of the transaction within the block corresponding to
	// block_hash.
	TransactionIndex int64 `json:"transaction_index"`
}

TransactionInBlockInfo represents the information regarding a transaction that appears in a block.

type TransactionInfo

type TransactionInfo struct {
	// // Block information that Transaction occurred in
	TransactionInBlockInfo // fix: Was not fetching values correctly prior
	// Transaction Specific Information
	Transaction TxnSpecificInfo `json:"transaction"`
}

TransactionInfo store all the transaction Information

type TransactionReceipt

type TransactionReceipt struct {
	TransactionInBlockInfo
	TransactionExecution
	Transaction TxnSpecificInfo `json:"transaction"`
}

TransactionReceipt represents a receipt of a StarkNet transaction; i.e., the information regarding its execution and the block it appears in.

type TransactionStatus

type TransactionStatus struct {
	// tx_status for get_transaction_status
	TxStatus string `json:"tx_status,omitempty"`
	// status for other calls.
	Status    string `json:"status,omitempty"`
	BlockHash string `json:"block_hash"`
}

type TransactionTrace

type TransactionTrace struct {
	InvokeFunction `json:"function_invocation"`
	Signature      []string `json:"signature"`
}

type TxnSpecificInfo

type TxnSpecificInfo struct {
	ContractAddress     string   `json:"contract_address"`
	ClassHash           string   `json:"class_hash"`
	Nonce               string   `json:"nonce"`
	SenderAddress       string   `json:"sender_address"`
	Version             string   `json:"version"`
	EntryPointSelector  string   `json:"entry_point_selector"`
	EntryPointType      string   `json:"entry_point_type"`
	Calldata            []string `json:"calldata"`
	ConstructorCalldata []string `json:"constructor_calldata"`
	Signature           []string `json:"signature"`
	TransactionHash     string   `json:"transaction_hash"`
	MaxFee              string   `json:"max_fee"`
	Type                string   `json:"type"`
	ContractAddressSalt string   `json:"contract_address_salt"`
}

TxnSpecificInfo represent a StarkNet transaction information.

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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