From 7c3ff821f0fff513e334cbef10baf77015b1b232 Mon Sep 17 00:00:00 2001 From: mDuo13 Date: Wed, 27 Oct 2021 17:37:05 -0700 Subject: [PATCH] Code samples: READMEs and smarter parsing --- content/_code-samples/escrow/README.md | 4 +++- content/_code-samples/freeze/README.md | 5 +++++ content/_code-samples/get-started/README.md | 9 +++++++++ content/_code-samples/issue-a-token/README.md | 5 +++++ content/_code-samples/key-derivation/README.md | 5 +++++ .../monitor-payments-websocket/README.md | 3 +++ .../_code-samples/require-destination-tags/README.md | 5 +++++ content/_code-samples/secure-signing/README.md | 5 +++++ content/_code-samples/send-xrp/README.md | 5 +++++ content/_code-samples/submit-and-verify/README.md | 7 +++++-- content/_code-samples/tx-serialization/README.md | 5 +++++ content/_code-samples/use-tickets/README.md | 5 +++++ template/page-code-samples.html.jinja | 3 +-- tool/filter_code_samples.py | 12 ++++++++---- 14 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 content/_code-samples/freeze/README.md create mode 100644 content/_code-samples/get-started/README.md create mode 100644 content/_code-samples/issue-a-token/README.md create mode 100644 content/_code-samples/key-derivation/README.md create mode 100644 content/_code-samples/monitor-payments-websocket/README.md create mode 100644 content/_code-samples/require-destination-tags/README.md create mode 100644 content/_code-samples/secure-signing/README.md create mode 100644 content/_code-samples/send-xrp/README.md create mode 100644 content/_code-samples/tx-serialization/README.md create mode 100644 content/_code-samples/use-tickets/README.md diff --git a/content/_code-samples/escrow/README.md b/content/_code-samples/escrow/README.md index 2bdb2b783e..24ce7c75fd 100644 --- a/content/_code-samples/escrow/README.md +++ b/content/_code-samples/escrow/README.md @@ -1,3 +1,5 @@ -# Escrow +# Escrows Create, finish, and cancel [Escrows](https://xrpl.org/escrow.html) using conditional or time-based release. + +Examples from the [Escrow Tutorials](https://xrpl.org/use-escrows.html). diff --git a/content/_code-samples/freeze/README.md b/content/_code-samples/freeze/README.md new file mode 100644 index 0000000000..9db1b00d4e --- /dev/null +++ b/content/_code-samples/freeze/README.md @@ -0,0 +1,5 @@ +# Freezes + +Freeze and unfreeze issued tokens, check freeze status, or give up the ability to freeze tokens. + +Examples from the [Freeze tutorials](https://xrpl.org/use-tokens.html). diff --git a/content/_code-samples/get-started/README.md b/content/_code-samples/get-started/README.md new file mode 100644 index 0000000000..c764d32f50 --- /dev/null +++ b/content/_code-samples/get-started/README.md @@ -0,0 +1,9 @@ +# Get Started + +Introductory code samples showing how to connect to the XRP Ledger and query it for data. + +For more context, see the Get Started tutorial for your preferred language: + +- [Python](https://xrpl.org/get-started-using-python.html) +- [Java](https://xrpl.org/get-started-using-java.html) +- [JavaScript](https://xrpl.org/get-started-using-javascript.html) diff --git a/content/_code-samples/issue-a-token/README.md b/content/_code-samples/issue-a-token/README.md new file mode 100644 index 0000000000..1e6abb43e0 --- /dev/null +++ b/content/_code-samples/issue-a-token/README.md @@ -0,0 +1,5 @@ +# Issue a Fungible Token + +Configure issuer settings and issue fungible tokens to a hot wallet. + +For an interactive tutorial demonstrating the function of these code samples, see [Issue a Fungible Token](https://xrpl.org/issue-a-fungible-token.html). diff --git a/content/_code-samples/key-derivation/README.md b/content/_code-samples/key-derivation/README.md new file mode 100644 index 0000000000..750769239b --- /dev/null +++ b/content/_code-samples/key-derivation/README.md @@ -0,0 +1,5 @@ +# Cryptographic Key Derivation + +Derive secp256k1 or Ed25519 key pairs from seeds in any of the XRP Ledger's encodings and formats. + +For background and diagrams, see [Key Derivation](https://xrpl.org/cryptographic-keys.html#key-derivation). diff --git a/content/_code-samples/monitor-payments-websocket/README.md b/content/_code-samples/monitor-payments-websocket/README.md new file mode 100644 index 0000000000..566abc97bf --- /dev/null +++ b/content/_code-samples/monitor-payments-websocket/README.md @@ -0,0 +1,3 @@ +# Monitor Incoming Payments with WebSocket + +Use the WebSocket protocol to watch for incoming payments to an XRP Ledger address, _without_ using a client library. diff --git a/content/_code-samples/require-destination-tags/README.md b/content/_code-samples/require-destination-tags/README.md new file mode 100644 index 0000000000..c861775ade --- /dev/null +++ b/content/_code-samples/require-destination-tags/README.md @@ -0,0 +1,5 @@ +# Require Destination Tags + +Require incoming payments to your account to specify a [Destination Tag](https://xrpl.org/source-and-destination-tags.html) so you know whom to credit. + +Examples from the [Require Destination Tags tutorial](https://xrpl.org/require-destination-tags.html). diff --git a/content/_code-samples/secure-signing/README.md b/content/_code-samples/secure-signing/README.md new file mode 100644 index 0000000000..9672644d9c --- /dev/null +++ b/content/_code-samples/secure-signing/README.md @@ -0,0 +1,5 @@ +# Secure Signing + +Sign transactions from the security of your own machine. + +For more information and more options, see [Set Up Secure Signing](https://xrpl.org/set-up-secure-signing.html). diff --git a/content/_code-samples/send-xrp/README.md b/content/_code-samples/send-xrp/README.md new file mode 100644 index 0000000000..c2255d439c --- /dev/null +++ b/content/_code-samples/send-xrp/README.md @@ -0,0 +1,5 @@ +# Send XRP + +Send a direct XRP payment to another account in the XRP Ledger. + +Examples from the interactive [Send XRP tutorial](https://xrpl.org/send-xrp.html). diff --git a/content/_code-samples/submit-and-verify/README.md b/content/_code-samples/submit-and-verify/README.md index ccbb5440e3..3a296117da 100644 --- a/content/_code-samples/submit-and-verify/README.md +++ b/content/_code-samples/submit-and-verify/README.md @@ -1,8 +1,11 @@ # Submit and Verify -Example JavaScript code using ripple-lib to submit a signed transaction blob and wait until it has a final result. +Example code to submit a signed transaction blob and wait until it has a final result. -Example usage: +- [submit-and-verify.js](js/submit-and-verify.js): ripple-lib 1.x version. +- [submit-and-verify2.js](js/submit-and-verify2.js): xrpl.js 2.x version. Unlike the submitAndWait() method built into xrpl.js, this checks the server's available history and returns a different code when the transaction's status is unknowable with the server's available history versus if the transaction was _definitely_ not confirmed by consensus. + +Example usage (ripple-lib 1.x): ```js // example testnet creds. Don't use for real diff --git a/content/_code-samples/tx-serialization/README.md b/content/_code-samples/tx-serialization/README.md new file mode 100644 index 0000000000..d3400c9b9e --- /dev/null +++ b/content/_code-samples/tx-serialization/README.md @@ -0,0 +1,5 @@ +# Transaction Serialization + +Convert transactions and other XRPL data from JSON to their canonical binary format for signing or cryptographic verification. + +For a detailed explanation, see [Serialization](https://xrpl.org/serialization.html). diff --git a/content/_code-samples/use-tickets/README.md b/content/_code-samples/use-tickets/README.md new file mode 100644 index 0000000000..2f52cb8680 --- /dev/null +++ b/content/_code-samples/use-tickets/README.md @@ -0,0 +1,5 @@ +# Tickets + +Create a Ticket and use it to send a transaction out of the usual Sequence order. + +For more context, see the interactive [Use Tickets tutorial](https://xrpl.org/use-tickets.html). diff --git a/template/page-code-samples.html.jinja b/template/page-code-samples.html.jinja index 7593040ac2..65868c68d9 100644 --- a/template/page-code-samples.html.jinja +++ b/template/page-code-samples.html.jinja @@ -39,9 +39,8 @@ "go": "assets/img/logos/golang.svg", "java": "assets/img/logos/java.svg", "js": "assets/img/logos/javascript.svg", - "json-rpc": "assets/img/logos/globe.svg", "py": "assets/img/logos/python.svg", - "websocket": "assets/img/logos/globe.svg", + "http": "assets/img/logos/globe.svg", } %} {% for card in code_samples %} diff --git a/tool/filter_code_samples.py b/tool/filter_code_samples.py index 4edf3f6a09..76935a25f1 100644 --- a/tool/filter_code_samples.py +++ b/tool/filter_code_samples.py @@ -13,7 +13,7 @@ import re from bs4 import BeautifulSoup from markdown import markdown -cs_dir = "content/_code-samples/" #TODO: make a configurable field +cs_dir = "content/_code-samples/" skip_dirs = [ "node_modules", ".git", @@ -48,7 +48,7 @@ def all_code_samples(): cs = { "path": dirpath, - "langs": dirnames, + "langs": sorted(list(set(["http" if d in ("websocket", "json-rpc") else d for d in dirnames]))), } if "README.md" in filenames: @@ -62,7 +62,10 @@ def all_code_samples(): else: cs["title"] = to_title_case(os.path.basename(dirpath)) p = soup.find("p") # first paragraph defines the blurb - cs["description"] = p.get_text() + if p: + cs["description"] = p.get_text() + else: + cs["description"] = "" else: cs["title"] = to_title_case(os.path.basename(dirpath)) @@ -70,7 +73,8 @@ def all_code_samples(): cs["href"] = dirpath cses.append(cs) - return cses + # Current sort value: alphabetical by title. + return sorted(cses, key=lambda x: x["title"]) export = { "all_code_samples": all_code_samples,