Skip to content

Commit

Permalink
Merge branch 'main' into rianhughes/07-getBlockWithReceipts
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes authored Mar 8, 2024
2 parents 6759494 + 4890312 commit e658126
Show file tree
Hide file tree
Showing 14 changed files with 418 additions and 931 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ go run main.go

### RPC

`starknet.go` RPC implements the [Starknet RPC v0.6.0 spec](https://github.com/starkware-libs/starknet-specs/tree/v0.6.0):
`starknet.go` RPC implements the Starknet [RPC v0.7.0 spec](https://github.com/starkware-libs/starknet-specs/tree/v0.7.0-rc2)

| Method | Implemented (*) |
| ------------------------------------------ | ------------------ |
| `starknet_getBlockWithReceipts` | :heavy_check_mark: |
| `starknet_getBlockWithTxHashes` | :heavy_check_mark: |
| `starknet_getBlockWithTxs` | :heavy_check_mark: |
| `starknet_getStateUpdate` | :heavy_check_mark: |
Expand Down
10 changes: 5 additions & 5 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type AccountInterface interface {
SignDeployAccountTransaction(ctx context.Context, tx *rpc.DeployAccountTxn, precomputeAddress *felt.Felt) error
SignDeclareTransaction(ctx context.Context, tx *rpc.DeclareTxnV2) error
PrecomputeAddress(deployerAddress *felt.Felt, salt *felt.Felt, classHash *felt.Felt, constructorCalldata []*felt.Felt) (*felt.Felt, error)
WaitForTransactionReceipt(ctx context.Context, transactionHash *felt.Felt, pollInterval time.Duration) (*rpc.TransactionReceipt, *rpc.RPCError)
WaitForTransactionReceipt(ctx context.Context, transactionHash *felt.Felt, pollInterval time.Duration) (*rpc.TransactionReceiptWithBlockInfo, *rpc.RPCError)
}

var _ AccountInterface = &Account{}
Expand Down Expand Up @@ -525,22 +525,22 @@ func (account *Account) PrecomputeAddress(deployerAddress *felt.Felt, salt *felt
// It returns:
// - *rpc.TransactionReceipt: the transaction receipt
// - error: an error
func (account *Account) WaitForTransactionReceipt(ctx context.Context, transactionHash *felt.Felt, pollInterval time.Duration) (*rpc.TransactionReceipt, *rpc.RPCError) {
func (account *Account) WaitForTransactionReceipt(ctx context.Context, transactionHash *felt.Felt, pollInterval time.Duration) (*rpc.TransactionReceiptWithBlockInfo, *rpc.RPCError) {
t := time.NewTicker(pollInterval)
for {
select {
case <-ctx.Done():
return nil, rpc.Err(rpc.InternalError, ctx.Err())
case <-t.C:
receipt, rpcErr := account.TransactionReceipt(ctx, transactionHash)
receiptWithBlockInfo, rpcErr := account.TransactionReceipt(ctx, transactionHash)
if rpcErr != nil {
if rpcErr.Message == rpc.ErrHashNotFound.Message {
continue
} else {
return nil, rpcErr
}
}
return &receipt, nil
return receiptWithBlockInfo, nil
}
}
}
Expand Down Expand Up @@ -839,7 +839,7 @@ func (account *Account) TraceBlockTransactions(ctx context.Context, blockID rpc.
// - transactionHash: The hash of the transaction.
// Returns:
// - rpc.Transactiontype: rpc.TransactionReceipt, error.
func (account *Account) TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (rpc.TransactionReceipt, *rpc.RPCError) {
func (account *Account) TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (*rpc.TransactionReceiptWithBlockInfo, *rpc.RPCError) {
return account.provider.TransactionReceipt(ctx, transactionHash)
}

Expand Down
13 changes: 8 additions & 5 deletions account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ func TestWaitForTransactionReceiptMOCK(t *testing.T) {
ShouldCallTransactionReceipt bool
Hash *felt.Felt
ExpectedErr *rpc.RPCError
ExpectedReceipt rpc.TransactionReceipt
ExpectedReceipt *rpc.TransactionReceiptWithBlockInfo
}
testSet := map[string][]testSetType{
"mock": {
Expand All @@ -964,10 +964,13 @@ func TestWaitForTransactionReceiptMOCK(t *testing.T) {
Timeout: time.Duration(1000),
Hash: new(felt.Felt).SetUint64(2),
ShouldCallTransactionReceipt: true,
ExpectedReceipt: rpc.InvokeTransactionReceipt{
TransactionHash: new(felt.Felt).SetUint64(2),
ExecutionStatus: rpc.TxnExecutionStatusSUCCEEDED,
ExpectedReceipt: &rpc.TransactionReceiptWithBlockInfo{
TransactionReceipt: rpc.InvokeTransactionReceipt{
TransactionHash: new(felt.Felt).SetUint64(2),
ExecutionStatus: rpc.TxnExecutionStatusSUCCEEDED,
},
},

ExpectedErr: nil,
},
{
Expand All @@ -991,7 +994,7 @@ func TestWaitForTransactionReceiptMOCK(t *testing.T) {
if test.ExpectedErr != nil {
require.Equal(t, test.ExpectedErr, err)
} else {
require.Equal(t, test.ExpectedReceipt.GetExecutionStatus(), (*resp).GetExecutionStatus())
require.Equal(t, test.ExpectedReceipt.GetExecutionStatus(), (resp.TransactionReceipt).GetExecutionStatus())
}

}
Expand Down
4 changes: 2 additions & 2 deletions mocks/mock_rpc_provider.go

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

28 changes: 25 additions & 3 deletions rpc/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,36 @@ func mock_starknet_getTransactionReceipt(result interface{}, method string, args
return errWrongArgs
}

arg0Felt, err := utils.HexToFelt(args[0].(string))
arg0Felt := args[0].(*felt.Felt)

testTxnHash, err := utils.HexToFelt("0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e")
if err != nil {
return err
}
if arg0Felt.Equal(testTxnHash) {
var txnRec struct {
Result UnknownTransactionReceipt `json:"result"`
}
read, err := os.ReadFile("tests/receipt/0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e.json")
if err != nil {
return err
}
err = json.Unmarshal(read, &txnRec)
if err != nil {
return err
}
txnReceipt, err := json.Marshal(txnRec.Result.TransactionReceipt)
if err != nil {
return err
}
return json.Unmarshal(txnReceipt, &r)
}

fromAddressFelt, err := utils.HexToFelt("0xdeadbeef")
if err != nil {
return err
}

transaction := InvokeTransactionReceipt(CommonTransactionReceipt{
TransactionHash: arg0Felt,
FinalityStatus: TxnFinalityStatusAcceptedOnL1,
Expand Down Expand Up @@ -1095,11 +1117,11 @@ func mock_starknet_traceTransaction(result interface{}, method string, args ...i
return errors.Wrap(errWrongArgs, fmt.Sprintf("args[0] should be felt, got %T\n", args[0]))
}
switch transactionHash.String() {
case "0xff66e14fc6a96f3289203690f5f876cb4b608868e8549b5f6a90a21d4d6329":
case "0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e":
var rawTrace struct {
Result InvokeTxnTrace `json:"result"`
}
read, err := os.ReadFile("tests/trace/0xff66e14fc6a96f3289203690f5f876cb4b608868e8549b5f6a90a21d4d6329.json")
read, err := os.ReadFile("tests/trace/0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e.json")
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type RpcProvider interface {
TraceBlockTransactions(ctx context.Context, blockID BlockID) ([]Trace, *RPCError)
TransactionByBlockIdAndIndex(ctx context.Context, blockID BlockID, index uint64) (Transaction, *RPCError)
TransactionByHash(ctx context.Context, hash *felt.Felt) (Transaction, *RPCError)
TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (TransactionReceipt, *RPCError)
TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (*TransactionReceiptWithBlockInfo, *RPCError)
TraceTransaction(ctx context.Context, transactionHash *felt.Felt) (TxnTrace, *RPCError)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"jsonrpc": "2.0",
"result": {
"type": "INVOKE",
"transaction_hash": "0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e",
"actual_fee": {
"amount": "0x30df144f446a59",
"unit": "FRI"
},
"execution_status": "SUCCEEDED",
"finality_status": "ACCEPTED_ON_L2",
"block_hash": "0x76c781a6a9d7f4a75205cd282fadf63f0c41d5c585a6cc384a7e726ac483316",
"block_number": 332275,
"messages_sent": [],
"events": [
{
"from_address": "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"keys": [
"0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9",
"0x14c5c28581c68f64c9a3d86b919094a5209fe0ccb454f776b3be2c3968cd91d",
"0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"
],
"data": [
"0x30df144f446a59",
"0x0"
]
},
{
"from_address": "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"keys": [
"0xa9fa878c35cd3d0191318f89033ca3e5501a3d90e21e3cc9256bdd5cd17fdd"
],
"data": [
"0xca46d96b37266650e0a8b79938d9300037337cad82ea4f45a921ad68b6a5f9",
"0x477bd3017f2b1cec6",
"0x0",
"0x477ee0f2c41f6391f",
"0x0"
]
}
],
"execution_resources": {
"steps": 7754,
"pedersen_builtin_applications": 20,
"range_check_builtin_applications": 185,
"ec_op_builtin_applications": 3,
"data_availability": {
"l1_gas": 0,
"l1_data_gas": 384
}
}
},
"id": 1
}
Loading

0 comments on commit e658126

Please sign in to comment.