Skip to content

Commit

Permalink
Adds GetStorageProof method
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagodeev committed Oct 3, 2024
1 parent 9cb1fb9 commit 9d37844
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
15 changes: 15 additions & 0 deletions mocks/mock_rpc_provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions rpc/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,20 @@ func (provider *Provider) EstimateMessageFee(ctx context.Context, msg MsgFromL1,
}
return &raw, nil
}

// Get merkle paths in one of the state tries: global state, classes, individual contract
//
// Parameters:
// - ctx: The context of the function call
// - storageProofInput: an input containing at least one of the fields filled
// Returns:
// - *StorageProofResult: the proofs of the field passed in the input
// - error: an error if any occurred during the execution
func (provider *Provider) GetStorageProof(ctx context.Context, storageProofInput StorageProofInput) (*StorageProofResult, error) {
var raw StorageProofResult
if err := do(ctx, provider.c, "starknet_getStorageProof", &raw, storageProofInput); err != nil {

return nil, tryUnwrapToRPCErr(err)
}
return &raw, nil
}
1 change: 1 addition & 0 deletions rpc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type RpcProvider interface {
EstimateMessageFee(ctx context.Context, msg MsgFromL1, blockID BlockID) (*FeeEstimation, error)
Events(ctx context.Context, input EventsInput) (*EventChunk, error)
BlockWithReceipts(ctx context.Context, blockID BlockID) (interface{}, error)
GetStorageProof(ctx context.Context, storageProofInput StorageProofInput) (*StorageProofResult, error)
GetTransactionStatus(ctx context.Context, transactionHash *felt.Felt) (*TxnStatusResp, error)
Nonce(ctx context.Context, blockID BlockID, contractAddress *felt.Felt) (*felt.Felt, error)
SimulateTransactions(ctx context.Context, blockID BlockID, txns []BroadcastTxn, simulationFlags []SimulationFlag) ([]SimulatedTransaction, error)
Expand Down
40 changes: 40 additions & 0 deletions rpc/types_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,46 @@ type ContractClass struct {
ABI string `json:"abi,omitempty"`
}

// You must provide one of these fields
type StorageProofInput struct {
// A list of the class hashes for which we want to prove membership in the classes trie
ClassHashes []*felt.Felt `json:"class_hashes,omitempty"`
// A list of contracts for which we want to prove membership in the global state trie
ContractAddresses []*felt.Felt `json:"contract_addresses,omitempty"`
// A list of (contract_address, storage_keys) pairs
ContractsStorageKeys []ContractStorageKeys `json:"contracts_storage_keys,omitempty"`
}

type StorageProofResult struct {
ClassesProof NodeHashToNode `json:"classes_proof,omitempty"`
ContractsProof NodeHashToNode `json:"contracts_proof,omitempty"`
ContractsStorageProofs []NodeHashToNode `json:"contracts_storage_proofs,omitempty"`
}

type ContractStorageKeys struct {
ContractAddress *felt.Felt `json:"contract_address"`
StorageKeys []*felt.Felt `json:"storage_keys"`
}

// A node_hash -> node mapping of all the nodes in the union of the paths between the requested leaves and the root (for each node present, its sibling is also present)
type NodeHashToNode struct {
NodeHash *felt.Felt `json:"node_hash"`
Node MerkleNode `json:"node"`
}

type MerkleNode struct {
Path uint `json:"path"`
Length uint `json:"length"`
Value *felt.Felt `json:"value"`
// the hash of the child nodes, if not present then the node is a leaf
ChildrenHashes ChildrenHashes `json:"children_hashes,omitempty"`
}

type ChildrenHashes struct {
Left *felt.Felt `json:"left"`
Right *felt.Felt `json:"right"`
}

// UnmarshalJSON unmarshals the JSON content into the DeprecatedContractClass struct.
//
// It takes a byte array `content` as a parameter and returns an error if there is any.
Expand Down

0 comments on commit 9d37844

Please sign in to comment.