Skip to content

Commit 6340da4

Browse files
Merge pull request #174 from XRPLF/xrpl/fix/wait-transaction-retries
[TA-6038]: fix waitForTransaction retries
2 parents 1639de0 + b76ddac commit 6340da4

File tree

4 files changed

+18
-83
lines changed

4 files changed

+18
-83
lines changed

xrpl/websocket/client.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -365,18 +365,20 @@ func (c *Client) waitForTransaction(txHash string, lastLedgerSequence uint32) (*
365365
res, err := c.Request(&requests.TxRequest{
366366
Transaction: txHash,
367367
})
368-
if err != nil {
368+
if err != nil && !strings.Contains(err.Error(), txnNotFound) {
369369
return nil, err
370370
}
371371

372-
err = res.GetResult(&txResponse)
373-
if err != nil {
374-
return nil, err
375-
}
372+
if res != nil {
373+
err = res.GetResult(&txResponse)
374+
if err != nil {
375+
return nil, err
376+
}
376377

377-
// Check if the transaction has been included in the current ledger
378-
if txResponse.LedgerIndex.Int() >= int(lastLedgerSequence) {
379-
break
378+
// Check if the transaction has been included in the current ledger
379+
if txResponse.LedgerIndex.Int() >= int(lastLedgerSequence) {
380+
break
381+
}
380382
}
381383

382384
// Wait for the retry delay before retrying
@@ -731,10 +733,10 @@ func (c *Client) handleStream(t streamtypes.Type, message []byte) {
731733
c.ledgerClosedChan <- &ledger
732734
}
733735
case streamtypes.TransactionStreamType:
734-
var transaction streamtypes.TransactionStream
735-
c.unmarshalMessage(message, &transaction)
736+
var transactionStream streamtypes.TransactionStream
737+
c.unmarshalMessage(message, &transactionStream)
736738
if c.transactionChan != nil {
737-
c.transactionChan <- &transaction
739+
c.transactionChan <- &transactionStream
738740
}
739741
case streamtypes.ValidationStreamType:
740742
var validation streamtypes.ValidationStream

xrpl/websocket/client_test.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,6 @@ import (
1616
"github.com/stretchr/testify/require"
1717
)
1818

19-
func TestClient_Connect(t *testing.T) {
20-
ws := NewClient(NewClientConfig().WithHost("wss://s.altnet.rippletest.net"))
21-
err := ws.Connect()
22-
require.NoError(t, err)
23-
require.True(t, ws.IsConnected())
24-
ws.Disconnect()
25-
require.False(t, ws.IsConnected())
26-
}
27-
28-
func TestClient_Disconnect(t *testing.T) {
29-
ws := NewClient(NewClientConfig().WithHost("wss://s.altnet.rippletest.net"))
30-
ws.Connect()
31-
require.True(t, ws.IsConnected())
32-
ws.Disconnect()
33-
require.False(t, ws.IsConnected())
34-
}
35-
36-
func TestClient_IsConnected(t *testing.T) {
37-
ws := NewClient(NewClientConfig().WithHost("wss://s.altnet.rippletest.net"))
38-
require.False(t, ws.IsConnected())
39-
err := ws.Connect()
40-
require.NoError(t, err)
41-
require.True(t, ws.IsConnected())
42-
err = ws.Disconnect()
43-
require.NoError(t, err)
44-
require.False(t, ws.IsConnected())
45-
}
46-
4719
func TestClient_SendRequest(t *testing.T) {
4820
tt := []struct {
4921
description string
@@ -936,8 +908,6 @@ func TestClient_setLastLedgerSequence(t *testing.T) {
936908
t.Errorf("Expected tx %v, but got %v", tt.expectedTx, tt.tx)
937909
}
938910
}
939-
940-
cl.Disconnect()
941911
})
942912
}
943913
}
@@ -999,8 +969,6 @@ func TestClient_checkAccountDeleteBlockers(t *testing.T) {
999969
t.Errorf("Unexpected error: %v", err)
1000970
}
1001971
}
1002-
1003-
cl.Disconnect()
1004972
})
1005973
}
1006974
}

xrpl/websocket/connection_test.go

Lines changed: 0 additions & 35 deletions
This file was deleted.

xrpl/websocket/errors.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import (
55
"fmt"
66
)
77

8+
const (
9+
// txnNotFound is the error message returned by the xrpl node when requesting for a not found transaction.
10+
txnNotFound = "txnNotFound"
11+
)
12+
813
var (
914
// transaction
1015

@@ -77,11 +82,6 @@ var (
7782
// ErrAmountAndDeliverMaxMustBeIdentical is returned when Amount and DeliverMax fields are not identical.
7883
ErrAmountAndDeliverMaxMustBeIdentical = errors.New("payment transaction: Amount and DeliverMax fields must be identical when both are provided")
7984

80-
// tags
81-
82-
// ErrTagMustEqualAddressTag is returned when a tag must equal the address tag.
83-
ErrTagMustEqualAddressTag = errors.New("tag, if present, must be equal to the tag of the address")
84-
8585
// connection
8686

8787
// ErrNotConnected is returned when attempting to perform operations on a connection that is not established.

0 commit comments

Comments
 (0)