mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-05 20:35:50 +00:00
Update with review comments
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Create, claim and verify a Payment Channel.
|
||||
* Reference: https://xrpl.org/paychannel.html
|
||||
* Reference: https://xrpl.org/docs/references/protocol/ledger-data/ledger-entry-types/paychannel
|
||||
*/
|
||||
import {
|
||||
AccountObjectsRequest,
|
||||
|
||||
@@ -35,7 +35,7 @@ payment_channel_create = PaymentChannelCreate(
|
||||
public_key=wallet1.public_key,
|
||||
)
|
||||
|
||||
print("Submitting a PaymentChannelCreate transaction...")
|
||||
print("\nSubmitting a PaymentChannelCreate transaction...")
|
||||
payment_channel_response = submit_and_wait(
|
||||
payment_channel_create,
|
||||
client,
|
||||
@@ -53,15 +53,16 @@ account_objects = account_objects_response.result["account_objects"]
|
||||
|
||||
# Find the PayChannel object to get the correct channel ID
|
||||
channel_id = None
|
||||
for obj in account_objects:
|
||||
if obj["LedgerEntryType"] == "PayChannel":
|
||||
channel_id = obj["index"]
|
||||
if 'meta' in payment_channel_response.result and 'AffectedNodes' in payment_channel_response.result['meta']:
|
||||
for node in payment_channel_response.result["meta"]["AffectedNodes"]:
|
||||
if 'CreatedNode' in node and node["CreatedNode"]["LedgerEntryType"] == 'PayChannel':
|
||||
channel_id = node['CreatedNode']['LedgerIndex']
|
||||
break
|
||||
|
||||
if not channel_id:
|
||||
raise Exception("PayChannel not found in account objects")
|
||||
raise Exception("Payment Channel ID not found in the response.")
|
||||
|
||||
print(f"PayChannel ID: {channel_id}")
|
||||
print(f"Payment Channel ID: {channel_id}")
|
||||
|
||||
# Destination claims the Payment Channel and we see the balances to verify.
|
||||
payment_channel_claim = PaymentChannelClaim(
|
||||
@@ -70,7 +71,7 @@ payment_channel_claim = PaymentChannelClaim(
|
||||
amount="100",
|
||||
)
|
||||
|
||||
print("Submitting a PaymentChannelClaim transaction...")
|
||||
print("\nSubmitting a PaymentChannelClaim transaction...")
|
||||
channel_claim_response = submit_and_wait(
|
||||
payment_channel_claim,
|
||||
client,
|
||||
|
||||
@@ -44,7 +44,7 @@ async function main() {
|
||||
"Destination": wallet.address,
|
||||
"Amount": "6000000", //drops XRP
|
||||
"DestinationTag": 2023,
|
||||
"Condition": conditionHex,
|
||||
"Condition": conditionHex, // Omit this for time-held escrows
|
||||
"Fee": "12",
|
||||
"FinishAfter": xrpl.isoTimeToRippleTime(finishAfter.toISOString()),
|
||||
};
|
||||
|
||||
@@ -35,9 +35,11 @@ const main = async () => {
|
||||
"Owner": wallet.address,
|
||||
// This should equal the sequence number of the escrow transaction
|
||||
"OfferSequence": offerSequence,
|
||||
// Crypto condition that must be met before escrow can be completed, passed on escrow creation
|
||||
// Crypto condition that must be met before escrow can be completed, passed on escrow creation.
|
||||
// Omit this for time-held escrows.
|
||||
"Condition": condition,
|
||||
// Fulfillment of the condition, passed on escrow creation
|
||||
// Fulfillment of the condition, passed on escrow creation.
|
||||
// Omit this for time-held escrows.
|
||||
"Fulfillment": fulfillment,
|
||||
};
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ create_txn = EscrowCreate(
|
||||
destination=receiver_addr,
|
||||
finish_after=claim_date,
|
||||
cancel_after=expiry_date,
|
||||
condition=condition
|
||||
condition=condition # Omit this for time-held escrows
|
||||
)
|
||||
|
||||
# Autofill, sign, then submit transaction and wait for result
|
||||
|
||||
@@ -29,8 +29,8 @@ finish_txn = EscrowFinish(
|
||||
account=sender_wallet.address,
|
||||
owner=escrow_creator,
|
||||
offer_sequence=escrow_sequence, # The sequence number of the escrow transaction
|
||||
condition=condition,
|
||||
fulfillment=fulfillment
|
||||
condition=condition, # Omit this for time-held escrows
|
||||
fulfillment=fulfillment # Omit this for time-held escrows
|
||||
)
|
||||
|
||||
# Autofill, sign, then submit transaction and wait for result
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
On a live network (including Mainnet, Testnet, or Devnet), you can wait 4-7 seconds for the ledger to close automatically.
|
||||
|
||||
If you're running `rippled` in stand-alone mode, use the [ledger_accept method][] to manually close the ledger.
|
||||
|
||||
{% raw-partial file="/docs/_snippets/common-links.md" /%}
|
||||
|
||||
@@ -308,7 +308,7 @@ If the transaction fails with the result `tecNO_ALTERNATIVE_KEY`, your account d
|
||||
|
||||
### 4. Wait for validation
|
||||
|
||||
{% partial file="/docs/_snippets/wait-for-validation.md" /%}
|
||||
{% raw-partial file="/docs/_snippets/wait-for-validation.md" /%}
|
||||
|
||||
### 5. Confirm Account Flags
|
||||
|
||||
|
||||
@@ -160,7 +160,7 @@ Make sure that the [Transaction Result](../../../references/protocol/transaction
|
||||
|
||||
## 4. Wait for validation
|
||||
|
||||
{% partial file="/docs/_snippets/wait-for-validation.md" /%}
|
||||
{% raw-partial file="/docs/_snippets/wait-for-validation.md" /%}
|
||||
|
||||
|
||||
## 5. Confirm the new signer list
|
||||
|
||||
@@ -91,7 +91,7 @@ Take note of the transaction's identifying `hash` value so you can check its fin
|
||||
|
||||
## 4. Wait for validation
|
||||
|
||||
{% partial file="/docs/_snippets/wait-for-validation.md" /%}
|
||||
{% raw-partial file="/docs/_snippets/wait-for-validation.md" /%}
|
||||
|
||||
## 5. Confirm final result
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ Response:
|
||||
|
||||
## 4. Wait for validation
|
||||
|
||||
{% partial file="/docs/_snippets/wait-for-validation.md" /%}
|
||||
{% raw-partial file="/docs/_snippets/wait-for-validation.md" /%}
|
||||
|
||||
## 5. Confirm that the escrow was created
|
||||
|
||||
@@ -178,7 +178,7 @@ Take note of the transaction's identifying `hash` value so you can check its fin
|
||||
|
||||
## 7. Wait for validation
|
||||
|
||||
{% partial file="/docs/_snippets/wait-for-validation.md" /%}
|
||||
{% raw-partial file="/docs/_snippets/wait-for-validation.md" /%}
|
||||
|
||||
## 8. Confirm final result
|
||||
|
||||
|
||||
@@ -58,54 +58,11 @@ Response:
|
||||
{% /tab %}
|
||||
|
||||
{% tab label="Javascript" %}
|
||||
```js
|
||||
// Prepare EscrowCreate transaction ------------------------------------
|
||||
const escrowCreateTransaction = {
|
||||
"TransactionType": "EscrowCreate",
|
||||
"Account": wallet.address,
|
||||
"Destination": wallet.address,
|
||||
"Amount": "6000000", //drops XRP
|
||||
"DestinationTag": 2023,
|
||||
"Fee": "12",
|
||||
"FinishAfter": xrpl.isoTimeToRippleTime(finishAfter.toISOString()),
|
||||
};
|
||||
|
||||
xrpl.validate(escrowCreateTransaction);
|
||||
|
||||
// Sign and submit the transaction ----------------------------------------
|
||||
console.log('Signing and submitting the transaction:',
|
||||
JSON.stringify(escrowCreateTransaction, null, "\t"), "\n"
|
||||
);
|
||||
const response = await client.submitAndWait(escrowCreateTransaction, { wallet });
|
||||
console.log(`Sequence number: ${response.result.tx_json.Sequence}`);
|
||||
console.log(`Finished submitting! ${JSON.stringify(response.result, null, "\t")}`);
|
||||
```
|
||||
{% code-snippet file="/_code-samples/escrow/js/create-escrow.js" language="js" from="// Prepare EscrowCreate" before="await client.disconnect" /%}
|
||||
{% /tab %}
|
||||
|
||||
{% tab label="Python" %}
|
||||
```python
|
||||
# Build escrow create transaction
|
||||
create_txn = EscrowCreate(
|
||||
account=sender_wallet.address,
|
||||
amount=xrp_to_drops(10.000),
|
||||
destination=receiver_addr,
|
||||
finish_after=claim_date
|
||||
)
|
||||
|
||||
# Autofill, sign, then submit transaction and wait for result
|
||||
stxn_response = submit_and_wait(create_txn, client, sender_wallet)
|
||||
|
||||
# Return result of transaction
|
||||
stxn_result = stxn_response.result
|
||||
|
||||
|
||||
# Parse result and print out the neccesary info
|
||||
print(stxn_result["tx_json"]["Account"])
|
||||
print(stxn_result["tx_json"]["Sequence"])
|
||||
|
||||
print(stxn_result["meta"]["TransactionResult"])
|
||||
print(stxn_result["hash"])
|
||||
```
|
||||
{% code-snippet file="/_code-samples/escrow/py/create_escrow.py" language="py" from="# Build escrow create" /%}
|
||||
{% /tab %}
|
||||
|
||||
{% /tabs %}
|
||||
@@ -114,7 +71,7 @@ Take note of the transaction's identifying `hash` value so you can check its fin
|
||||
|
||||
## 3. Wait for validation
|
||||
|
||||
{% partial file="/docs/_snippets/wait-for-validation.md" /%}
|
||||
{% raw-partial file="/docs/_snippets/wait-for-validation.md" /%}
|
||||
|
||||
## 4. Confirm that the escrow was created
|
||||
|
||||
@@ -191,44 +148,11 @@ Response:
|
||||
{% /tab %}
|
||||
|
||||
{% tab label="Javascript" %}
|
||||
```js
|
||||
// Prepare EscrowFinish transaction ---------------------------------
|
||||
const escrowFinishTransaction = {
|
||||
"Account": wallet.address,
|
||||
"TransactionType": "EscrowFinish",
|
||||
"Owner": wallet.address,
|
||||
// This should equal the sequence number of the escrow transaction
|
||||
"OfferSequence": offerSequence,
|
||||
};
|
||||
|
||||
xrpl.validate(escrowFinishTransaction);
|
||||
|
||||
// Sign and submit the transaction ----------------------------------------
|
||||
console.log('Signing and submitting the transaction:', JSON.stringify(escrowFinishTransaction, null, "\t"));
|
||||
const response = await client.submitAndWait(escrowFinishTransaction, { wallet });
|
||||
console.log(`Finished submitting! ${JSON.stringify(response.result, null, "\t")}`);
|
||||
```
|
||||
{% code-snippet file="/_code-samples/escrow/js/finish-escrow.js" language="js" from="// Prepare EscrowFinish" before="await client.disconnect" /%}
|
||||
{% /tab %}
|
||||
|
||||
{% tab label="Python" %}
|
||||
```python
|
||||
# Build escrow finish transaction
|
||||
finish_txn = EscrowFinish(
|
||||
account=sender_wallet.address,
|
||||
owner=escrow_creator,
|
||||
offer_sequence=escrow_sequence, # The sequence number of the escrow transaction
|
||||
)
|
||||
|
||||
# Autofill, sign, then submit transaction and wait for result
|
||||
stxn_response = submit_and_wait(finish_txn, client, sender_wallet)
|
||||
|
||||
# Parse response and return result
|
||||
stxn_result = stxn_response.result
|
||||
|
||||
# Parse result and print out the transaction result and transaction hash
|
||||
print(stxn_result["meta"]["TransactionResult"])
|
||||
print(stxn_result["hash"])
|
||||
```
|
||||
{% code-snippet file="/_code-samples/escrow/py/finish_escrow.py" language="py" from="# Build escrow finish" /%}
|
||||
{% /tab %}
|
||||
|
||||
{% /tabs %}
|
||||
@@ -237,7 +161,7 @@ Take note of the transaction's identifying `hash` value so you can check its fin
|
||||
|
||||
## 7. Wait for validation
|
||||
|
||||
{% partial file="/docs/_snippets/wait-for-validation.md" /%}
|
||||
{% raw-partial file="/docs/_snippets/wait-for-validation.md" /%}
|
||||
|
||||
## 8. Confirm final result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user