rpcv7

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2025 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const ExecutionStepsHeader string = "X-Cairo-Steps"

Variables

This section is empty.

Functions

func MakeContractError

func MakeContractError(err json.RawMessage) *jsonrpc.Error

Types

type AddTxResponse

type AddTxResponse struct {
	TransactionHash *felt.Felt `json:"transaction_hash"`
	ContractAddress *felt.Felt `json:"contract_address,omitempty"`
	ClassHash       *felt.Felt `json:"class_hash,omitempty"`
}

type BlockID

type BlockID struct {
	Pending bool
	Latest  bool
	Hash    *felt.Felt
	Number  uint64
}

https://github.com/starkware-libs/starknet-specs/blob/a789ccc3432c57777beceaa53a34a7ae2f25fda0/api/starknet_api_openrpc.json#L814

func (*BlockID) GetHash

func (b *BlockID) GetHash() *felt.Felt

func (*BlockID) GetNumber

func (b *BlockID) GetNumber() uint64

func (*BlockID) IsLatest

func (b *BlockID) IsLatest() bool

func (*BlockID) IsPending

func (b *BlockID) IsPending() bool

func (*BlockID) UnmarshalJSON

func (b *BlockID) UnmarshalJSON(data []byte) error

type BlockIdentifier

type BlockIdentifier interface {
	IsLatest() bool
	IsPending() bool
	GetHash() *felt.Felt
	GetNumber() uint64
	UnmarshalJSON(data []byte) error
}

type BlockWithReceipts

type BlockWithReceipts struct {
	Status rpcv6.BlockStatus `json:"status,omitempty"`
	rpcv6.BlockHeader
	Transactions []TransactionWithReceipt `json:"transactions"`
}

type BroadcastedTransaction

type BroadcastedTransaction struct {
	Transaction
	ContractClass json.RawMessage `json:"contract_class,omitempty" validate:"required_if=Transaction.Type DECLARE"`
	PaidFeeOnL1   *felt.Felt      `json:"paid_fee_on_l1,omitempty" validate:"required_if=Transaction.Type L1_HANDLER"`
}

https://github.com/starkware-libs/starknet-specs/blob/a789ccc3432c57777beceaa53a34a7ae2f25fda0/api/starknet_api_openrpc.json#L1273-L1287

type CasmCompiledContractClass

type CasmCompiledContractClass struct {
	EntryPointsByType EntryPointsByType `json:"entry_points_by_type"`
	// can't use felt.Felt here because prime is larger than felt
	Prime                  string          `json:"prime"`
	CompilerVersion        string          `json:"compiler_version"`
	Bytecode               []*felt.Felt    `json:"bytecode"`
	Hints                  json.RawMessage `json:"hints"`
	BytecodeSegmentLengths []int           `json:"bytecode_segment_lengths,omitempty"`
}

CasmCompiledContractClass follows this specification: https://github.com/starkware-libs/starknet-specs/blob/v0.8.0-rc0/api/starknet_executables.json#L45

type CasmEntryPoint

type CasmEntryPoint struct {
	Offset   *felt.Felt `json:"offset"`
	Selector *felt.Felt `json:"selector"`
	Builtins []string   `json:"builtins"`
}

type ComputationResources

type ComputationResources struct {
	Steps        uint64 `json:"steps"`
	MemoryHoles  uint64 `json:"memory_holes,omitempty"`
	Pedersen     uint64 `json:"pedersen_builtin_applications,omitempty"`
	RangeCheck   uint64 `json:"range_check_builtin_applications,omitempty"`
	Bitwise      uint64 `json:"bitwise_builtin_applications,omitempty"`
	Ecdsa        uint64 `json:"ecdsa_builtin_applications,omitempty"`
	EcOp         uint64 `json:"ec_op_builtin_applications,omitempty"`
	Keccak       uint64 `json:"keccak_builtin_applications,omitempty"`
	Poseidon     uint64 `json:"poseidon_builtin_applications,omitempty"`
	SegmentArena uint64 `json:"segment_arena_builtin,omitempty"`
}

type ContractErrorData

type ContractErrorData struct {
	RevertError json.RawMessage `json:"revert_error"`
}

type DataAvailability

type DataAvailability struct {
	L1Gas     uint64 `json:"l1_gas"`
	L1DataGas uint64 `json:"l1_data_gas"`
}

type DataAvailabilityMode

type DataAvailabilityMode uint32
const (
	DAModeL1 DataAvailabilityMode = iota
	DAModeL2
)

func (DataAvailabilityMode) MarshalText

func (m DataAvailabilityMode) MarshalText() ([]byte, error)

func (*DataAvailabilityMode) UnmarshalJSON

func (m *DataAvailabilityMode) UnmarshalJSON(data []byte) error

type EntryPointsByType

type EntryPointsByType struct {
	Constructor []CasmEntryPoint `json:"CONSTRUCTOR"`
	External    []CasmEntryPoint `json:"EXTERNAL"`
	L1Handler   []CasmEntryPoint `json:"L1_HANDLER"`
}

type Event

type Event struct {
	From *felt.Felt   `json:"from_address,omitempty"`
	Keys []*felt.Felt `json:"keys"`
	Data []*felt.Felt `json:"data"`
}

type ExecutionResources

type ExecutionResources struct {
	ComputationResources
	DataAvailability *DataAvailability `json:"data_availability"`
}

type FeeEstimate

type FeeEstimate struct {
	GasConsumed     *felt.Felt `json:"gas_consumed"`
	GasPrice        *felt.Felt `json:"gas_price"`
	DataGasConsumed *felt.Felt `json:"data_gas_consumed"`
	DataGasPrice    *felt.Felt `json:"data_gas_price"`
	OverallFee      *felt.Felt `json:"overall_fee"`
	Unit            *FeeUnit   `json:"unit,omitempty"`
}

type FeePayment

type FeePayment struct {
	Amount *felt.Felt `json:"amount"`
	Unit   FeeUnit    `json:"unit"`
}

type FeeUnit

type FeeUnit byte
const (
	WEI FeeUnit = iota
	FRI
)

func (FeeUnit) MarshalText

func (u FeeUnit) MarshalText() ([]byte, error)

type FunctionCall

type FunctionCall struct {
	ContractAddress    felt.Felt   `json:"contract_address"`
	EntryPointSelector felt.Felt   `json:"entry_point_selector"`
	Calldata           []felt.Felt `json:"calldata"`
}

https://github.com/starkware-libs/starknet-specs/blob/v0.3.0/api/starknet_api_openrpc.json#L2344

type Handler

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

func New

func New(bcReader blockchain.Reader, syncReader sync.Reader, virtualMachine vm.VM, version string, network *utils.Network,
	logger utils.Logger,
) *Handler

func (*Handler) BlockWithReceipts

func (h *Handler) BlockWithReceipts(id BlockID) (*BlockWithReceipts, *jsonrpc.Error)

func (*Handler) BlockWithTxHashes

func (h *Handler) BlockWithTxHashes(id BlockID) (*rpcv6.BlockWithTxHashes, *jsonrpc.Error)

BlockWithTxHashes returns the block information with transaction hashes given a block ID.

It follows the specification defined here: https://github.com/starkware-libs/starknet-specs/blob/a789ccc3432c57777beceaa53a34a7ae2f25fda0/api/starknet_api_openrpc.json#L11

func (*Handler) BlockWithTxs

func (h *Handler) BlockWithTxs(id BlockID) (*BlockWithTxs, *jsonrpc.Error)

BlockWithTxs returns the block information with full transactions given a block ID.

It follows the specification defined here: https://github.com/starkware-libs/starknet-specs/blob/a789ccc3432c57777beceaa53a34a7ae2f25fda0/api/starknet_api_openrpc.json#L44

func (*Handler) CompiledCasm

func (h *Handler) CompiledCasm(classHash *felt.Felt) (*CasmCompiledContractClass, *jsonrpc.Error)

func (*Handler) EstimateFee

func (h *Handler) EstimateFee(broadcastedTxns []BroadcastedTransaction,
	simulationFlags []SimulationFlag, id BlockID,
) ([]FeeEstimate, http.Header, *jsonrpc.Error)

func (*Handler) EstimateMessageFee

func (h *Handler) EstimateMessageFee(msg MsgFromL1, id BlockID) (*FeeEstimate, http.Header, *jsonrpc.Error)

func (*Handler) Run

func (h *Handler) Run(ctx context.Context) error

func (*Handler) SimulateTransactions

func (h *Handler) SimulateTransactions(id BlockID, transactions []BroadcastedTransaction,
	simulationFlags []SimulationFlag,
) ([]SimulatedTransaction, http.Header, *jsonrpc.Error)

func (*Handler) SpecVersion

func (h *Handler) SpecVersion() (string, *jsonrpc.Error)

func (*Handler) StorageAt

func (h *Handler) StorageAt(address, key felt.Felt, id BlockID) (*felt.Felt, *jsonrpc.Error)

StorageAt gets the value of the storage at the given address and key.

It follows the specification defined here: https://github.com/starkware-libs/starknet-specs/blob/a789ccc3432c57777beceaa53a34a7ae2f25fda0/api/starknet_api_openrpc.json#L110

func (*Handler) SubscribeNewHeads

func (h *Handler) SubscribeNewHeads(ctx context.Context) (uint64, *jsonrpc.Error)

func (*Handler) TraceBlockTransactions

func (h *Handler) TraceBlockTransactions(ctx context.Context, id BlockID) ([]TracedBlockTransaction, http.Header, *jsonrpc.Error)

func (*Handler) TraceTransaction

func (h *Handler) TraceTransaction(ctx context.Context, hash felt.Felt) (*TransactionTrace, http.Header, *jsonrpc.Error)

TraceTransaction returns the trace for a given executed transaction, including internal calls

It follows the specification defined here: https://github.com/starkware-libs/starknet-specs/blob/1ae810e0137cc5d175ace4554892a4f43052be56/api/starknet_trace_api_openrpc.json#L11

func (*Handler) TransactionByBlockIDAndIndex

func (h *Handler) TransactionByBlockIDAndIndex(id BlockID, txIndex int) (*Transaction, *jsonrpc.Error)

TransactionByBlockIDAndIndex returns the details of a transaction identified by the given BlockID and index.

It follows the specification defined here: https://github.com/starkware-libs/starknet-specs/blob/master/api/starknet_api_openrpc.json#L184

func (*Handler) TransactionReceiptByHash

func (h *Handler) TransactionReceiptByHash(hash felt.Felt) (*TransactionReceipt, *jsonrpc.Error)

TransactionReceiptByHash returns the receipt of a transaction identified by the given hash.

It follows the specification defined here: https://github.com/starkware-libs/starknet-specs/blob/master/api/starknet_api_openrpc.json#L222

func (*Handler) TransactionStatus

func (h *Handler) TransactionStatus(ctx context.Context, hash felt.Felt) (*TransactionStatus, *jsonrpc.Error)

func (*Handler) TransactionStatusV0_7

func (h *Handler) TransactionStatusV0_7(ctx context.Context, hash felt.Felt) (*TransactionStatusV0_7, *jsonrpc.Error)

func (*Handler) Unsubscribe

func (h *Handler) Unsubscribe(ctx context.Context, id uint64) (bool, *jsonrpc.Error)

func (*Handler) Version

func (h *Handler) Version() (string, *jsonrpc.Error)

func (*Handler) WithCallMaxSteps

func (h *Handler) WithCallMaxSteps(maxSteps uint64) *Handler

func (*Handler) WithFeeder

func (h *Handler) WithFeeder(feederClient *feeder.Client) *Handler

func (*Handler) WithFilterLimit

func (h *Handler) WithFilterLimit(limit uint) *Handler

WithFilterLimit sets the maximum number of blocks to scan in a single call for event filtering.

func (*Handler) WithGateway

func (h *Handler) WithGateway(gatewayClient rpccore.Gateway) *Handler

func (*Handler) WithIDGen

func (h *Handler) WithIDGen(idgen func() uint64) *Handler

type MsgFromL1

type MsgFromL1 struct {
	// The address of the L1 contract sending the message.
	From common.Address `json:"from_address" validate:"required"`
	// The address of the L1 contract sending the message.
	To felt.Felt `json:"to_address" validate:"required"`
	// The payload of the message.
	Payload  []felt.Felt `json:"payload" validate:"required"`
	Selector felt.Felt   `json:"entry_point_selector" validate:"required"`
}

type MsgToL1

type MsgToL1 struct {
	From    *felt.Felt     `json:"from_address,omitempty"`
	To      common.Address `json:"to_address"`
	Payload []*felt.Felt   `json:"payload"`
}

type Resource

type Resource uint32
const (
	ResourceL1Gas Resource = iota + 1
	ResourceL2Gas
)

func (Resource) MarshalText

func (r Resource) MarshalText() ([]byte, error)

func (*Resource) UnmarshalJSON

func (r *Resource) UnmarshalJSON(data []byte) error

func (*Resource) UnmarshalText

func (r *Resource) UnmarshalText(data []byte) error

type ResourceBounds

type ResourceBounds struct {
	MaxAmount       *felt.Felt `json:"max_amount"`
	MaxPricePerUnit *felt.Felt `json:"max_price_per_unit"`
}

type SimulatedTransaction

type SimulatedTransaction struct {
	TransactionTrace *TransactionTrace `json:"transaction_trace,omitempty"`
	FeeEstimation    FeeEstimate       `json:"fee_estimation,omitempty"`
}

type SimulationFlag

type SimulationFlag int
const (
	SkipValidateFlag SimulationFlag = iota + 1
	SkipFeeChargeFlag
)

func (*SimulationFlag) UnmarshalJSON

func (s *SimulationFlag) UnmarshalJSON(bytes []byte) (err error)

type SubscriptionBlockID

type SubscriptionBlockID struct {
	Latest bool
	Hash   *felt.Felt
	Number uint64
}

As per the spec, this is the same as BlockID, but without `pending`

func (*SubscriptionBlockID) GetHash

func (b *SubscriptionBlockID) GetHash() *felt.Felt

func (*SubscriptionBlockID) GetNumber

func (b *SubscriptionBlockID) GetNumber() uint64

func (*SubscriptionBlockID) IsLatest

func (b *SubscriptionBlockID) IsLatest() bool

func (*SubscriptionBlockID) IsPending

func (b *SubscriptionBlockID) IsPending() bool

func (*SubscriptionBlockID) UnmarshalJSON

func (b *SubscriptionBlockID) UnmarshalJSON(data []byte) error

type SubscriptionResponse

type SubscriptionResponse struct {
	Version string `json:"jsonrpc"`
	Method  string `json:"method"`
	Params  any    `json:"params"`
}

type TracedBlockTransaction

type TracedBlockTransaction struct {
	TraceRoot       *TransactionTrace `json:"trace_root,omitempty"`
	TransactionHash *felt.Felt        `json:"transaction_hash,omitempty"`
}

func AdaptFeederBlockTrace added in v0.13.3

func AdaptFeederBlockTrace(block *BlockWithTxs, blockTrace *starknet.BlockTrace) ([]TracedBlockTransaction, error)

type Transaction

type Transaction struct {
	Hash                  *felt.Felt                   `json:"transaction_hash,omitempty"`
	Type                  TransactionType              `json:"type" validate:"required"`
	Version               *felt.Felt                   `json:"version,omitempty" validate:"required"`
	Nonce                 *felt.Felt                   `json:"nonce,omitempty" validate:"required_unless=Version 0x0"`
	MaxFee                *felt.Felt                   `json:"max_fee,omitempty" validate:"required_if=Version 0x0,required_if=Version 0x1,required_if=Version 0x2"`
	ContractAddress       *felt.Felt                   `json:"contract_address,omitempty"`
	ContractAddressSalt   *felt.Felt                   `json:"contract_address_salt,omitempty" validate:"required_if=Type DEPLOY,required_if=Type DEPLOY_ACCOUNT"`
	ClassHash             *felt.Felt                   `json:"class_hash,omitempty" validate:"required_if=Type DEPLOY,required_if=Type DEPLOY_ACCOUNT"`
	ConstructorCallData   *[]*felt.Felt                `json:"constructor_calldata,omitempty" validate:"required_if=Type DEPLOY,required_if=Type DEPLOY_ACCOUNT"`
	SenderAddress         *felt.Felt                   `` /* 139-byte string literal not displayed */
	Signature             *[]*felt.Felt                `json:"signature,omitempty" validate:"required"`
	CallData              *[]*felt.Felt                `json:"calldata,omitempty" validate:"required_if=Type INVOKE"`
	EntryPointSelector    *felt.Felt                   `json:"entry_point_selector,omitempty" validate:"required_if=Type INVOKE Version 0x0"`
	CompiledClassHash     *felt.Felt                   `json:"compiled_class_hash,omitempty" validate:"required_if=Type DECLARE Version 0x2"`
	ResourceBounds        *map[Resource]ResourceBounds `json:"resource_bounds,omitempty" validate:"required_if=Version 0x3"`
	Tip                   *felt.Felt                   `json:"tip,omitempty" validate:"required_if=Version 0x3"`
	PaymasterData         *[]*felt.Felt                `json:"paymaster_data,omitempty" validate:"required_if=Version 0x3"`
	AccountDeploymentData *[]*felt.Felt                `json:"account_deployment_data,omitempty" validate:"required_if=Type INVOKE Version 0x3,required_if=Type DECLARE Version 0x3"`
	NonceDAMode           *DataAvailabilityMode        `json:"nonce_data_availability_mode,omitempty" validate:"required_if=Version 0x3"`
	FeeDAMode             *DataAvailabilityMode        `json:"fee_data_availability_mode,omitempty" validate:"required_if=Version 0x3"`
}

https://github.com/starkware-libs/starknet-specs/blob/a789ccc3432c57777beceaa53a34a7ae2f25fda0/api/starknet_api_openrpc.json#L1252

func AdaptTransaction

func AdaptTransaction(t core.Transaction) *Transaction

type TransactionExecutionErrorData

type TransactionExecutionErrorData struct {
	TransactionIndex uint64          `json:"transaction_index"`
	ExecutionError   json.RawMessage `json:"execution_error"`
}

type TransactionReceipt

type TransactionReceipt struct {
	Type               TransactionType     `json:"type"`
	Hash               *felt.Felt          `json:"transaction_hash"`
	ActualFee          *FeePayment         `json:"actual_fee"`
	ExecutionStatus    TxnExecutionStatus  `json:"execution_status"`
	FinalityStatus     TxnFinalityStatus   `json:"finality_status"`
	BlockHash          *felt.Felt          `json:"block_hash,omitempty"`
	BlockNumber        *uint64             `json:"block_number,omitempty"`
	MessagesSent       []*MsgToL1          `json:"messages_sent"`
	Events             []*Event            `json:"events"`
	ContractAddress    *felt.Felt          `json:"contract_address,omitempty"`
	RevertReason       string              `json:"revert_reason,omitempty"`
	ExecutionResources *ExecutionResources `json:"execution_resources,omitempty"`
	MessageHash        string              `json:"message_hash,omitempty"`
}

https://github.com/starkware-libs/starknet-specs/blob/master/api/starknet_api_openrpc.json#L1871

func AdaptReceipt

func AdaptReceipt(receipt *core.TransactionReceipt, txn core.Transaction,
	finalityStatus TxnFinalityStatus, blockHash *felt.Felt, blockNumber uint64,
) *TransactionReceipt

todo(Kirill): try to replace core.Transaction with rpc.Transaction type

type TransactionStatus

type TransactionStatus struct {
	Finality      TxnStatus          `json:"finality_status"`
	Execution     TxnExecutionStatus `json:"execution_status,omitempty"`
	FailureReason string             `json:"failure_reason,omitempty"`
}

type TransactionStatusV0_7

type TransactionStatusV0_7 struct {
	Finality  TxnStatus          `json:"finality_status"`
	Execution TxnExecutionStatus `json:"execution_status,omitempty"`
}

In 0.7.0, the failure reason is not returned in the TransactionStatus response.

type TransactionTrace added in v0.13.3

type TransactionTrace struct {
	Type                  TransactionType           `json:"type"`
	ValidateInvocation    *rpcv6.FunctionInvocation `json:"validate_invocation,omitempty"`
	ExecuteInvocation     *rpcv6.ExecuteInvocation  `json:"execute_invocation,omitempty" validate:"required_if=Type INVOKE"`
	FeeTransferInvocation *rpcv6.FunctionInvocation `json:"fee_transfer_invocation,omitempty"`
	ConstructorInvocation *rpcv6.FunctionInvocation `json:"constructor_invocation,omitempty" validate:"required_if=Type DEPLOY_ACCOUNT"`
	FunctionInvocation    *rpcv6.FunctionInvocation `json:"function_invocation,omitempty" validate:"required_if=Type L1_HANDLER"`
	StateDiff             *rpcv6.StateDiff          `json:"state_diff,omitempty"`
	ExecutionResources    *ExecutionResources       `json:"execution_resources"`
}

func AdaptVMTransactionTrace added in v0.13.3

func AdaptVMTransactionTrace(trace *vm.TransactionTrace) TransactionTrace

func (*TransactionTrace) TotalComputationResources added in v0.13.3

func (t *TransactionTrace) TotalComputationResources() ComputationResources

type TransactionType

type TransactionType uint8
const (
	Invalid TransactionType = iota
	TxnDeclare
	TxnDeploy
	TxnDeployAccount
	TxnInvoke
	TxnL1Handler
)

func (TransactionType) MarshalText

func (t TransactionType) MarshalText() ([]byte, error)

func (TransactionType) String

func (t TransactionType) String() string

func (*TransactionType) UnmarshalJSON

func (t *TransactionType) UnmarshalJSON(data []byte) error

type TransactionWithReceipt

type TransactionWithReceipt struct {
	Transaction *Transaction        `json:"transaction"`
	Receipt     *TransactionReceipt `json:"receipt"`
}

type TxnExecutionStatus

type TxnExecutionStatus uint8
const (
	TxnSuccess TxnExecutionStatus = iota + 1
	TxnFailure
)

func (TxnExecutionStatus) MarshalText

func (es TxnExecutionStatus) MarshalText() ([]byte, error)

type TxnFinalityStatus

type TxnFinalityStatus uint8
const (
	TxnAcceptedOnL2 TxnFinalityStatus = iota + 3
	TxnAcceptedOnL1
)

func (TxnFinalityStatus) MarshalText

func (fs TxnFinalityStatus) MarshalText() ([]byte, error)

type TxnStatus

type TxnStatus uint8
const (
	TxnStatusReceived TxnStatus = iota + 1
	TxnStatusRejected
	TxnStatusAcceptedOnL2
	TxnStatusAcceptedOnL1
)

func (TxnStatus) MarshalText

func (s TxnStatus) MarshalText() ([]byte, error)

Jump to

Keyboard shortcuts

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