From b093f933dd6f7039e62f2112a62cecffb3fa78d2 Mon Sep 17 00:00:00 2001 From: thiagodeev Date: Thu, 3 Oct 2024 16:34:17 -0300 Subject: [PATCH 1/2] Added GetMessagesStatus method --- mocks/mock_rpc_provider.go | 15 +++++++++++++++ rpc/provider.go | 3 ++- rpc/transaction.go | 17 +++++++++++++++++ rpc/types_transaction_receipt.go | 9 +++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/mocks/mock_rpc_provider.go b/mocks/mock_rpc_provider.go index 6e86bf39..2dfddd4a 100644 --- a/mocks/mock_rpc_provider.go +++ b/mocks/mock_rpc_provider.go @@ -296,6 +296,21 @@ func (mr *MockRpcProviderMockRecorder) Events(ctx, input any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Events", reflect.TypeOf((*MockRpcProvider)(nil).Events), ctx, input) } +// GetMessagesStatus mocks base method. +func (m *MockRpcProvider) GetMessagesStatus(ctx context.Context, transactionHash *felt.Felt) ([]rpc.MessageStatusResp, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetMessagesStatus", ctx, transactionHash) + ret0, _ := ret[0].([]rpc.MessageStatusResp) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetMessagesStatus indicates an expected call of GetMessagesStatus. +func (mr *MockRpcProviderMockRecorder) GetMessagesStatus(ctx, transactionHash any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMessagesStatus", reflect.TypeOf((*MockRpcProvider)(nil).GetMessagesStatus), ctx, transactionHash) +} + // GetTransactionStatus mocks base method. func (m *MockRpcProvider) GetTransactionStatus(ctx context.Context, transactionHash *felt.Felt) (*rpc.TxnStatusResp, error) { m.ctrl.T.Helper() diff --git a/rpc/provider.go b/rpc/provider.go index f7a5e53a..d1c04a81 100644 --- a/rpc/provider.go +++ b/rpc/provider.go @@ -48,6 +48,7 @@ type RpcProvider interface { BlockHashAndNumber(ctx context.Context) (*BlockHashAndNumberOutput, error) BlockNumber(ctx context.Context) (uint64, error) BlockTransactionCount(ctx context.Context, blockID BlockID) (uint64, error) + BlockWithReceipts(ctx context.Context, blockID BlockID) (interface{}, error) BlockWithTxHashes(ctx context.Context, blockID BlockID) (interface{}, error) BlockWithTxs(ctx context.Context, blockID BlockID) (interface{}, error) Call(ctx context.Context, call FunctionCall, block BlockID) ([]*felt.Felt, error) @@ -58,8 +59,8 @@ type RpcProvider interface { EstimateFee(ctx context.Context, requests []BroadcastTxn, simulationFlags []SimulationFlag, blockID BlockID) ([]FeeEstimation, error) 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) GetTransactionStatus(ctx context.Context, transactionHash *felt.Felt) (*TxnStatusResp, error) + GetMessagesStatus(ctx context.Context, transactionHash *felt.Felt) ([]MessageStatusResp, 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) StateUpdate(ctx context.Context, blockID BlockID) (*StateUpdateOutput, error) diff --git a/rpc/transaction.go b/rpc/transaction.go index 7d2743e4..06403b0b 100644 --- a/rpc/transaction.go +++ b/rpc/transaction.go @@ -71,3 +71,20 @@ func (provider *Provider) GetTransactionStatus(ctx context.Context, transactionH } return &receipt, nil } + +// Given an l1 tx hash, returns the associated l1_handler tx hashes and statuses for all L1 -> L2 messages sent by the l1 transaction, ordered by the l1 tx sending order +// +// Parameters: +// - ctx: the context.Context object for cancellation and timeouts. +// - transactionHash: The hash of the L1 transaction that sent L1->L2 messages as a felt +// Returns: +// - [] MessageStatusResp: An array containing the status of the messages sent by the l1 transaction +// - error, if one arose. +func (provider *Provider) GetMessagesStatus(ctx context.Context, transactionHash *felt.Felt) ([]MessageStatusResp, error) { + var response []MessageStatusResp + err := do(ctx, provider.c, "starknet_getMessagesStatus", &response, transactionHash) + if err != nil { + return nil, tryUnwrapToRPCErr(err, ErrHashNotFound) + } + return response, nil +} diff --git a/rpc/types_transaction_receipt.go b/rpc/types_transaction_receipt.go index d9d04d4a..41607257 100644 --- a/rpc/types_transaction_receipt.go +++ b/rpc/types_transaction_receipt.go @@ -28,6 +28,15 @@ type MsgFromL1 struct { Payload []*felt.Felt `json:"payload"` } +type MessageStatusResp struct { + // The hash of a Starknet transaction + TransactionHash *felt.Felt `json:"transaction_hash"` + // The finality status of the transaction, including the case the txn is still in the mempool or failed validation during the block construction phase + FinalityStatus TxnStatus `json:"finality_status"` + // The failure reason, only appears if finality_status is REJECTED + FailureReason string `json:"failure_reason,omitempty"` +} + type OrderedMsg struct { // The order of the message within the transaction Order int `json:"order"` From d59f54083e7b919d7d1192b29c78119c448487cd Mon Sep 17 00:00:00 2001 From: thiagodeev Date: Thu, 24 Oct 2024 13:24:56 -0300 Subject: [PATCH 2/2] PR comment fixes --- mocks/mock_rpc_provider.go | 2 +- rpc/provider.go | 2 +- rpc/transaction.go | 8 ++++---- rpc/transaction_test.go | 4 ++++ rpc/types_transaction_receipt.go | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/mocks/mock_rpc_provider.go b/mocks/mock_rpc_provider.go index 2dfddd4a..bbd47649 100644 --- a/mocks/mock_rpc_provider.go +++ b/mocks/mock_rpc_provider.go @@ -297,7 +297,7 @@ func (mr *MockRpcProviderMockRecorder) Events(ctx, input any) *gomock.Call { } // GetMessagesStatus mocks base method. -func (m *MockRpcProvider) GetMessagesStatus(ctx context.Context, transactionHash *felt.Felt) ([]rpc.MessageStatusResp, error) { +func (m *MockRpcProvider) GetMessagesStatus(ctx context.Context, transactionHash rpc.NumAsHex) ([]rpc.MessageStatusResp, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetMessagesStatus", ctx, transactionHash) ret0, _ := ret[0].([]rpc.MessageStatusResp) diff --git a/rpc/provider.go b/rpc/provider.go index d1c04a81..3a8c72e2 100644 --- a/rpc/provider.go +++ b/rpc/provider.go @@ -60,7 +60,7 @@ type RpcProvider interface { EstimateMessageFee(ctx context.Context, msg MsgFromL1, blockID BlockID) (*FeeEstimation, error) Events(ctx context.Context, input EventsInput) (*EventChunk, error) GetTransactionStatus(ctx context.Context, transactionHash *felt.Felt) (*TxnStatusResp, error) - GetMessagesStatus(ctx context.Context, transactionHash *felt.Felt) ([]MessageStatusResp, error) + GetMessagesStatus(ctx context.Context, transactionHash NumAsHex) ([]MessageStatusResp, 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) StateUpdate(ctx context.Context, blockID BlockID) (*StateUpdateOutput, error) diff --git a/rpc/transaction.go b/rpc/transaction.go index 06403b0b..32485d10 100644 --- a/rpc/transaction.go +++ b/rpc/transaction.go @@ -72,15 +72,15 @@ func (provider *Provider) GetTransactionStatus(ctx context.Context, transactionH return &receipt, nil } -// Given an l1 tx hash, returns the associated l1_handler tx hashes and statuses for all L1 -> L2 messages sent by the l1 transaction, ordered by the l1 tx sending order +// Given an L1 tx hash, returns the associated l1_handler tx hashes and statuses for all L1 -> L2 messages sent by the l1 transaction, ordered by the L1 tx sending order // // Parameters: // - ctx: the context.Context object for cancellation and timeouts. -// - transactionHash: The hash of the L1 transaction that sent L1->L2 messages as a felt +// - transactionHash: The hash of the L1 transaction that sent L1->L2 messages // Returns: -// - [] MessageStatusResp: An array containing the status of the messages sent by the l1 transaction +// - [] MessageStatusResp: An array containing the status of the messages sent by the L1 transaction // - error, if one arose. -func (provider *Provider) GetMessagesStatus(ctx context.Context, transactionHash *felt.Felt) ([]MessageStatusResp, error) { +func (provider *Provider) GetMessagesStatus(ctx context.Context, transactionHash NumAsHex) ([]MessageStatusResp, error) { var response []MessageStatusResp err := do(ctx, provider.c, "starknet_getMessagesStatus", &response, transactionHash) if err != nil { diff --git a/rpc/transaction_test.go b/rpc/transaction_test.go index a674738a..5405ac75 100644 --- a/rpc/transaction_test.go +++ b/rpc/transaction_test.go @@ -203,3 +203,7 @@ func TestGetTransactionStatus(t *testing.T) { require.Equal(t, *resp, test.ExpectedResp) } } + +func TestGetMessagesStatus(t *testing.T) { + t.Skip("TODO: create a test before merge") +} diff --git a/rpc/types_transaction_receipt.go b/rpc/types_transaction_receipt.go index 41607257..86217179 100644 --- a/rpc/types_transaction_receipt.go +++ b/rpc/types_transaction_receipt.go @@ -29,7 +29,7 @@ type MsgFromL1 struct { } type MessageStatusResp struct { - // The hash of a Starknet transaction + // The hash of a L1 handler transaction TransactionHash *felt.Felt `json:"transaction_hash"` // The finality status of the transaction, including the case the txn is still in the mempool or failed validation during the block construction phase FinalityStatus TxnStatus `json:"finality_status"`