Skip to content

Commit

Permalink
rpcv05 Implement GetTransactionStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Oct 11, 2023
1 parent a3676e6 commit 9acbc39
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
13 changes: 13 additions & 0 deletions rpc/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
27 changes: 27 additions & 0 deletions rpc/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
15 changes: 15 additions & 0 deletions rpc/types_transaction_receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit 9acbc39

Please sign in to comment.