Skip to content

Commit 5e4c3a0

Browse files
Merge branch 'xrpl/fix/rpc-version' into v0.1.x
2 parents afa011a + ac1d98c commit 5e4c3a0

File tree

14 files changed

+145
-31
lines changed

14 files changed

+145
-31
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
- `WalletLocator`
2626
- `WalletSize`
2727
- `TransferRate`
28-
2928
- Adds more tests for setting some `asf` flags in `AccountSet`.
3029
- Fixed `Transaction` field in `account_tx` response.
30+
- Fixed `Ledger` field in `ledger` response. LedgerIndex is now an uint32 instead of a string.
3131

3232
## [v0.1.5]
3333

examples/ledger/rpc/main.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/Peersyst/xrpl-go/xrpl/faucet"
7+
"github.com/Peersyst/xrpl-go/xrpl/queries/common"
8+
ledgerqueries "github.com/Peersyst/xrpl-go/xrpl/queries/ledger"
9+
"github.com/Peersyst/xrpl-go/xrpl/rpc"
10+
)
11+
12+
func main() {
13+
cfg, err := rpc.NewClientConfig(
14+
"https://s.altnet.rippletest.net:51234/",
15+
rpc.WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
16+
)
17+
if err != nil {
18+
panic(err)
19+
}
20+
21+
client := rpc.NewClient(cfg)
22+
23+
ledger, err := client.GetLedger(&ledgerqueries.Request{
24+
LedgerIndex: common.LedgerIndex(5115183),
25+
})
26+
if err != nil {
27+
panic(err)
28+
}
29+
fmt.Println(ledger.Ledger.LedgerHash)
30+
fmt.Println(ledger.Ledger.LedgerIndex)
31+
}

examples/ledger/ws/main.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/Peersyst/xrpl-go/xrpl/faucet"
7+
"github.com/Peersyst/xrpl-go/xrpl/queries/common"
8+
ledgerqueries "github.com/Peersyst/xrpl-go/xrpl/queries/ledger"
9+
"github.com/Peersyst/xrpl-go/xrpl/websocket"
10+
)
11+
12+
func main() {
13+
client := websocket.NewClient(
14+
websocket.NewClientConfig().
15+
WithHost("wss://s.altnet.rippletest.net:51233").
16+
WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
17+
)
18+
defer client.Disconnect()
19+
20+
fmt.Println("⏳ Connecting to server...")
21+
if err := client.Connect(); err != nil {
22+
fmt.Println(err)
23+
return
24+
}
25+
26+
fmt.Println("✅ Connected to server")
27+
fmt.Println()
28+
29+
ledger, err := client.GetLedger(&ledgerqueries.Request{
30+
LedgerIndex: common.LedgerIndex(5115183),
31+
})
32+
if err != nil {
33+
fmt.Println(err)
34+
return
35+
}
36+
fmt.Println(ledger.Ledger.LedgerHash)
37+
fmt.Println(ledger.Ledger.LedgerIndex)
38+
}

examples/queries/account-tx/rpc/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func main() {
2323
client := rpc.NewClient(cfg)
2424

2525
txs, err := client.GetAccountTransactions(&account.TransactionsRequest{
26-
Account: "rMCcNuTcajgw7YTgBy1sys3b89QqjUrMpH",
27-
LedgerIndex: common.LedgerIndex(4976692) ,
26+
Account: "rMCcNuTcajgw7YTgBy1sys3b89QqjUrMpH",
27+
LedgerIndex: common.LedgerIndex(4976692),
2828
})
2929
if err != nil {
3030
fmt.Println(err)

examples/queries/account-tx/ws/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ func main() {
3232
fmt.Println()
3333

3434
txs, err := client.GetAccountTransactions(&account.TransactionsRequest{
35-
Account: "rMCcNuTcajgw7YTgBy1sys3b89QqjUrMpH",
36-
LedgerIndex: common.LedgerIndex(4976692) ,
35+
Account: "rMCcNuTcajgw7YTgBy1sys3b89QqjUrMpH",
36+
LedgerIndex: common.LedgerIndex(4976692),
3737
})
3838
if err != nil {
3939
fmt.Println(err)
@@ -42,4 +42,4 @@ func main() {
4242

4343
fmt.Println("Number of transactions:", len(txs.Transactions))
4444
fmt.Println(txs.Transactions[0].Tx)
45-
}
45+
}

xrpl/queries/account/transactions_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ func TestAccountTransactionsRequest(t *testing.T) {
3333

3434
func TestAccountTransactionsResponse(t *testing.T) {
3535
s := TransactionsResponse{
36-
Account: "abc",
36+
Account: "abc",
3737
LedgerIndexMin: 100,
3838
LedgerIndexMax: 120,
39-
Limit: 10,
40-
Marker: "123",
39+
Limit: 10,
40+
Marker: "123",
4141
Transactions: []Transaction{
4242
{
43-
Hash: "def",
44-
LedgerHash: "ghi",
45-
LedgerIndex: 10,
43+
Hash: "def",
44+
LedgerHash: "ghi",
45+
LedgerIndex: 10,
4646
CloseTimeISO: "2021-01-01T00:00:00Z",
4747
Tx: map[string]any{
4848
"TransactionType": "Payment",
49-
"Account": "abc",
50-
"Destination": "def",
51-
"Amount": "100",
49+
"Account": "abc",
50+
"Destination": "def",
51+
"Amount": "100",
5252
},
5353
},
5454
},
@@ -84,4 +84,3 @@ func TestAccountTransactionsResponse(t *testing.T) {
8484
t.Error(err)
8585
}
8686
}
87-

xrpl/queries/ledger/ledger_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestLedgerResponse(t *testing.T) {
3232
CloseTimeResolution: 10,
3333
Closed: true,
3434
LedgerHash: "1723099E269C77C4BDE86C83FA6415D71CF20AA5CB4A94E5C388ED97123FB55B",
35-
LedgerIndex: "54300932",
35+
LedgerIndex: 54300932,
3636
ParentCloseTime: 638329240,
3737
ParentHash: "DF68B3BCABD31097634BABF0BDC87932D43D26E458BFEEFD36ADF2B3D94998C0",
3838
TotalCoins: types.XRPCurrencyAmount(99991024049648900),
@@ -51,7 +51,7 @@ func TestLedgerResponse(t *testing.T) {
5151
"close_time_resolution": 10,
5252
"closed": true,
5353
"ledger_hash": "1723099E269C77C4BDE86C83FA6415D71CF20AA5CB4A94E5C388ED97123FB55B",
54-
"ledger_index": "54300932",
54+
"ledger_index": 54300932,
5555
"parent_close_time": 638329240,
5656
"parent_hash": "DF68B3BCABD31097634BABF0BDC87932D43D26E458BFEEFD36ADF2B3D94998C0",
5757
"total_coins": "99991024049648900",

xrpl/queries/ledger/types/ledger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type BaseLedger struct {
1515
CloseTimeResolution int `json:"close_time_resolution"`
1616
Closed bool `json:"closed"`
1717
LedgerHash string `json:"ledger_hash"`
18-
LedgerIndex string `json:"ledger_index"`
18+
LedgerIndex uint32 `json:"ledger_index"`
1919
ParentCloseTime int `json:"parent_close_time"`
2020
ParentHash string `json:"parent_hash"`
2121
TotalCoins types.XRPCurrencyAmount `json:"total_coins"`

xrpl/queries/ledger/v1/ledger.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package v1
33
import (
44
"github.com/Peersyst/xrpl-go/xrpl/ledger-entry-types"
55
"github.com/Peersyst/xrpl-go/xrpl/queries/common"
6-
ledgertypes "github.com/Peersyst/xrpl-go/xrpl/queries/ledger/types"
6+
ledgertypesv1 "github.com/Peersyst/xrpl-go/xrpl/queries/ledger/v1/types"
77
"github.com/Peersyst/xrpl-go/xrpl/queries/version"
88
)
99

@@ -45,9 +45,9 @@ func (*Request) Validate() error {
4545

4646
// The expected response from the ledger method.
4747
type Response struct {
48-
Ledger ledgertypes.BaseLedger `json:"ledger"`
49-
LedgerHash string `json:"ledger_hash"`
50-
LedgerIndex common.LedgerIndex `json:"ledger_index"`
51-
Validated bool `json:"validated,omitempty"`
52-
QueueData []ledgertypes.QueueData `json:"queue_data,omitempty"`
48+
Ledger ledgertypesv1.BaseLedger `json:"ledger"`
49+
LedgerHash string `json:"ledger_hash"`
50+
LedgerIndex common.LedgerIndex `json:"ledger_index"`
51+
Validated bool `json:"validated,omitempty"`
52+
QueueData []ledgertypesv1.QueueData `json:"queue_data,omitempty"`
5353
}

xrpl/queries/ledger/v1/ledger_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"testing"
55

66
"github.com/Peersyst/xrpl-go/xrpl/queries/common"
7-
ledgertypes "github.com/Peersyst/xrpl-go/xrpl/queries/ledger/types"
7+
ledgertypesv1 "github.com/Peersyst/xrpl-go/xrpl/queries/ledger/v1/types"
88
"github.com/Peersyst/xrpl-go/xrpl/testutil"
99
"github.com/Peersyst/xrpl-go/xrpl/transaction/types"
1010
)
@@ -25,7 +25,7 @@ func TestLedgerRequest(t *testing.T) {
2525

2626
func TestLedgerResponse(t *testing.T) {
2727
s := Response{
28-
Ledger: ledgertypes.BaseLedger{
28+
Ledger: ledgertypesv1.BaseLedger{
2929
AccountHash: "53BD4650A024E27DEB52DBB6A52EDB26528B987EC61C895C48D1EB44CEDD9AD3",
3030
CloseTime: 638329241,
3131
CloseTimeHuman: "2020-Mar-24 01:40:41.000000000 UTC",

0 commit comments

Comments
 (0)