mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-04 20:05:50 +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
|
||||
@@ -2,8 +2,6 @@
|
||||
html: nftoken-batch-minting.html
|
||||
parent: non-fungible-tokens.html
|
||||
blurb: Minting NFToken objects in batches.
|
||||
filters:
|
||||
- include_code
|
||||
labels:
|
||||
- Non-fungible Tokens, NFTs
|
||||
---
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
html: non-fungible-token-transfers.html
|
||||
parent: non-fungible-tokens.html
|
||||
blurb: NFTokenをダイレクトモードまたはブローカーモードで取引する。
|
||||
filters:
|
||||
- include_code
|
||||
labels:
|
||||
- Non-fungible Tokens, NFTs
|
||||
status: not_enabled
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
html: non-fungible-token-transfers.html
|
||||
parent: non-fungible-tokens.html
|
||||
blurb: Trading NFTokens in direct or brokered mode.
|
||||
filters:
|
||||
- include_code
|
||||
labels:
|
||||
- Non-fungible Tokens, NFTs
|
||||
---
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
html: non-fungible-tokens.html
|
||||
parent: tokens.html
|
||||
blurb: XRPL NFTの紹介。
|
||||
filters:
|
||||
- include_code
|
||||
labels:
|
||||
- Non-fungible Tokens, NFTs
|
||||
---
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
html: non-fungible-tokens.html
|
||||
parent: tokens.html
|
||||
blurb: Introduction to XRPL NFTs.
|
||||
filters:
|
||||
- include_code
|
||||
labels:
|
||||
- Non-fungible Tokens, NFTs
|
||||
---
|
||||
|
||||
@@ -8,3 +8,15 @@ blurb: Convention for paginating large queries into multiple responses.
|
||||
Some methods return more data than can efficiently fit into one response. When there are more results than contained, the response includes a `marker` field. You can use this to retrieve more pages of data across multiple calls. In each request, pass the `marker` value from the previous response to resume from the point where you left off. If the `marker` is omitted from a response, then you have reached the end of the data set.
|
||||
|
||||
The format of the `marker` field is intentionally undefined. Each server can define a `marker` field as desired, so it may take the form of a string, a nested object, or another type. Different servers, and different methods provided by the same server, can have different `marker` definitions. Each `marker` is ephemeral, and may not work as expected after 10 minutes.
|
||||
|
||||
<!-- MULTICODE_BLOCK_START -->
|
||||
|
||||
_Python_
|
||||
|
||||
{{ include_code("_code-samples/markers-and-pagination/py/pagination-with-markers.py", language="py") }}
|
||||
|
||||
_JavaScript_
|
||||
|
||||
{{ include_code("_code-samples/markers-and-pagination/js/pagination-with-markers.js", language="js") }}
|
||||
|
||||
<!-- MULTICODE_BLOCK_END -->
|
||||
@@ -2,8 +2,6 @@
|
||||
html: nftokenoffer.html
|
||||
parent: ledger-object-types.html
|
||||
blurb: NFTを売買するオファーを作成する。
|
||||
filters:
|
||||
- include_code
|
||||
labels:
|
||||
- Non-fungible Tokens, NFTs
|
||||
---
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
html: nftokenoffer.html
|
||||
parent: ledger-object-types.html
|
||||
blurb: Create offers to buy or sell NFTs.
|
||||
filters:
|
||||
- include_code
|
||||
labels:
|
||||
- Non-fungible Tokens, NFTs
|
||||
---
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
html: nftokenpage.html
|
||||
parent: ledger-object-types.html
|
||||
blurb: NFTokenを記録するためのレジャー構造。
|
||||
filters:
|
||||
- include_code
|
||||
labels:
|
||||
- Non-fungible Tokens, NFTs
|
||||
---
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
html: nftokenpage.html
|
||||
parent: ledger-object-types.html
|
||||
blurb: Ledger structure for recording NFTokens.
|
||||
filters:
|
||||
- include_code
|
||||
labels:
|
||||
- Non-fungible Tokens, NFTs
|
||||
---
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
---
|
||||
parent: build-apps.html
|
||||
filters:
|
||||
- include_code
|
||||
targets:
|
||||
- en
|
||||
- ja # TODO: translate this page
|
||||
|
||||
@@ -8,8 +8,6 @@ blurb: Build a simple Java app that interacts with the XRP Ledger.
|
||||
cta_text: Build an XRP Ledger-connected app
|
||||
top_nav_name: Java
|
||||
top_nav_grouping: Get Started
|
||||
filters:
|
||||
- include_code
|
||||
labels:
|
||||
- Development
|
||||
showcase_icon: assets/img/logos/java.svg
|
||||
|
||||
@@ -4,8 +4,6 @@ parent: get-started.html
|
||||
blurb: XRP Ledgerを参照するためのエントリーレベルのJavaScriptアプリケーションを構築します。
|
||||
top_nav_name: JavaScript
|
||||
top_nav_grouping: Get Started
|
||||
filters:
|
||||
- include_code
|
||||
labels:
|
||||
- 開発
|
||||
showcase_icon: assets/img/logos/javascript.svg
|
||||
|
||||
@@ -4,8 +4,6 @@ parent: get-started.html
|
||||
blurb: Build an entry-level JavaScript application for querying the XRP Ledger.
|
||||
top_nav_name: JavaScript
|
||||
top_nav_grouping: Get Started
|
||||
filters:
|
||||
- include_code
|
||||
labels:
|
||||
- Development
|
||||
showcase_icon: assets/img/logos/javascript.svg
|
||||
|
||||
@@ -5,8 +5,6 @@ blurb: Build a simple Python app that interacts with the XRP Ledger.
|
||||
cta_text: Build an XRP Ledger-connected app
|
||||
top_nav_name: Python
|
||||
top_nav_grouping: Get Started
|
||||
filters:
|
||||
- include_code
|
||||
labels:
|
||||
- Development
|
||||
showcase_icon: assets/img/logos/python.svg
|
||||
|
||||
@@ -6,7 +6,6 @@ cta_text: XRPを送金しよう
|
||||
embed_xrpl_js: true
|
||||
filters:
|
||||
- interactive_steps
|
||||
- include_code
|
||||
labels:
|
||||
- 支払い
|
||||
- XRP
|
||||
|
||||
@@ -6,7 +6,6 @@ cta_text: Send XRP
|
||||
embed_xrpl_js: true
|
||||
filters:
|
||||
- interactive_steps
|
||||
- include_code
|
||||
labels:
|
||||
- XRP
|
||||
- Payments
|
||||
|
||||
@@ -5,7 +5,6 @@ blurb: Require users to specify a destination tag when sending to your address.
|
||||
embed_xrpl_js: true
|
||||
filters:
|
||||
- interactive_steps
|
||||
- include_code
|
||||
labels:
|
||||
- Accounts
|
||||
---
|
||||
|
||||
@@ -5,7 +5,6 @@ blurb: チケットは、通常のシーケンス順序以外でトランザク
|
||||
embed_xrpl_js: true
|
||||
filters:
|
||||
- interactive_steps
|
||||
- include_code
|
||||
labels:
|
||||
- アカウント
|
||||
---
|
||||
|
||||
@@ -5,7 +5,6 @@ blurb: Use Tickets to send a transaction outside of normal Sequence order.
|
||||
embed_xrpl_js: true
|
||||
filters:
|
||||
- interactive_steps
|
||||
- include_code
|
||||
labels:
|
||||
- Accounts
|
||||
---
|
||||
|
||||
@@ -5,7 +5,6 @@ blurb: Permanently give up your account's ability to freeze tokens it issues.
|
||||
embed_xrpl_js: true
|
||||
filters:
|
||||
- interactive_steps
|
||||
- include_code
|
||||
labels:
|
||||
- Tokens
|
||||
---
|
||||
|
||||
@@ -5,7 +5,6 @@ blurb: Freeze all tokens issued by your address.
|
||||
embed_xrpl_js: true
|
||||
filters:
|
||||
- interactive_steps
|
||||
- include_code
|
||||
labels:
|
||||
- Tokens
|
||||
- Security
|
||||
|
||||
@@ -5,7 +5,6 @@ blurb: Freeze an individual holder of a token.
|
||||
embed_xrpl_js: true
|
||||
filters:
|
||||
- interactive_steps
|
||||
- include_code
|
||||
labels:
|
||||
- Tokens
|
||||
- Security
|
||||
|
||||
@@ -5,7 +5,6 @@ blurb: Create your own token and issue it on the XRP Ledger Testnet.
|
||||
embed_xrpl_js: true
|
||||
filters:
|
||||
- interactive_steps
|
||||
- include_code
|
||||
labels:
|
||||
- Tokens
|
||||
---
|
||||
|
||||
@@ -4,7 +4,6 @@ blurb: Buy or sell fungible tokens for each other or for XRP in the decentralize
|
||||
embed_xrpl_js: true
|
||||
filters:
|
||||
- interactive_steps
|
||||
- include_code
|
||||
labels:
|
||||
- Decentralized Exchange
|
||||
- Tokens
|
||||
|
||||
@@ -25,6 +25,7 @@ default_filters:
|
||||
- link_replacement
|
||||
- external_links
|
||||
- status_badges
|
||||
- include_code
|
||||
- include_svg
|
||||
- css_tables
|
||||
- slug
|
||||
|
||||
@@ -51,7 +51,7 @@ For privacy reasons, the memo does not and MUST NOT include personally identifyi
|
||||
|
||||
An interactive tutorial is a page, so you add it to the `dactyl-config.yml` page like any other page. However, you need to add the following pieces to make the interactive stuff work:
|
||||
|
||||
1. Set page properties, either in the config file or the page's frontmatter. The `interactive_steps` Dactyl filter gives you access to the functions you use to demarcate the interactive bits in your markdown file. The `include_code` filter is optional, but can be useful for pulling code samples out of another file. Most of the time, you'll also want to include xrpl.js and its dependencies as well; you can have the templates handle that for you by setting the field `embed_xrpl_js: true`. For example:
|
||||
1. Set page properties, either in the config file or the page's frontmatter. The `interactive_steps` Dactyl filter gives you access to the functions you use to demarcate the interactive bits in your markdown file. Most of the time, you'll also want to include xrpl.js and its dependencies as well; you can have the templates handle that for you by setting the field `embed_xrpl_js: true`. For example:
|
||||
|
||||
html: use-tickets.html
|
||||
parent: manage-account-settings.html
|
||||
@@ -59,7 +59,6 @@ An interactive tutorial is a page, so you add it to the `dactyl-config.yml` page
|
||||
embed_xrpl_js: true
|
||||
filters:
|
||||
- interactive_steps
|
||||
- include_code
|
||||
|
||||
Including the `interactive_steps` filter automatically causes the templates to load the [interactive-tutorial.js](../assets/js/interactive-tutorial.js) file on that page. This JavaScript file implements much of the functionality for interactive tutorials, and provides helper functions for a lot of other common things you might want to do.
|
||||
|
||||
@@ -76,7 +75,7 @@ An interactive tutorial is a page, so you add it to the `dactyl-config.yml` page
|
||||
|
||||
Use excerpts of the example code to demonstrate each step. You can gloss over certain parts of the sample code if they're tangential to the goal of the tutorial, like the nitty-gritty of getting credentials from the Testnet faucet.
|
||||
|
||||
This is where the `include_code` filter comes in really handy. You can pull in just an excerpt of a code sample based on starting and ending bits. For example:
|
||||
This is where `include_code` comes in really handy. You can pull in just an excerpt of a code sample based on starting and ending bits. For example:
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/send-xrp.js",
|
||||
start_with="// Connect", end_before="// Get credentials",
|
||||
|
||||
Reference in New Issue
Block a user