xrpl.js 2.0: more updates

This commit is contained in:
mDuo13
2021-10-15 17:49:35 -07:00
parent c0d32f50ca
commit 73a3756ede
11 changed files with 26 additions and 24 deletions

View File

@@ -136,7 +136,7 @@ const set_up_tx_sender = async function() {
try { try {
const {tx_blob, hash} = use_wallet.sign(prepared) const {tx_blob, hash} = use_wallet.sign(prepared)
const final_result_data = await api.submitSignedReliable(tx_blob) const final_result_data = await api.submitAndWait(tx_blob)
console.log("final_result_data is", final_result_data) console.log("final_result_data is", final_result_data)
let final_result = final_result_data.result.meta.TransactionResult let final_result = final_result_data.result.meta.TransactionResult
if (!silent) { if (!silent) {

File diff suppressed because one or more lines are too long

2
assets/js/xrpl-2.0.0preview.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -38,7 +38,7 @@ async function main() {
const cst_prepared = await api.autofill(cold_settings_tx) const cst_prepared = await api.autofill(cold_settings_tx)
const cst_signed = cold_wallet.sign(cst_prepared) const cst_signed = cold_wallet.sign(cst_prepared)
console.log("Sending cold address AccountSet transaction...") console.log("Sending cold address AccountSet transaction...")
const cst_result = await api.submitSignedReliable(cst_signed.tx_blob) const cst_result = await api.submitAndWait(cst_signed.tx_blob)
if (cst_result.result.meta.TransactionResult == "tesSUCCESS") { if (cst_result.result.meta.TransactionResult == "tesSUCCESS") {
console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${cst_signed.hash}`) console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${cst_signed.hash}`)
} else { } else {
@@ -61,7 +61,7 @@ async function main() {
const hst_prepared = await api.autofill(hot_settings_tx) const hst_prepared = await api.autofill(hot_settings_tx)
const hst_signed = hot_wallet.sign(hst_prepared) const hst_signed = hot_wallet.sign(hst_prepared)
console.log("Sending hot address AccountSet transaction...") console.log("Sending hot address AccountSet transaction...")
const hst_result = await api.submitSignedReliable(hst_signed.tx_blob) const hst_result = await api.submitAndWait(hst_signed.tx_blob)
if (hst_result.result.meta.TransactionResult == "tesSUCCESS") { if (hst_result.result.meta.TransactionResult == "tesSUCCESS") {
console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${hst_signed.hash}`) console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${hst_signed.hash}`)
} else { } else {
@@ -84,7 +84,7 @@ async function main() {
const ts_prepared = await api.autofill(trust_set_tx) const ts_prepared = await api.autofill(trust_set_tx)
const ts_signed = hot_wallet.sign(ts_prepared) const ts_signed = hot_wallet.sign(ts_prepared)
console.log("Creating trust line from hot address to issuer...") console.log("Creating trust line from hot address to issuer...")
const ts_result = await api.submitSignedReliable(ts_signed.tx_blob) const ts_result = await api.submitAndWait(ts_signed.tx_blob)
if (ts_result.result.meta.TransactionResult == "tesSUCCESS") { if (ts_result.result.meta.TransactionResult == "tesSUCCESS") {
console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${ts_signed.hash}`) console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${ts_signed.hash}`)
} else { } else {
@@ -108,7 +108,7 @@ async function main() {
const pay_prepared = await api.autofill(send_token_tx) const pay_prepared = await api.autofill(send_token_tx)
const pay_signed = cold_wallet.sign(pay_prepared) const pay_signed = cold_wallet.sign(pay_prepared)
console.log(`Sending ${issue_quantity} ${currency_code} to ${hot_wallet.address}...`) console.log(`Sending ${issue_quantity} ${currency_code} to ${hot_wallet.address}...`)
const pay_result = await api.submitSignedReliable(pay_signed.tx_blob) const pay_result = await api.submitAndWait(pay_signed.tx_blob)
if (pay_result.result.meta.TransactionResult == "tesSUCCESS") { if (pay_result.result.meta.TransactionResult == "tesSUCCESS") {
console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${pay_signed.hash}`) console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${pay_signed.hash}`)
} else { } else {

View File

@@ -29,7 +29,7 @@ async function main() {
const signed = wallet.sign(prepared) const signed = wallet.sign(prepared)
console.log("Transaction hash:", signed.hash) console.log("Transaction hash:", signed.hash)
const submit_result = await client.submitSignedReliable(signed.tx_blob) const submit_result = await client.submitAndWait(signed.tx_blob)
console.log("Submit result:", submit_result) console.log("Submit result:", submit_result)

View File

@@ -36,11 +36,11 @@ async function main() {
console.log("Signed blob:", signed.tx_blob) console.log("Signed blob:", signed.tx_blob)
// Submit signed blob -------------------------------------------------------- // Submit signed blob --------------------------------------------------------
const tx = await api.submitSignedReliable(signed.tx_blob) const tx = await api.submitAndWait(signed.tx_blob)
// This raises an exception if the transaction isn't confirmed. // This raises an exception if the transaction isn't confirmed.
// Wait for validation ------------------------------------------------------- // Wait for validation -------------------------------------------------------
// submitSignedReliable() handles this automatically, but it can take 4-7s. // submitAndWait() handles this automatically, but it can take 4-7s.
// Check transaction results ------------------------------------------------- // Check transaction results -------------------------------------------------
console.log("Transaction result:", tx.result.meta.TransactionResult) console.log("Transaction result:", tx.result.meta.TransactionResult)

View File

@@ -62,7 +62,7 @@ The serialization processes described here are implemented in multiple places an
- In JavaScript in the [`ripple-binary-codec`](https://github.com/ripple/ripple-binary-codec/) package. - In JavaScript in the [`ripple-binary-codec`](https://github.com/ripple/ripple-binary-codec/) package.
- In Python 3 in [this repository's code samples section]({{target.github_forkurl}}/blob/{{target.github_branch}}/content/_code-samples/tx-serialization/serialize.py). - In Python 3 in [this repository's code samples section]({{target.github_forkurl}}/blob/{{target.github_branch}}/content/_code-samples/tx-serialization/serialize.py).
Additionally, many [client libraries](client-libraries) provide serialization support under permissive open-source licenses, so you can import, use, or adapt the code for your needs. Additionally, many [client libraries](client-libraries.html) provide serialization support under permissive open-source licenses, so you can import, use, or adapt the code for your needs.

View File

@@ -51,7 +51,7 @@ const xrpl = require("xrpl");
## Transaction Submission ## Transaction Submission
In xrpl.js there are specific helper functions for signing and submitting transactions and waiting for the XRP Ledger blockchain to confirm those transactions' final outcomes. Use the `submitReliable(tx_json, wallet)` method to sign a prepared transaction with the given wallet and submit it, like in this example: In xrpl.js there are specific helper functions for signing and submitting transactions and waiting for the XRP Ledger blockchain to confirm those transactions' final outcomes. Use the `submitAndWait(tx_json, wallet)` method to sign a prepared transaction with the given wallet and submit it, like in this example:
```js ```js
const tx_json = await client.autofill({ const tx_json = await client.autofill({
@@ -60,8 +60,8 @@ const tx_json = await client.autofill({
"SetFlag": xrpl.AccountSetAsfFlags.asfRequireDest "SetFlag": xrpl.AccountSetAsfFlags.asfRequireDest
}) })
try { try {
const submit_result = await client.submitReliable(tx_json, wallet) const submit_result = await client.submitAndWait(tx_json, wallet)
// submitReliable() doesn't return until the transaction has a final result. // submitAndWait() doesn't return until the transaction has a final result.
// Raises XrplError if the transaction doesn't get confirmed by the network. // Raises XrplError if the transaction doesn't get confirmed by the network.
console.log("Transaction result:", submit_result) console.log("Transaction result:", submit_result)
} catch(err) { } catch(err) {
@@ -69,7 +69,7 @@ try {
} }
``` ```
Alternatively, you can use the `sign` method of a wallet to sign a transaction and then use `submitSignedReliable(tx_blob)` to submit it. This can be useful for building [reliable transaction submission](reliable-transaction-submission.html) that can recover from power outages and other disasters. (The library does not handle disaster recovery on its own.) Alternatively, you can use the `sign` method of a wallet to sign a transaction and then use `submitAndWait(tx_blob)` to submit it. This can be useful for building [reliable transaction submission](reliable-transaction-submission.html) that can recover from power outages and other disasters. (The library does not handle disaster recovery on its own.)
@@ -80,7 +80,7 @@ In ripple-lib 1.x all methods and properties were on instances of the `RippleAPI
| RippleAPI instance method / property | xrpl.js method / property| Notes | | RippleAPI instance method / property | xrpl.js method / property| Notes |
|-------------------|----------------|---| |-------------------|----------------|---|
| `new ripple.RippleAPI({server: url})` | `new xrpl.Client(url)` | Use `xrpl.BroadcastClient([url1, url2, ..])` to connect to multiple servers. | | `new ripple.RippleAPI({server: url})` | `new xrpl.Client(url)` | Use `xrpl.BroadcastClient([url1, url2, ..])` to connect to multiple servers. |
| `request(command, options)` | `Client.request(options)` | The `command` field moved into the `options` object for consistency with the WebSocket API. | | `request(command, options)` | `Client.request(options)` | The `command` field moved into the `options` object for consistency with the WebSocket API; also, the return value . |
| `hasNextPage(response)` | ***TODO (check for marker?)*** | See also: `Client.requestNextPage()` and `Client.requestAll()` | | `hasNextPage(response)` | ***TODO (check for marker?)*** | See also: `Client.requestNextPage()` and `Client.requestAll()` |
| `requestNextPage(command, options, response)` | `Client.requestNextPage(response)` | | | `requestNextPage(command, options, response)` | `Client.requestNextPage(response)` | |
| `computeBinaryTransactionHash(tx_blob)` | `xrpl.hashes.hashTx(tx_blob)` | | | `computeBinaryTransactionHash(tx_blob)` | `xrpl.hashes.hashTx(tx_blob)` | |

View File

@@ -14,7 +14,7 @@ showcase_icon: assets/img/logos/javascript.svg
This tutorial guides you through the basics of building an XRP Ledger-connected application in JavaScript or TypeScript using the [`xrpl.js`](https://github.com/XRPLF/xrpl.js/) client library in either Node.js or web browsers. This tutorial guides you through the basics of building an XRP Ledger-connected application in JavaScript or TypeScript using the [`xrpl.js`](https://github.com/XRPLF/xrpl.js/) client library in either Node.js or web browsers.
The scripts and config files used in this guide are [available in this website's GitHub Repository]({{github_forkurl}}/tree/{{github_branch}}/content/_code-samples/get-started/js/). The scripts and config files used in this guide are [available in this website's GitHub Repository]({{target.github_forkurl}}/tree/{{target.github_branch}}/content/_code-samples/get-started/js/).
## Learning goals ## Learning goals

View File

@@ -110,7 +110,7 @@ The bare minimum set of instructions you must provide for an XRP Payment is:
Technically, a viable transaction must contain some additional fields, and certain optional fields such as `LastLedgerSequence` are strongly recommended. Some other language-specific notes: Technically, a viable transaction must contain some additional fields, and certain optional fields such as `LastLedgerSequence` are strongly recommended. Some other language-specific notes:
- If you're using `xrpl.js` for JavaScript or TypeScript, you can use the [`Client.autofill()` method](TODO: link autofill) to automatically fill in good defaults for the remaining fields of a transaction. - If you're using `xrpl.js` for JavaScript, you can use the [`Client.autofill()` method](https://js.xrpl.org/classes/Client.html#autofill) to automatically fill in good defaults for the remaining fields of a transaction. In TypeScript, you can also use the transaction models like `xrpl.Payment` to enforce the correct fields.
- With `xrpl-py` for Python, you can use the models in `xrpl.models.transactions` to construct transactions as native Python objects. - With `xrpl-py` for Python, you can use the models in `xrpl.models.transactions` to construct transactions as native Python objects.
- With xrpl4j for Java, you can use the model objects in the `xrpl4j-model` module to construct transactions as Java objects. - With xrpl4j for Java, you can use the model objects in the `xrpl4j-model` module to construct transactions as Java objects.
- Unlike the other libraries, you must provide the account `sequence` and the `signingPublicKey` of the source - Unlike the other libraries, you must provide the account `sequence` and the `signingPublicKey` of the source
@@ -156,7 +156,7 @@ _Java_
Signing a transaction uses your credentials to authorize the transaction on your behalf. The input to this step is a completed set of transaction instructions (usually JSON), and the output is a binary blob containing the instructions and a signature from the sender. Signing a transaction uses your credentials to authorize the transaction on your behalf. The input to this step is a completed set of transaction instructions (usually JSON), and the output is a binary blob containing the instructions and a signature from the sender.
- **JavaScript:** Use the [sign() method of a Wallet instance](TODO: link sign) to sign the transaction with `xrpl.js`. - **JavaScript:** Use the [`sign()` method of a Wallet instance](https://js.xrpl.org/classes/Wallet.html#sign) to sign the transaction with `xrpl.js`.
- **Python:** Use the [`xrpl.transaction.safe_sign_transaction()` method](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.transaction.html#xrpl.transaction.safe_sign_transaction) with a model and wallet object. - **Python:** Use the [`xrpl.transaction.safe_sign_transaction()` method](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.transaction.html#xrpl.transaction.safe_sign_transaction) with a model and wallet object.
- **Java:** Use a [`SignatureService`](https://javadoc.io/doc/org.xrpl/xrpl4j-crypto-core/latest/org/xrpl/xrpl4j/crypto/signing/SignatureService.html) instance to sign the transaction. For this tutorial, use the [`SingleKeySignatureService`](https://javadoc.io/doc/org.xrpl/xrpl4j-crypto-bouncycastle/latest/org/xrpl/xrpl4j/crypto/signing/SingleKeySignatureService.html). - **Java:** Use a [`SignatureService`](https://javadoc.io/doc/org.xrpl/xrpl4j-crypto-core/latest/org/xrpl/xrpl4j/crypto/signing/SignatureService.html) instance to sign the transaction. For this tutorial, use the [`SingleKeySignatureService`](https://javadoc.io/doc/org.xrpl/xrpl4j-crypto-bouncycastle/latest/org/xrpl/xrpl4j/crypto/signing/SingleKeySignatureService.html).
@@ -196,7 +196,7 @@ The result of the signing operation is a transaction object containing a signatu
Now that you have a signed transaction, you can submit it to an XRP Ledger server, and that server will relay it through the network. It's also a good idea to take note of the latest validated ledger index before you submit. The earliest ledger version that your transaction could get into as a result of this submission is one higher than the latest validated ledger when you submit it. Of course, if the same transaction was previously submitted, it could already be in a previous ledger. (It can't succeed a second time, but you may not realize it succeeded if you aren't looking in the right ledger versions.) Now that you have a signed transaction, you can submit it to an XRP Ledger server, and that server will relay it through the network. It's also a good idea to take note of the latest validated ledger index before you submit. The earliest ledger version that your transaction could get into as a result of this submission is one higher than the latest validated ledger when you submit it. Of course, if the same transaction was previously submitted, it could already be in a previous ledger. (It can't succeed a second time, but you may not realize it succeeded if you aren't looking in the right ledger versions.)
- **JavaScript:** Use the [`submitSignedReliable()` method of the Client](https://js.xrpl.org/classes/Client.html#submitSignedReliable) to submit a signed transaction to the network and wait for the response, or use [`submitSigned()`](https://js.xrpl.org/classes/Client.html#submitSigned) to submit a transaction and get only the preliminary response. - **JavaScript:** Use the [`submitAndWait()` method of the Client](https://js.xrpl.org/classes/Client.html#submitAndWait) to submit a signed transaction to the network and wait for the response, or use [`submitSigned()`](https://js.xrpl.org/classes/Client.html#submitSigned) to submit a transaction and get only the preliminary response.
- **Python:** Use the [`xrpl.transaction.send_reliable_submission()` method](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.transaction.html#xrpl.transaction.send_reliable_submission) to submit a transaction to the network and wait for a response. - **Python:** Use the [`xrpl.transaction.send_reliable_submission()` method](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.transaction.html#xrpl.transaction.send_reliable_submission) to submit a transaction to the network and wait for a response.
- **Java:** Use the [`XrplClient.submit(SignedTransaction)` method](https://javadoc.io/doc/org.xrpl/xrpl4j-client/latest/org/xrpl/xrpl4j/client/XrplClient.html#submit(org.xrpl.xrpl4j.crypto.signing.SignedTransaction)) to submit a transaction to the network. Use the [`XrplClient.ledger()`](https://javadoc.io/doc/org.xrpl/xrpl4j-client/latest/org/xrpl/xrpl4j/client/XrplClient.html#ledger(org.xrpl.xrpl4j.model.client.ledger.LedgerRequestParams)) method to get the latest validated ledger index. - **Java:** Use the [`XrplClient.submit(SignedTransaction)` method](https://javadoc.io/doc/org.xrpl/xrpl4j-client/latest/org/xrpl/xrpl4j/client/XrplClient.html#submit(org.xrpl.xrpl4j.crypto.signing.SignedTransaction)) to submit a transaction to the network. Use the [`XrplClient.ledger()`](https://javadoc.io/doc/org.xrpl/xrpl4j-client/latest/org/xrpl/xrpl4j/client/XrplClient.html#ledger(org.xrpl.xrpl4j.model.client.ledger.LedgerRequestParams)) method to get the latest validated ledger index.
@@ -238,7 +238,7 @@ example transaction</button>
Most transactions are accepted into the next ledger version after they're submitted, which means it may take 4-7 seconds for a transaction's outcome to be final. If the XRP Ledger is busy or poor network connectivity delays a transaction from being relayed throughout the network, a transaction may take longer to be confirmed. (For more information on expiration of unconfirmed transactions, see [Reliable Transaction Submission](reliable-transaction-submission.html).) Most transactions are accepted into the next ledger version after they're submitted, which means it may take 4-7 seconds for a transaction's outcome to be final. If the XRP Ledger is busy or poor network connectivity delays a transaction from being relayed throughout the network, a transaction may take longer to be confirmed. (For more information on expiration of unconfirmed transactions, see [Reliable Transaction Submission](reliable-transaction-submission.html).)
- **JavaScript:** If you used the [`.submitSignedReliable()` method](https://js.xrpl.org/classes/Client.html#submitSignedReliable), you can wait until the returned Promise resolves. Other, more asynchronous approaches are also possible. - **JavaScript:** If you used the [`.submitAndWait()` method](https://js.xrpl.org/classes/Client.html#submitAndWait), you can wait until the returned Promise resolves. Other, more asynchronous approaches are also possible.
- **Python:** If you used the [`xrpl.transaction.send_reliable_submission()` method](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.transaction.html#xrpl.transaction.send_reliable_submission), you can wait for the function to return. Other approaches, including asynchronous ones using the WebSocket client, are also possible. - **Python:** If you used the [`xrpl.transaction.send_reliable_submission()` method](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.transaction.html#xrpl.transaction.send_reliable_submission), you can wait for the function to return. Other approaches, including asynchronous ones using the WebSocket client, are also possible.
@@ -269,7 +269,7 @@ _Java_
To know for sure what a transaction did, you must look up the outcome of the transaction when it appears in a validated ledger version. To know for sure what a transaction did, you must look up the outcome of the transaction when it appears in a validated ledger version.
- **JavaScript:** Use the response from `submitSignedReliable()` or call the [tx method][] using [`Client.request()`](https://js.xrpl.org/classes/Client.html#request). - **JavaScript:** Use the response from `submitAndWait()` or call the [tx method][] using [`Client.request()`](https://js.xrpl.org/classes/Client.html#request).
**Tip:** In **TypeScript** you can pass a [`TxRequest`](https://js.xrpl.org/interfaces/TxRequest.html) to the [`Client.request()`](https://js.xrpl.org/classes/Client.html#request) method. **Tip:** In **TypeScript** you can pass a [`TxRequest`](https://js.xrpl.org/interfaces/TxRequest.html) to the [`Client.request()`](https://js.xrpl.org/classes/Client.html#request) method.

View File

@@ -64,7 +64,7 @@ default_keys: &defaults
hover_anchors: <i class="fa fa-link"></i> hover_anchors: <i class="fa fa-link"></i>
light_theme_enabled: true light_theme_enabled: true
# Script tags used in a variety of tools & examples. # Script tags used in a variety of tools & examples.
ripple_lib_tag: '<script type="application/javascript" src="assets/js/xrpl-2.0.0b5.min.js"></script>' ripple_lib_tag: '<script type="application/javascript" src="assets/js/xrpl-2.0.0preview.min.js"></script>'
targets: targets:
# First member is the default that gets built when target not specified # First member is the default that gets built when target not specified
@@ -159,7 +159,9 @@ targets:
"xrp-ledger-toml.html#account-verification": "xrp-ledger-toml.html#アカウント検証" "xrp-ledger-toml.html#account-verification": "xrp-ledger-toml.html#アカウント検証"
"offers.html#offers-and-trust": "offers.html#オファーとトラスト" "offers.html#offers-and-trust": "offers.html#オファーとトラスト"
"authorized-trust-lines.html#authorizing-trust-lines": "authorized-trust-lines.html#トラストラインの承認" "authorized-trust-lines.html#authorizing-trust-lines": "authorized-trust-lines.html#トラストラインの承認"
# Fix links from untranslated freeze tutorials:
"accountset.html#accountset-flags": "accountset.html#accountsetのフラグ"
"ripplestate.html#ripplestate-flags": "ripplestate.html#ripplestateのフラグ"
pages: pages: