mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-27 23:25:51 +00:00
Merge pull request #1598 from XRPLF/oeggert/issue1554
Add code samples for markers and pagination.
This commit is contained in:
5
content/_code-samples/markers-and-pagination/README.md
Normal file
5
content/_code-samples/markers-and-pagination/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Markers and Pagination
|
||||
|
||||
Iterate over a `ledger_data` method request that requires multiple calls.
|
||||
|
||||
Examples from the [Markers and Pagination page](https://xrpl.org/markers-and-pagination.html#markers-and-pagination).
|
||||
@@ -0,0 +1,43 @@
|
||||
const xrpl = require("xrpl")
|
||||
|
||||
async function main() {
|
||||
|
||||
// Create a client and connect to the network.
|
||||
const client = new xrpl.Client("wss://xrplcluster.com/")
|
||||
await client.connect()
|
||||
|
||||
// Query the most recently validated ledger for info.
|
||||
let ledger = await client.request({
|
||||
"command": "ledger_data",
|
||||
"ledger_index": "validated",
|
||||
})
|
||||
const ledger_data_index = ledger["result"]["ledger_index"]
|
||||
|
||||
// Create a function to run on each API call.
|
||||
function printLedgerResult(){
|
||||
console.log(ledger["result"])
|
||||
}
|
||||
|
||||
// Execute function at least once before checking for markers.
|
||||
do {
|
||||
printLedgerResult()
|
||||
|
||||
if (ledger["result"]["marker"] === undefined) {
|
||||
break
|
||||
}
|
||||
|
||||
// Specify the same ledger and add the marker to continue querying.
|
||||
const ledger_marker = await client.request({
|
||||
"command": "ledger_data",
|
||||
"ledger_index": ledger_data_index,
|
||||
"marker": ledger["result"]["marker"]
|
||||
})
|
||||
ledger = ledger_marker
|
||||
|
||||
} while (true)
|
||||
|
||||
// Disconnect when done. If you omit this, Node.js won't end the process.
|
||||
client.disconnect()
|
||||
}
|
||||
|
||||
main()
|
||||
@@ -0,0 +1,24 @@
|
||||
from xrpl.clients import JsonRpcClient
|
||||
from xrpl.models.requests import LedgerData
|
||||
|
||||
# Create a client to connect to the network.
|
||||
client = JsonRpcClient("https://xrplcluster.com/")
|
||||
|
||||
# Query the most recently validated ledger for info.
|
||||
ledger = LedgerData(ledger_index="validated")
|
||||
ledger_data = client.request(ledger).result
|
||||
ledger_data_index = ledger_data["ledger_index"]
|
||||
|
||||
# Create a function to run on each API call.
|
||||
def printLedgerResult():
|
||||
print(ledger_data)
|
||||
|
||||
# Execute function at least once before checking for markers.
|
||||
while True:
|
||||
printLedgerResult()
|
||||
if "marker" not in ledger_data:
|
||||
break
|
||||
|
||||
# Specify the same ledger and add the marker to continue querying.
|
||||
ledger_marker = LedgerData(ledger_index=ledger_data_index, marker=ledger_data["marker"])
|
||||
ledger_data = client.request(ledger_marker).result
|
||||
Reference in New Issue
Block a user