Skip to content

Commit

Permalink
Adds GetMessagesStatus method (#634)
Browse files Browse the repository at this point in the history
* Added GetMessagesStatus method

* PR comment fixes
  • Loading branch information
thiagodeev authored Oct 28, 2024
1 parent 470f18c commit 2013420
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
15 changes: 15 additions & 0 deletions mocks/mock_rpc_provider.go

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

3 changes: 2 additions & 1 deletion rpc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions rpc/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions rpc/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
9 changes: 9 additions & 0 deletions rpc/types_transaction_receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 2013420

Please sign in to comment.