diff --git a/rpc/transaction.go b/rpc/transaction.go index 04140b8d..9e9aeacd 100644 --- a/rpc/transaction.go +++ b/rpc/transaction.go @@ -106,3 +106,16 @@ func (provider *Provider) TransactionReceipt(ctx context.Context, transactionHas } return receipt.TransactionReceipt, nil } + +// GetTransactionStatus gets the transaction status (possibly reflecting that the tx is still in the mempool, or dropped from it) +func (provider *Provider) GetTransactionStatus(ctx context.Context, transactionHash *felt.Felt) (*GetTxnStatusResp, error) { + var receipt GetTxnStatusResp + err := do(ctx, provider.c, "starknet_getTransactionStatus", &receipt, transactionHash) + if err != nil { + if errors.Is(err, ErrHashNotFound) { + return nil, ErrHashNotFound + } + return nil, err + } + return &receipt, nil +} diff --git a/rpc/transaction_test.go b/rpc/transaction_test.go index 5920dd2f..50cb32b4 100644 --- a/rpc/transaction_test.go +++ b/rpc/transaction_test.go @@ -309,3 +309,30 @@ func TestDeployOrDeclareReceipt(t *testing.T) { } } + +// TestGetTransactionStatus tests starknet_getTransactionStatus +func TestGetTransactionStatus(t *testing.T) { + testConfig := beforeEach(t) + + type testSetType struct { + TxnHash *felt.Felt + ExpextedResp GetTxnStatusResp + } + + testSet := map[string][]testSetType{ + "mock": {}, + "testnet": { + { + TxnHash: utils.TestHexToFelt(t, "0x46a9f52a96b2d226407929e04cb02507e531f7c78b9196fc8c910351d8c33f3"), + ExpextedResp: GetTxnStatusResp{FinalityStatus: TxnStatus_Accepted_On_L1, ExecutionStatus: TxnExecutionStatusSUCCEEDED}, + }, + }, + "mainnet": {}, + }[testEnv] + + for _, test := range testSet { + resp, err := testConfig.provider.GetTransactionStatus(context.Background(), test.TxnHash) + require.NoError(t, err) + require.Equal(t, *resp, test.ExpextedResp) + } +} diff --git a/rpc/types_transaction_receipt.go b/rpc/types_transaction_receipt.go index 195614b5..a8e80fa7 100644 --- a/rpc/types_transaction_receipt.go +++ b/rpc/types_transaction_receipt.go @@ -264,3 +264,18 @@ func unmarshalTransactionReceipt(t interface{}) (TransactionReceipt, error) { return nil, fmt.Errorf("unknown transaction type: %v", t) } + +// The finality status of the transaction, including the case the txn is still in the mempool or failed validation during the block construction phase +type TxnStatus string + +const ( + TxnStatus_Recieved TxnStatus = "RECEIVED" + TxnStatus_Rejected TxnStatus = "REJECTED" + TxnStatus_Accepted_On_L2 TxnStatus = "ACCEPTED_ON_L2" + TxnStatus_Accepted_On_L1 TxnStatus = "ACCEPTED_ON_L1" +) + +type GetTxnStatusResp struct { + ExecutionStatus TxnExecutionStatus `json:"execution_status,omitempty"` + FinalityStatus TxnStatus `json:"finality_status"` +}