Skip to content

Commit

Permalink
Return all execution resources in rpc v0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
joshklop authored and omerfirmak committed Dec 2, 2023
1 parent 2b12b53 commit 27c1ac2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
16 changes: 6 additions & 10 deletions rpc/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,7 @@ func TestLegacyTransactionReceiptByHash(t *testing.T) {
"messages_sent": [],
"events": [],
"contract_address": "0x20cfa74ee3564b4cd5435cdace0f9c4d43b939620e4a0bb5076105df0a626c6",
"execution_resources":{"steps":"0x1d"}
"execution_resources": {"bitwise_builtin_applications":"0x0", "ec_op_builtin_applications":"0x0", "ecdsa_builtin_applications":"0x0", "keccak_builtin_applications":"0x0", "memory_holes":"0x0", "pedersen_builtin_applications":"0x0", "poseidon_builtin_applications":"0x0", "range_check_builtin_applications":"0x0", "steps":"0x1d"}
}`,
},
"without contract addr": {
Expand All @@ -1564,7 +1564,7 @@ func TestLegacyTransactionReceiptByHash(t *testing.T) {
}
],
"events": [],
"execution_resources":{"steps":"0x1f"}
"execution_resources":{"bitwise_builtin_applications":"0x0", "ec_op_builtin_applications":"0x0", "ecdsa_builtin_applications":"0x0", "keccak_builtin_applications":"0x0", "memory_holes":"0x0", "pedersen_builtin_applications":"0x0", "poseidon_builtin_applications":"0x0", "range_check_builtin_applications":"0x0", "steps":"0x1f"}
}`,
},
}
Expand Down Expand Up @@ -1598,7 +1598,7 @@ func TestLegacyTransactionReceiptByHash(t *testing.T) {
}
],
"events": [],
"execution_resources":{"steps":"0x1f"}
"execution_resources":{"bitwise_builtin_applications":"0x0", "ec_op_builtin_applications":"0x0", "ecdsa_builtin_applications":"0x0", "keccak_builtin_applications":"0x0", "memory_holes":"0x0", "pedersen_builtin_applications":"0x0", "poseidon_builtin_applications":"0x0", "range_check_builtin_applications":"0x0", "steps":"0x1f"}
}`

txHash := block0.Transactions[i].Hash()
Expand Down Expand Up @@ -1629,7 +1629,7 @@ func TestLegacyTransactionReceiptByHash(t *testing.T) {
}
],
"events": [],
"execution_resources":{"steps":"0x1f"}
"execution_resources":{"bitwise_builtin_applications":"0x0", "ec_op_builtin_applications":"0x0", "ecdsa_builtin_applications":"0x0", "keccak_builtin_applications":"0x0", "memory_holes":"0x0", "pedersen_builtin_applications":"0x0", "poseidon_builtin_applications":"0x0", "range_check_builtin_applications":"0x0", "steps":"0x1f"}
}`

txHash := block0.Transactions[i].Hash()
Expand All @@ -1655,7 +1655,7 @@ func TestLegacyTransactionReceiptByHash(t *testing.T) {
"messages_sent": [],
"events": [],
"revert_reason": "Error in the called contract (0x00b1461de04c6a1aa3375bdf9b7723a8779c082ffe21311d683a0b15c078b5dc):\nError at pc=0:25:\nGot an exception while executing a hint.\nCairo traceback (most recent call last):\nUnknown location (pc=0:731)\nUnknown location (pc=0:677)\nUnknown location (pc=0:291)\nUnknown location (pc=0:314)\n\nError in the called contract (0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7):\nError at pc=0:104:\nGot an exception while executing a hint.\nCairo traceback (most recent call last):\nUnknown location (pc=0:1678)\nUnknown location (pc=0:1664)\n\nError in the called contract (0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7):\nError at pc=0:6:\nGot an exception while executing a hint: Assertion failed, 0 % 0x800000000000011000000000000000000000000000000000000000000000001 is equal to 0\nCairo traceback (most recent call last):\nUnknown location (pc=0:1238)\nUnknown location (pc=0:1215)\nUnknown location (pc=0:836)\n",
"execution_resources":{"steps":"0x0"}
"execution_resources":{"bitwise_builtin_applications":"0x0", "ec_op_builtin_applications":"0x0", "ecdsa_builtin_applications":"0x0", "keccak_builtin_applications":"0x0", "memory_holes":"0x0", "pedersen_builtin_applications":"0x0", "poseidon_builtin_applications":"0x0", "range_check_builtin_applications":"0x0","steps":"0x0"}
}`

integClient := feeder.NewTestClient(t, utils.Integration)
Expand Down Expand Up @@ -1710,11 +1710,7 @@ func TestLegacyTransactionReceiptByHash(t *testing.T) {
]
}
],
"execution_resources": {
"steps": "0x267",
"range_check_builtin_applications": "0x13",
"memory_holes": "0x4"
},
"execution_resources": {"bitwise_builtin_applications":"0x0", "ec_op_builtin_applications":"0x0", "ecdsa_builtin_applications":"0x0", "keccak_builtin_applications":"0x0", "memory_holes":"0x4", "pedersen_builtin_applications":"0x0", "poseidon_builtin_applications":"0x0", "range_check_builtin_applications":"0x13", "steps":"0x267"},
"actual_fee": "0x16d8b4ad4000",
"type": "INVOKE"
}`
Expand Down
34 changes: 24 additions & 10 deletions rpc/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,31 @@ type ExecutionResources struct {
}

func (r *ExecutionResources) MarshalJSON() ([]byte, error) {
type resources ExecutionResources // Avoid infinite recursion with MarshalJSON.
rawJSON, err := json.Marshal(resources(*r))
if !r.isLegacy {
return rawJSON, err
}

hexMap := make(map[string]NumAsHex)
if err = json.Unmarshal(rawJSON, &hexMap); err != nil {
return nil, err
if r.isLegacy {
return json.Marshal(struct {
Steps NumAsHex `json:"steps"`
MemoryHoles NumAsHex `json:"memory_holes"`
Pedersen NumAsHex `json:"pedersen_builtin_applications"`
RangeCheck NumAsHex `json:"range_check_builtin_applications"`
Bitwise NumAsHex `json:"bitwise_builtin_applications"`
Ecsda NumAsHex `json:"ecdsa_builtin_applications"`
EcOp NumAsHex `json:"ec_op_builtin_applications"`
Keccak NumAsHex `json:"keccak_builtin_applications"`
Poseidon NumAsHex `json:"poseidon_builtin_applications"`
}{
Steps: NumAsHex(r.Steps),
MemoryHoles: NumAsHex(r.MemoryHoles),
Pedersen: NumAsHex(r.Pedersen),
RangeCheck: NumAsHex(r.RangeCheck),
Bitwise: NumAsHex(r.Bitwise),
Ecsda: NumAsHex(r.Ecsda),
EcOp: NumAsHex(r.EcOp),
Keccak: NumAsHex(r.Keccak),
Poseidon: NumAsHex(r.Poseidon),
})
}
return json.Marshal(hexMap)
type resources ExecutionResources // Avoid infinite recursion with MarshalJSON.
return json.Marshal(resources(*r))
}

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

0 comments on commit 27c1ac2

Please sign in to comment.