Freeze tutorials: fixes and cleanup

- Move JS code samples to JS folder (future-proofing for other
  languages)
- Make "Freeze a Trust Line" tutorial interactive
- Add necessary functionality to interactive_tutorial helper JS
- Rework freeze a trust line tutorial/code sample to make an incoming
  line from another address and make looking up trust lines a
  full-fledged step
This commit is contained in:
mDuo13
2021-10-25 22:56:31 -07:00
parent afe6b6263d
commit 7c6257c2d8
15 changed files with 448 additions and 117 deletions

View File

@@ -73,7 +73,7 @@ For example:
_JavaScript_
{{ include_code("_code-samples/freeze/set-no-freeze.js", start_with="// Submit an AccountSet transaction", end_before="// Done", language="js") }}
{{ include_code("_code-samples/freeze/js/set-no-freeze.js", start_with="// Submit an AccountSet transaction", end_before="// Done", language="js") }}
_WebSocket_
@@ -122,7 +122,7 @@ After the transaction is validated, you can check your account's settings to con
_JavaScript_
{{ include_code("_code-samples/freeze/check-no-freeze.js", start_with="// Request account info", end_before="await client.disconnect()", language="js") }}
{{ include_code("_code-samples/freeze/js/check-no-freeze.js", start_with="// Request account info", end_before="await client.disconnect()", language="js") }}
_WebSocket_

View File

@@ -78,7 +78,7 @@ For example:
_JavaScript_
{{ include_code("_code-samples/freeze/set-global-freeze.js", language="js", start_with="// Prepare an AccountSet", end_before="// Investigate") }}
{{ include_code("_code-samples/freeze/js/set-global-freeze.js", language="js", start_with="// Prepare an AccountSet", end_before="// Investigate") }}
_WebSocket_
@@ -125,7 +125,7 @@ After the transaction is validated, you can check your issuing account's setting
_JavaScript_
{{ include_code("_code-samples/freeze/check-global-freeze.js", language="js", start_with="// Request account info", end_before="await client.disconnect()") }}
{{ include_code("_code-samples/freeze/js/check-global-freeze.js", language="js", start_with="// Request account info", end_before="await client.disconnect()") }}
_WebSocket_
@@ -202,7 +202,7 @@ For example:
_JavaScript_
{{ include_code("_code-samples/freeze/set-global-freeze.js", language="js", start_with="// Now we disable", end_before="// Global freeze disabled") }}
{{ include_code("_code-samples/freeze/js/set-global-freeze.js", language="js", start_with="// Now we disable", end_before="// Global freeze disabled") }}
_WebSocket_

View File

@@ -2,7 +2,9 @@
html: freeze-a-trust-line.html
parent: use-tokens.html
blurb: Freeze an individual holder of a token.
embed_ripple_lib: true
filters:
- interactive_steps
- include_code
labels:
- Tokens
@@ -23,6 +25,9 @@ This tutorial shows the steps to [freeze an individual trust line](freezes.html#
- This tutorial assumes **you have already [issued a token](issue-a-fungible-token.html)** in the XRP Ledger.
- You **cannot** have enabled the [No Freeze setting](freezes.html#no-freeze), which gives up your ability to freeze individual trust lines.
<!-- Source for this specific tutorial's interactive bits: -->
<script type="application/javascript" src="assets/js/tutorials/freeze-individual-line.js"></script>
## Example Code
@@ -37,6 +42,8 @@ Complete sample code for all of the steps of this tutorial is available under th
To transact on the XRP Ledger, you need an address and secret key, and some XRP. If you use the best practice of having separate ["cold" and "hot" addresses](issuing-and-operational-addresses.html), you need the keys to the _cold address_, which is the **issuer** of the token.
{% include '_snippets/interactive-tutorials/generate-step.md' %}
### {{n.next()}}. Connect to the Network
You must be connected to the network to submit transactions to it. The following code shows how to connect to a public XRP Ledger Testnet server a supported [client library](client-libraries.html):
@@ -55,6 +62,78 @@ _WebSocket_
<!-- MULTICODE_BLOCK_END -->
For purposes of this tutorial, use the following interface to connect and perform setup:
{% include '_snippets/interactive-tutorials/connect-step.md' %}
### {{n.next()}}. Choose Trust Line
You can only freeze one trust line per transaction, so you need to know which one you want. A trust line is uniquely identified by these 3 things:
- Your own address.
- The address of the account linked to yours via the trust line.
- The currency code of the trust line.
There can be multiple [trust lines](trust-lines-and-issuing.html) between two accounts, each for a different currency. If you suspect a particular account is behaving maliciously, you may want to freeze all the trust lines between your accounts, one at a time. Use the [account_lines method][] with a pair of accounts to find all trust lines between those accounts, then choose a trust line to freeze from among the results. For example:
<!-- MULTICODE_BLOCK_START -->
_JavaScript_
{{ include_code("_code-samples/freeze/js/set-individual-freeze.js", language="js", start_with="// Look up current trust lines", end_before="// Send a TrustSet") }}
_WebSocket_
```json
Example Request:
{
"id": "example_look_up_trust_lines",
"command": "account_lines",
"account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"peer": "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW",
"ledger_index": "validated"
}
// Example Response:
{
"id": "example_look_up_trust_lines",
"result": {
"account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"ledger_hash": "AF5C6E6FBC44183D8662C7F5BF88D52F99738A0E66FF07FC7B5A516AC8EA1B37",
"ledger_index": 67268474,
"lines": [
{
"account": "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW",
"balance": "0",
"currency": "USD",
"limit": "0",
"limit_peer": "110",
"quality_in": 0,
"quality_out": 0
}
],
"validated": true
},
"status": "success",
"type": "response"
}
```
<!-- MULTICODE_BLOCK_END -->
For purposes of this tutorial, a second test address has created a trust line to the test address for the currency "FOO", which you can see in the following example:
{{ start_step("Choose Trust Line")}}
<div class="loader collapse" id="trust-line-setup-loader"><img class="throbber" src="assets/img/xrp-loader-96.png">Waiting for setup to complete...</div>
<input type="hidden" id="peer-seed" value="" />
<button id="look-up-trust-lines" class="btn btn-primary" disabled="disabled" title="Wait for setup to complete...">Choose Trust Line</button>
<div class="loader loader-looking collapse"><img class="throbber" src="assets/img/xrp-loader-96.png">Looking...</div>
<div class="output-area"></div>
{{ end_step() }}
### {{n.next()}}. Send TrustSet Transaction to Freeze the Trust Line
@@ -76,7 +155,7 @@ As always, to send a transaction, you _prepare_ it by filling in all the necessa
_JavaScript_
{{ include_code("_code-samples/freeze/set-individual-freeze.js", language="js", start_with="// Prepare a TrustSet", end_before="// Investigate") }}
{{ include_code("_code-samples/freeze/js/set-individual-freeze.js", language="js", start_with="// Send a TrustSet", end_before="// Investigate") }}
_WebSocket_
@@ -103,11 +182,22 @@ _WebSocket_
<!-- MULTICODE_BLOCK_END -->
{{ start_step("Send TrustSet to Freeze") }}
<button class="btn btn-primary previous-steps-required send-trustset" data-wait-step-name="Wait" data-action="start_freeze">Send TrustSet (Freeze)</button>
<div class="loader collapse"><img class="throbber" src="assets/img/xrp-loader-96.png">Sending...</div>
<div class="output-area"></div>
{{ end_step() }}
**Note:** If you want to freeze multiple trust lines in different currencies with the same counterparty, repeat this step for each one, choosing a different currency code each time. It is possible to send several transactions in a single ledger if you use different [sequence numbers](basic-data-types.html#account-sequence) for each. <!--{# TODO: link rapid/batch submission guidelines when https://github.com/XRPLF/xrpl-dev-portal/issues/1025 is done #}-->
### {{n.next()}}. Wait for Validation
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 information on how to set an expiration for transactions, see [Reliable Transaction Submission](reliable-transaction-submission.html).)
{{ start_step("Wait") }}
{% include '_snippets/interactive-tutorials/wait-step.md' %}
{{ end_step() }}
### {{n.next()}}. Check Trust Line Freeze Status
@@ -120,13 +210,13 @@ At this point, the trust line from the counterparty should be frozen. You can ch
**Caution:** The response includes _all_ trust lines between the two accounts. (Each different currency code uses a different trust line.) Be sure to check the one for the right token.
In the response, the field `"freeze": true` indicates that the account from the request has enabled an Individual Freeze on that trust line. The field `"freeze_peer": true` indicates that the counterparty (`peer`) from the request has frozen the trust line.
In the response, the field `"freeze": true` indicates that the account from the request has enabled an Individual Freeze on that trust line. The field `"freeze_peer": true` indicates that the counterparty (`peer`) from the request has frozen the trust line. For example:
<!-- MULTICODE_BLOCK_START -->
_JavaScript_
{{ include_code("_code-samples/freeze/check-individual-freeze.js", language="js", start_with="// Look up current state", end_before="await client.disconnect()") }}
{{ include_code("_code-samples/freeze/js/set-individual-freeze.js", language="js", start_with="// Confirm trust line status", end_before="// Investigate") }}
_WebSocket_
@@ -167,6 +257,13 @@ Example Response:
<!-- MULTICODE_BLOCK_END -->
{{ start_step("Check Freeze Status") }}
<button id="confirm-settings" class="btn btn-primary previous-steps-required">Check Trust Line</button>
<div class="loader collapse"><img class="throbber" src="assets/img/xrp-loader-96.png">Checking...</div>
<div class="output-area"></div>
{{ end_step() }}
### {{n.next()}}. (Optional) Send TrustSet Transaction to End the Freeze
If you decide that the trust line no longer needs to be frozen (for example, you investigated and decided that the suspicious activity was benign), you can end the individual freeze in almost the same way that you froze the trust line in the first place. To end an individual freeze, send a [TrustSet transaction][] with the [`tfClearFreeze` flag enabled](trustset.html#trustset-flags). The other fields of the transaction should be the same as when you froze the trust line:
@@ -187,7 +284,7 @@ As always, to send a transaction, you _prepare_ it by filling in all the necessa
_JavaScript_
{{ include_code("_code-samples/freeze/set-individual-freeze.js", language="js", start_with="// Clear the individual", end_before="// End main") }}
{{ include_code("_code-samples/freeze/js/set-individual-freeze.js", language="js", start_with="// Clear the individual", end_before="// End main") }}
_WebSocket_
@@ -214,10 +311,21 @@ _WebSocket_
<!-- MULTICODE_BLOCK_END -->
{{ start_step("Send TrustSet to End Freeze") }}
<button class="btn btn-primary previous-steps-required send-trustset" data-wait-step-name="Wait (again)" data-action="end_freeze">Send TrustSet (End Freeze)</button>
<div class="loader collapse"><img class="throbber" src="assets/img/xrp-loader-96.png">Sending...</div>
<div class="output-area"></div>
{{ end_step() }}
### {{n.next()}}. Wait for Validation
As before, wait for the previous transaction to be validated by consensus before continuing.
As before, wait for the transaction to be validated by consensus.
{{ start_step("Wait (again)") }}
{% include '_snippets/interactive-tutorials/wait-step.md' %}
{{ end_step() }}
## See Also