sequencer

package
v0.0.0-...-9345ff8 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: MIT Imports: 16 Imported by: 0

README

Sequencer API

Package implements wrapper over Sequencer API. Package is under development.

Install

go get github.com/dipdup-io/starknet-api-go/pkg/sequencer

Usage

Full example of usage can be found here.

Methods

Wrapper implements next methods:


CallContract(ctx context.Context, block data.BlockID, contractAddress, entrypointSelector string, calldata []string) (response Response[[]string], err error)

GetTransaction(ctx context.Context, hash string) (response Trace, err error) 

GetCode(ctx context.Context, block data.BlockID, contractAddress string) (response Code, err error)

GetNonce(ctx context.Context, block data.BlockID, contractAddress string) (response string, err error)

TraceBlock(ctx context.Context, block data.BlockID) (response TraceResponse, err error)

TraceTransaction(ctx context.Context, hash string) (response Trace, err error)
Creation

First of all you should import package in your code:

starknetData "github.com/QinPengLin/starknet-go/pkg/data"
sequencerAPI "github.com/QinPengLin/starknet-go/pkg/sequencer"

Then create API object:

api := sequencerAPI.NewAPI("https://alpha-mainnet.starknet.io/gateway", "https://alpha-mainnet.starknet.io/feeder_gateway")

And call any method:

response, err := api.CallContract(ctx, starknetData.BlockID{
    String: starknetData.Latest,
},
    "0x233084545b87df4940643bdcc5ff959f8371d2f388ae5f05c8c19eea7059c1a",
    "0x26813d396fdb198e9ead934e4f7a592a8b88a059e45ab0eb6ee53494e8d45b0",
    []string{
        "5",
    })
if err != nil {
    log.Panic(err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

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

API - wrapper of starknet node API.

func NewAPI

func NewAPI(gatewayUrl, feederGatewayUrl string, opts ...ApiOption) API

NewAPI - constructor of API

func (API) CallContract

func (api API) CallContract(ctx context.Context, block data.BlockID, contractAddress, entrypointSelector string, calldata []string) (response Response[[]data.Felt], err error)

CallContract -

func (API) Declare

func (api API) Declare(ctx context.Context, tx data.Declare) (string, error)

Declare -

func (API) DeployAccount

func (api API) DeployAccount(ctx context.Context, tx data.DeployAccount) (string, error)

DeployAccount -

func (API) GetBlock

func (api API) GetBlock(ctx context.Context, block data.BlockID) (response Block, err error)

GetBlock - Gets block

func (API) GetClassAt

func (api API) GetClassAt(ctx context.Context, block data.BlockID, contractAddress string) (response data.Class, err error)

GetClassAt -

func (API) GetClassByHash

func (api API) GetClassByHash(ctx context.Context, block data.BlockID, classHash string) (response data.Class, err error)

GetClassByHash -

func (API) GetClassHashAt

func (api API) GetClassHashAt(ctx context.Context, block data.BlockID, contractAddress string) (response string, err error)

GetClassHashAt -

func (API) GetCode

func (api API) GetCode(ctx context.Context, block data.BlockID, contractAddress string) (response Code, err error)

GetBlock - Gets code of contract

func (API) GetContractAddresses

func (api API) GetContractAddresses(ctx context.Context) (response ContractAddresses, err error)

GetContractAddresses -

func (API) GetNonce

func (api API) GetNonce(ctx context.Context, block data.BlockID, contractAddress string) (response string, err error)

GetNonce - Gets nonce for address

func (API) GetStateUpdate

func (api API) GetStateUpdate(ctx context.Context, block data.BlockID) (response data.StateUpdate, err error)

GetStateUpdate -

func (API) GetStorageAt

func (api API) GetStorageAt(ctx context.Context, block data.BlockID, contractAddress, key string) (response string, err error)

GetStorageAt - 'key' is decimal string

func (API) GetTransaction

func (api API) GetTransaction(ctx context.Context, hash string) (response Trace, err error)

GetTransaction - Gets the transaction by hash

func (API) GetTransactionStatus

func (api API) GetTransactionStatus(ctx context.Context, txHash string) (response TransactionStatus, err error)

GetTransactionStatus - Gets nonce for address

func (API) Invoke

func (api API) Invoke(ctx context.Context, tx data.Invoke) (string, error)

Invoke -

func (API) TraceBlock

func (api API) TraceBlock(ctx context.Context, block data.BlockID) (response TraceResponse, err error)

TraceBlock -

func (API) TraceTransaction

func (api API) TraceTransaction(ctx context.Context, hash string) (response Trace, err error)

TraceTransaction - Gets the transaction trace from hash

type ApiOption

type ApiOption func(*API)

ApiOption -

func WithCacheInFS

func WithCacheInFS(dir string) ApiOption

WithCacheInFS -

func WithRateLimit

func WithRateLimit(requestPerSecond int) ApiOption

WithRateLimit -

type Block

type Block struct {
	Timestamp        int64              `json:"timestamp"`
	BlockNumber      uint64             `json:"block_number"`
	Status           string             `json:"status"`
	BlockHash        string             `json:"block_hash"`
	ParentHash       string             `json:"parent_block_hash"`
	NewRoot          string             `json:"state_root"`
	GasPrice         string             `json:"gas_price"`
	SequencerAddress string             `json:"sequencer_address"`
	StarknetVersion  *string            `json:"starknet_version,omitempty"`
	Transactions     []data.Transaction `json:"transactions"`
	Receipts         []Receipt          `json:"transaction_receipts"`
}

Block -

type BuiltinInstanceCounter

type BuiltinInstanceCounter struct {
	RangeCheckBuiltin int `json:"range_check_builtin"`
	EcdsaBuiltin      int `json:"ecdsa_builtin"`
	PedersenBuiltin   int `json:"pedersen_builtin"`
	BitwiseBuiltin    int `json:"bitwise_builtin"`
}

BuiltinInstanceCounter -

type Code

type Code struct {
	ByteCode []string `json:"bytecode"`
	Abi      abi.Abi  `json:"abi"`
}

Code -

type ContractAddresses

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

ContractAddresses -

type ExecutionResources

type ExecutionResources struct {
	NSteps                 int                    `json:"n_steps"`
	BuiltinInstanceCounter BuiltinInstanceCounter `json:"builtin_instance_counter"`
	NMemoryHoles           int                    `json:"n_memory_holes"`
}

ExecutionResources -

type GetTransactionResponse

type GetTransactionResponse struct {
	Status           string           `json:"status"`
	BlockHash        string           `json:"block_hash"`
	BlockNumber      uint64           `json:"block_number"`
	TransactionIndex uint64           `json:"transaction_index"`
	Transaction      data.Transaction `json:"transaction"`
}

GetTransactionResponse -

type Invocation

type Invocation struct {
	CallerAddress      data.Felt          `json:"caller_address"`
	ContractAddress    data.Felt          `json:"contract_address"`
	Calldata           []string           `json:"calldata"`
	CallType           string             `json:"call_type"`
	ClassHash          data.Felt          `json:"class_hash"`
	Selector           data.Felt          `json:"selector"`
	EntrypointType     string             `json:"entry_point_type"`
	Result             []string           `json:"result"`
	ExecutionResources ExecutionResources `json:"execution_resources"`
	InternalCalls      []Invocation       `json:"internal_calls"`
	Events             []data.Event       `json:"events"`
	Messages           []data.Message     `json:"messages"`
}

Invocation -

type Receipt

type Receipt struct {
	TransactionIndex   uint64             `json:"transaction_index"`
	TransactionHash    string             `json:"transaction_hash"`
	L2ToL1Messages     []data.Message     `json:"l2_to_l1_messages"`
	L1ToL2Message      data.Message       `json:"l1_to_l2_consumed_message"`
	Events             []data.Event       `json:"events"`
	ExecutionResources ExecutionResources `json:"execution_resources"`
	ActualFee          data.Felt          `json:"actual_fee"`
}

Receipt -

type Response

type Response[T any] struct {
	Result T `json:"result"`
}

Response -

type Trace

type Trace struct {
	ValidateInvocation    *Invocation `json:"validate_invocation,omitempty"`
	FunctionInvocation    *Invocation `json:"function_invocation,omitempty"`
	FeeTransferInvocation *Invocation `json:"fee_transfer_invocation,omitempty"`
	Signature             []string    `json:"signature"`
	TransactionHash       data.Felt   `json:"transaction_hash"`
}

Trace -

type TraceResponse

type TraceResponse struct {
	Traces []Trace `json:"traces"`
}

TraceResponse -

type TransactionStatus

type TransactionStatus struct {
	Status    string `json:"tx_status"`
	BlockHash string `json:"block_hash"`
}

TransactionStatus -

Jump to

Keyboard shortcuts

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