gateway

package
v0.0.0-...-00a565c Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	INVOKE         string = "INVOKE_FUNCTION"
	DEPLOY         string = "DEPLOY"
	DEPLOY_ACCOUNT string = "DEPLOY_ACCOUNT"
	DECLARE        string = "DECLARE"
	GOERLI_ID      string = "SN_GOERLI"
	GOERLI2_ID     string = "SN_GOERLI2"
	MAINNET_ID     string = "SN_MAIN"
	LOCAL_BASE     string = "http://localhost:5050"
	GOERLI_BASE    string = "https://alpha4.starknet.io"
	GOERLI2_BASE   string = "https://alpha4-2.starknet.io"
	MAINNET_BASE   string = "https://alpha-mainnet.starknet.io"
)

Variables

View Source
var ErrInvalidBlock = errors.New("invalid block")

Functions

func NewError

func NewError(resp *http.Response) error

NewError creates a new Error from an API response.

Types

type Block

type Block struct {
	BlockHash           string               `json:"block_hash"`
	ParentBlockHash     string               `json:"parent_block_hash"`
	BlockNumber         int                  `json:"block_number"`
	StateRoot           string               `json:"state_root"`
	Status              string               `json:"status"`
	Transactions        []Transaction        `json:"transactions"`
	Timestamp           int                  `json:"timestamp"`
	TransactionReceipts []TransactionReceipt `json:"transaction_receipts"`
}

type BlockOptions

type BlockOptions struct {
	BlockNumber *uint64
	BlockHash   string
	Tag         string
}

type Bytecode

type Bytecode []string

type Code

type Code struct {
	Bytecode Bytecode   `json:"bytecode"`
	Abi      *types.ABI `json:"abi"`
}

func (*Code) UnmarshalJSON

func (c *Code) UnmarshalJSON(content []byte) error

type ContractAddresses

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

type DeclareRequest

type DeclareRequest struct {
	Type          string              `json:"type"`
	SenderAddress string              `json:"sender_address"`
	MaxFee        string              `json:"max_fee"`
	Nonce         string              `json:"nonce"`
	Signature     []string            `json:"signature"`
	ContractClass types.ContractClass `json:"contract_class"`
}

type DeployAccountRequest

type DeployAccountRequest types.DeployAccountRequest

func (DeployAccountRequest) MarshalJSON

func (d DeployAccountRequest) MarshalJSON() ([]byte, error)

type DeployRequest

type DeployRequest types.DeployRequest

func (DeployRequest) MarshalJSON

func (d DeployRequest) MarshalJSON() ([]byte, error)

type Error

type Error struct {
	StatusCode int    `json:"-"`
	Body       []byte `json:"-"`

	Code    string `json:"code"`
	Message string `json:"message"`
}

func (Error) Error

func (e Error) Error() string

Error implements the error interface.

type Event

type Event struct {
	Order       int           `json:"order,omitempty"`
	FromAddress string        `json:"from_address,omitempty"`
	Keys        []*types.Felt `json:"keys,omitempty"`
	Data        []*types.Felt `json:"data,omitempty"`
}

type ExecutionResources

type ExecutionResources struct {
	NSteps                 int `json:"n_steps"`
	BuiltinInstanceCounter struct {
		PedersenBuiltin   int `json:"pedersen_builtin"`
		RangeCheckBuiltin int `json:"range_check_builtin"`
		BitwiseBuiltin    int `json:"bitwise_builtin"`
		OutputBuiltin     int `json:"output_builtin"`
		EcdsaBuiltin      int `json:"ecdsa_builtin"`
		EcOpBuiltin       int `json:"ec_op_builtin"`
	} `json:"builtin_instance_counter"`
	NMemoryHoles int `json:"n_memory_holes"`
}

type FunctionCall

type FunctionCall types.FunctionCall

func (FunctionCall) MarshalJSON

func (f FunctionCall) MarshalJSON() ([]byte, error)

type FunctionInvocation

type FunctionInvocation struct {
	CallerAddress      string               `json:"caller_address"`
	ContractAddress    string               `json:"contract_address"`
	Calldata           []string             `json:"calldata"`
	CallType           string               `json:"call_type"`
	ClassHash          string               `json:"class_hash"`
	Selector           string               `json:"selector"`
	EntryPointType     string               `json:"entry_point_type"`
	Result             []string             `json:"result"`
	ExecutionResources ExecutionResources   `json:"execution_resources"`
	InternalCalls      []FunctionInvocation `json:"internal_calls"`
	Events             []Event              `json:"events"`
	Messages           []interface{}        `json:"messages"`
}

type Gateway

type Gateway struct {
	Base    string `json:"base"`
	Feeder  string `json:"feeder"`
	Gateway string `json:"gateway"`
	ChainId string `json:"chainId"`
	// contains filtered or unexported fields
}

func NewClient

func NewClient(opts ...Option) *Gateway

Instantiate a new StarkNet Gateway client - defaults to the GOERLI endpoints

func (*Gateway) AccountNonce

func (sg *Gateway) AccountNonce(ctx context.Context, address types.Hash) (*big.Int, error)

func (*Gateway) BlockByHash

func (sg *Gateway) BlockByHash(context.Context, string, string) (*Block, error)

func (*Gateway) BlockByNumber

func (sg *Gateway) BlockByNumber(context.Context, *big.Int, string) (*Block, error)

func (*Gateway) Call

func (sg *Gateway) Call(ctx context.Context, call types.FunctionCall, blockHashOrTag string) ([]string, error)

'call_contract' wrapper and can accept a blockId in the hash or height format

func (*Gateway) ChainID

func (sg *Gateway) ChainID(context.Context) (string, error)

func (*Gateway) Class

func (*Gateway) ClassAt

func (*Gateway) ClassByHash

func (sg *Gateway) ClassByHash(ctx context.Context, hash string) (*types.ContractClass, error)

func (*Gateway) ClassHashAt

func (sg *Gateway) ClassHashAt(ctx context.Context, address string) (*types.Felt, error)

func (*Gateway) ContractAddresses

func (sg *Gateway) ContractAddresses(ctx context.Context) (*ContractAddresses, error)

func (*Gateway) Declare

func (sg *Gateway) Declare(ctx context.Context, contract types.ContractClass, declareRequest DeclareRequest) (resp types.AddDeclareResponse, err error)

'add_transaction' wrapper for compressing and declaring a contract class

func (*Gateway) Deploy

func (sg *Gateway) Deploy(ctx context.Context, contract types.ContractClass, deployRequest types.DeployRequest) (resp types.AddDeployResponse, err error)

'add_transaction' wrapper for compressing and deploying a compiled StarkNet contract

func (*Gateway) DeployAccount

func (sg *Gateway) DeployAccount(ctx context.Context, deployAccountRequest types.DeployAccountRequest) (resp types.AddDeployResponse, err error)

'add_transaction' wrapper for deploying a compiled StarkNet account

func (*Gateway) EstimateFee

func (sg *Gateway) EstimateFee(ctx context.Context, call types.FunctionInvoke, hash string) (*types.FeeEstimate, error)

func (*Gateway) FullContract

func (sg *Gateway) FullContract(ctx context.Context, contract string) (*types.ContractClass, error)

func (*Gateway) Invoke

'add_transaction' wrapper for invokation requests

func (*Gateway) Nonce

func (sg *Gateway) Nonce(ctx context.Context, contractAddress, blockHashOrTag string) (*big.Int, error)

func (*Gateway) StateUpdate

func (sg *Gateway) StateUpdate(ctx context.Context, opts *BlockOptions) (*StateUpdate, error)

func (*Gateway) TransactionByHash

func (gw *Gateway) TransactionByHash(ctx context.Context, hash string) (*Transaction, error)

func (*Gateway) TransactionTrace

func (gw *Gateway) TransactionTrace(ctx context.Context, txHash string) (*TransactionTrace, error)

func (*Gateway) WaitForTransaction

func (gw *Gateway) WaitForTransaction(ctx context.Context, txHash string, interval, maxPoll int) (n int, receipt *TransactionReceipt, err error)

type GatewayFunctionCall

type GatewayFunctionCall struct {
	FunctionCall
	Signature []string `json:"signature"`
}

type GatewayProvider

type GatewayProvider struct {
	Gateway
}

func NewProvider

func NewProvider(opts ...Option) *GatewayProvider

func (*GatewayProvider) BlockByHash

func (p *GatewayProvider) BlockByHash(ctx context.Context, hash, scope string) (*Block, error)

func (*GatewayProvider) BlockByNumber

func (p *GatewayProvider) BlockByNumber(ctx context.Context, number *big.Int, scope string) (*Block, error)

func (*GatewayProvider) Class

func (p *GatewayProvider) Class(ctx context.Context, classHash string) (*types.ContractClass, error)

func (*GatewayProvider) ClassAt

func (p *GatewayProvider) ClassAt(ctx context.Context, contractAddress string) (*types.ContractClass, error)

func (*GatewayProvider) ClassHashAt

func (p *GatewayProvider) ClassHashAt(ctx context.Context, contractAddress string) (*types.Felt, error)

func (*GatewayProvider) TransactionByHash

func (p *GatewayProvider) TransactionByHash(ctx context.Context, hash string) (*Transaction, error)

type L1Message

type L1Message struct {
	ToAddress string        `json:"to_address,omitempty"`
	Payload   []*types.Felt `json:"payload,omitempty"`
}

type L2Message

type L2Message struct {
	FromAddress string        `json:"from_address,omitempty"`
	Payload     []*types.Felt `json:"payload,omitempty"`
}

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures how we set up the connection.

func WithBaseURL

func WithBaseURL(baseURL string) Option

func WithChain

func WithChain(chainID string) Option

func WithErrorHandler

func WithErrorHandler(f func(e error) error) Option

WithErrorHandler returns an Option to set the error handler to be used.

func WithHttpClient

func WithHttpClient(client http.Client) Option

type StarkResp

type StarkResp struct {
	Result []string `json:"result"`
}

type StarknetTransaction

type StarknetTransaction struct {
	TransactionIndex int         `json:"transaction_index"`
	BlockNumber      int         `json:"block_number"`
	Transaction      Transaction `json:"transaction"`
	BlockHash        string      `json:"block_hash"`
	Status           string      `json:"status"`
}

type StateUpdate

type StateUpdate struct {
	BlockHash string `json:"block_hash"`
	NewRoot   string `json:"new_root"`
	OldRoot   string `json:"old_root"`
	StateDiff struct {
		StorageDiffs      map[string]interface{} `json:"storage_diffs"`
		DeployedContracts []struct {
			Address   string `json:"address"`
			ClassHash string `json:"class_hash"`
		} `json:"deployed_contracts"`
	} `json:"state_diff"`
}

type StorageAtOptions

type StorageAtOptions struct {
	BlockNumber int    `url:"blockNumber,omitempty"`
	BlockHash   string `url:"blockHash,omitempty"`
}

type Transaction

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

type TransactionOptions

type TransactionOptions struct {
	TransactionId   uint64 `url:"transactionId,omitempty"`
	TransactionHash string `url:"transactionHash,omitempty"`
}

type TransactionReceipt

type TransactionReceipt struct {
	Status                types.TransactionState `json:"status"`
	BlockHash             string                 `json:"block_hash"`
	BlockNumber           int                    `json:"block_number"`
	TransactionIndex      int                    `json:"transaction_index"`
	TransactionHash       string                 `json:"transaction_hash"`
	L1ToL2ConsumedMessage struct {
		FromAddress string   `json:"from_address"`
		ToAddress   string   `json:"to_address"`
		Selector    string   `json:"selector"`
		Payload     []string `json:"payload"`
	} `json:"l1_to_l2_consumed_message"`
	L2ToL1Messages     []interface{}      `json:"l2_to_l1_messages"`
	Events             []interface{}      `json:"events"`
	ExecutionResources ExecutionResources `json:"execution_resources"`
}

type TransactionReceiptType

type TransactionReceiptType struct {
	TransactionHash string       `json:"txn_hash,omitempty"`
	Status          string       `json:"status,omitempty"`
	StatusData      string       `json:"status_data,omitempty"`
	MessagesSent    []*L1Message `json:"messages_sent,omitempty"`
	L1OriginMessage *L2Message   `json:"l1_origin_message,omitempty"`
	Events          []*Event     `json:"events,omitempty"`
}

type TransactionStatus

type TransactionStatus struct {
	TxStatus        string `json:"tx_status"`
	BlockHash       string `json:"block_hash,omitempty"`
	TxFailureReason struct {
		ErrorMessage string `json:"error_message,omitempty"`
	} `json:"tx_failure_reason,omitempty"`
}

type TransactionStatusOptions

type TransactionStatusOptions struct {
	TransactionId   uint64 `url:"transactionId,omitempty"`
	TransactionHash string `url:"transactionHash,omitempty"`
}

type TransactionTrace

type TransactionTrace struct {
	FunctionInvocation FunctionInvocation `json:"function_invocation"`
	Signature          []*types.Felt      `json:"signature"`
}

Jump to

Keyboard shortcuts

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