diff --git a/mocks/mock_rpc_provider.go b/mocks/mock_rpc_provider.go index a8edd76f..9a62fc94 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 rpc.NumAsHex) ([]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) +} + // GetStorageProof mocks base method. func (m *MockRpcProvider) GetStorageProof(ctx context.Context, storageProofInput rpc.StorageProofInput) (*rpc.StorageProofResult, error) { m.ctrl.T.Helper() diff --git a/rpc/provider.go b/rpc/provider.go index 9159e7cc..36852c5a 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,9 +59,9 @@ 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) GetStorageProof(ctx context.Context, storageProofInput StorageProofInput) (*StorageProofResult, error) GetTransactionStatus(ctx context.Context, transactionHash *felt.Felt) (*TxnStatusResp, 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 7d2743e4..32485d10 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 +// 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 NumAsHex) ([]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/transaction_test.go b/rpc/transaction_test.go index 6fb914a2..8525cc8d 100644 --- a/rpc/transaction_test.go +++ b/rpc/transaction_test.go @@ -205,3 +205,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 755734a9..969c4fbd 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 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"` + // 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"`