Skip to content

Commit

Permalink
Remove status
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Aug 21, 2023
1 parent 1abb0e4 commit dd987aa
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 66 deletions.
2 changes: 1 addition & 1 deletion contracts/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (p *GatewayProvider) declareAndWaitWithWallet(ctx context.Context, compiled
return nil, err
}
if !receipt.Status.IsTransactionFinal() ||
rpc.TransactionState(receipt.Status.String()) == rpc.TransactionRejected {
receipt.Status == types.TransactionState(rpc.TxnExecutionStatusSUCCEEDED) {
return nil, fmt.Errorf("wrong status: %s", receipt.Status)
}
return &DeclareOutput{
Expand Down
2 changes: 1 addition & 1 deletion rpc/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func mock_starknet_getTransactionReceipt(result interface{}, method string, args
}
transaction := InvokeTransactionReceipt(CommonTransactionReceipt{
TransactionHash: arg0Felt,
Status: TransactionAcceptedOnL1,
FinalityStatus: TxnFinalityStatusAcceptedOnL1,
Events: []Event{{
FromAddress: fromAddressFelt,
}},
Expand Down
18 changes: 9 additions & 9 deletions rpc/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (provider *Provider) TransactionReceipt(ctx context.Context, transactionHas
}

// WaitForTransaction waits for the transaction to succeed or fail
func (provider *Provider) WaitForTransaction(ctx context.Context, transactionHash *felt.Felt, pollInterval time.Duration) (TransactionState, error) {
func (provider *Provider) WaitForTransaction(ctx context.Context, transactionHash *felt.Felt, pollInterval time.Duration) (TxnExecutionStatus, error) {
t := time.NewTicker(pollInterval)
for {
select {
Expand All @@ -109,20 +109,20 @@ func (provider *Provider) WaitForTransaction(ctx context.Context, transactionHas
}
switch r := receipt.(type) {
case DeclareTransactionReceipt:
if r.Status.IsTransactionFinal() {
return r.Status, nil
if r.ExecutionStatus == TxnExecutionStatusSUCCEEDED {
return r.ExecutionStatus, nil
}
case DeployTransactionReceipt:
if r.Status.IsTransactionFinal() {
return r.Status, nil
if r.ExecutionStatus == TxnExecutionStatusSUCCEEDED {
return r.ExecutionStatus, nil
}
case InvokeTransactionReceipt:
if r.Status.IsTransactionFinal() {
return r.Status, nil
if r.ExecutionStatus == TxnExecutionStatusSUCCEEDED {
return r.ExecutionStatus, nil
}
case L1HandlerTransactionReceipt:
if r.Status.IsTransactionFinal() {
return r.Status, nil
if r.ExecutionStatus == TxnExecutionStatusSUCCEEDED {
return r.ExecutionStatus, nil
}
default:
return "", fmt.Errorf("unknown receipt %T", receipt)
Expand Down
2 changes: 0 additions & 2 deletions rpc/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rpc

import (
"context"
"fmt"
"regexp"
"testing"

Expand Down Expand Up @@ -266,7 +265,6 @@ func TestTransactionReceipt_MatchesStatus(t *testing.T) {
if ok, err := regexp.MatchString(test.ExecutionStatus, string(txnReceipt.ExecutionStatus)); err != nil || !ok {
t.Fatal("error checking transaction status", ok, err, txnReceipt.ExecutionStatus)
}
fmt.Println("transaction status", txnReceipt.Status)
}
}

Expand Down
52 changes: 0 additions & 52 deletions rpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,58 +176,6 @@ type FeeEstimate struct {
OverallFee NumAsHex `json:"overall_fee"`
}

type TransactionState string

const (
TransactionAcceptedOnL1 TransactionState = "ACCEPTED_ON_L1"
TransactionAcceptedOnL2 TransactionState = "ACCEPTED_ON_L2"
TransactionNotReceived TransactionState = "NOT_RECEIVED"
TransactionPending TransactionState = "PENDING"
TransactionReceived TransactionState = "RECEIVED"
TransactionRejected TransactionState = "REJECTED"
)

func (ts *TransactionState) UnmarshalJSON(data []byte) error {
unquoted, err := strconv.Unquote(string(data))
if err != nil {
return err
}
switch unquoted {
case "ACCEPTED_ON_L2":
*ts = TransactionAcceptedOnL2
case "ACCEPTED_ON_L1":
*ts = TransactionAcceptedOnL1
case "NOT_RECEIVED":
*ts = TransactionNotReceived
case "PENDING":
*ts = TransactionPending
case "RECEIVED":
*ts = TransactionReceived
case "REJECTED":
*ts = TransactionRejected
default:
return fmt.Errorf("unsupported status: %s", data)
}
return nil
}

func (ts TransactionState) MarshalJSON() ([]byte, error) {
return []byte(strconv.Quote(string(ts))), nil
}

func (s TransactionState) String() string {
return string(s)
}

func (s TransactionState) IsTransactionFinal() bool {
if s == TransactionAcceptedOnL2 ||
s == TransactionAcceptedOnL1 ||
s == TransactionRejected {
return true
}
return false
}

type TxnExecutionStatus string

const (
Expand Down
1 change: 0 additions & 1 deletion rpc/types_transaction_receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type CommonTransactionReceipt struct {
TransactionHash *felt.Felt `json:"transaction_hash"`
// ActualFee The fee that was charged by the sequencer
ActualFee *felt.Felt `json:"actual_fee"`
Status TransactionState `json:"status"` // TODO: remove
ExecutionStatus TxnExecutionStatus `json:"execution_status"`
FinalityStatus TxnFinalityStatus `json:"finality_status"`
BlockHash *felt.Felt `json:"block_hash"`
Expand Down

0 comments on commit dd987aa

Please sign in to comment.