Skip to content

Commit

Permalink
Implements new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagodeev committed Dec 19, 2024
1 parent 25f44cd commit 3f85e3b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
12 changes: 11 additions & 1 deletion rpc/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ func (provider *Provider) Nonce(ctx context.Context, blockID BlockID, contractAd
// Estimates the resources required by a given sequence of transactions when applied on a given state.
// If one of the transactions reverts or fails due to any reason (e.g. validation failure or an internal error),
// a TRANSACTION_EXECUTION_ERROR is returned. For v0-2 transactions the estimate is given in wei, and for v3 transactions it is given in fri.
//
// Parameters:
// - ctx: The context of the function call
// - requests: A sequence of transactions to estimate, running each transaction on the state resulting from applying all the previous ones
// - simulationFlags: Describes what parts of the transaction should be executed
// - blockID: The hash of the requested block, or number (height) of the requested block, or a block tag, for the block referencing the state or call the transaction on
// Returns:
// - []FeeEstimation: A sequence of fee estimation where the i'th estimate corresponds to the i'th transaction
// - error: An error if any occurred during the execution
func (provider *Provider) EstimateFee(ctx context.Context, requests []BroadcastTxn, simulationFlags []SimulationFlag, blockID BlockID) ([]FeeEstimation, error) {
var raw []FeeEstimation
if err := do(ctx, provider.c, "starknet_estimateFee", &raw, requests, simulationFlags, blockID); err != nil {
Expand Down Expand Up @@ -168,7 +177,8 @@ func (provider *Provider) EstimateMessageFee(ctx context.Context, msg MsgFromL1,
// - 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
// - *StorageProofResult: The requested storage proofs. Note that if a requested leaf has the default value,
// the path to it may end in an edge node whose path is not a prefix of the requested leaf, thus effectively proving non-membership
// - error: an error if any occurred during the execution
func (provider *Provider) GetStorageProof(ctx context.Context, storageProofInput StorageProofInput) (*StorageProofResult, error) {
var raw StorageProofResult
Expand Down
4 changes: 2 additions & 2 deletions rpc/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ var (
Message: "An unexpected error occurred",
}
ErrCompilationError = &RPCError{
Code: 9999, //placeholder number as this error has no code so far. TODO: change this with the next updates
Message: "More data about the compilation failure",
Code: 100,
Message: "Failed to compile the contract",
}
)
1 change: 1 addition & 0 deletions rpc/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

func TestRPCError(t *testing.T) {
t.Skip("TODO: test the new RPCData field before merge")
if testEnv == "mock" {
testConfig := beforeEach(t)
_, err := testConfig.provider.ChainID(context.Background())
Expand Down
12 changes: 11 additions & 1 deletion rpc/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,17 @@ func (provider *Provider) TraceBlockTransactions(ctx context.Context, blockID Bl
// SimulateTransactions simulates transactions on the blockchain.
// Simulate a given sequence of transactions on the requested state, and generate the execution traces.
// Note that some of the transactions may revert, in which case no error is thrown, but revert details can be seen on the returned trace object.
// Note that some of the transactions may revert, this will be reflected by the revert_error property in the trace. Other types of failures (e.g. unexpected error or failure in the validation phase) will result in TRANSACTION_EXECUTION_ERROR.
// Note that some of the transactions may revert, this will be reflected by the revert_error property in the trace. Other
// types of failures (e.g. unexpected error or failure in the validation phase) will result in TRANSACTION_EXECUTION_ERROR.
//
// Parameters:
// - ctx: The context of the function call
// - blockID: The hash of the requested block, or number (height) of the requested block, or a block tag, for the block referencing the state or call the transaction on.
// - txns: A sequence of transactions to simulate, running each transaction on the state resulting from applying all the previous ones
// - simulationFlags: Describes what parts of the transaction should be executed
// Returns:
// - []SimulatedTransaction: The execution trace and consumed resources of the required transactions
// - error: An error if any occurred during the execution
func (provider *Provider) SimulateTransactions(ctx context.Context, blockID BlockID, txns []BroadcastTxn, simulationFlags []SimulationFlag) ([]SimulatedTransaction, error) {

var output []SimulatedTransaction
Expand Down
4 changes: 2 additions & 2 deletions rpc/types_executables.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type CasmCompiledContractClass struct {
Prime NumAsHex `json:"prime"`
CompilerVersion string `json:"compiler_version"`
Hints []Hints `json:"hints"`
// a list of sizes of segments in the bytecode, each segment is hashed invidually when computing the bytecode hash
// a list of sizes of segments in the bytecode, each segment is hashed individually when computing the bytecode hash
BytecodeSegmentLengths []int `json:"bytecode_segment_lengths,omitempty"`
}

Expand Down Expand Up @@ -152,7 +152,7 @@ type ResOperand struct {

type Deref CellRef

// A (CellRef, offsest) tuple, but adapted to a golang struct
// A (CellRef, offset) tuple, but adapted to a golang struct
type DoubleDeref struct {
CellRef CellRef
Offset int
Expand Down
3 changes: 3 additions & 0 deletions rpc/types_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,13 @@ type DeclareTxnV3 struct {
type ResourceBoundsMapping struct {
// The max amount and max price per unit of L1 gas used in this tx
L1Gas ResourceBounds `json:"l1_gas"`
// The max amount and max price per unit of L1 blob gas used in this tx
L1DataGas ResourceBounds `json:"l1_data_gas"`
// The max amount and max price per unit of L2 gas used in this tx
L2Gas ResourceBounds `json:"l2_gas"`
}

// DA_MODE: Specifies a storage domain in Starknet. Each domain has different guarantees regarding availability
type DataAvailabilityMode string

const (
Expand Down

0 comments on commit 3f85e3b

Please sign in to comment.