Skip to content

Commit

Permalink
Merge branch 'main' into model-type-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mvadari authored Sep 26, 2024
2 parents 786ad8d + 9e491cc commit 71b0a04
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 143 deletions.
105 changes: 0 additions & 105 deletions snippets/bridge_transfer.py

This file was deleted.

82 changes: 44 additions & 38 deletions snippets/paths.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,54 @@
"""Example of how to find the best path to trade with"""

from xrpl.clients import JsonRpcClient
from xrpl.models import XRP, IssuedCurrencyAmount, Payment, RipplePathFind
from xrpl.clients import WebsocketClient
from xrpl.models import IssuedCurrencyAmount, PathFind, Payment
from xrpl.models.requests import PathFindSubcommand
from xrpl.transaction import autofill_and_sign
from xrpl.wallet import generate_faucet_wallet

# References
# - https://xrpl.org/paths.html#paths
# - https://xrpl.org/ripple_path_find.html#ripple_path_find
# Prerequisites for this snippet. Please verify these conditions after a reset of the
# test network:
# - destination_account must have a trust line with the destination_amount.issuer
# - There must be appropriate DEX Offers or XRP/TST AMM for the cross-currency exchange

# Create a client to connect to the test network
client = JsonRpcClient("https://s.altnet.rippletest.net:51234")

# Creating wallet to send money from
wallet = generate_faucet_wallet(client, debug=True)

# Create account and amount variables for later transaction
destination_account = "rKT4JX4cCof6LcDYRz8o3rGRu7qxzZ2Zwj"
destination_amount = IssuedCurrencyAmount(
value="0.001",
currency="USD",
issuer="rVnYNK9yuxBz4uP8zC8LEFokM2nqH3poc",
)

# Create a RipplePathFind request and have the client call it
path_request = RipplePathFind(
source_account=wallet.address,
source_currencies=[XRP()],
destination_account=destination_account,
destination_amount=destination_amount,
)
path_response = client.request(path_request)
print(path_response)

# Extract out paths from the RipplePathFind response
paths = path_response.result["alternatives"][0]["paths_computed"]
print(paths)

# Create a Payment to send money from wallet to destination_account using path
payment_tx = Payment(
account=wallet.address,
amount=destination_amount,
destination=destination_account,
paths=paths,
)

print("signed: ", autofill_and_sign(payment_tx, client, wallet))
# PathFind RPC requires the use of a Websocket client only

with WebsocketClient("wss://s.altnet.rippletest.net:51233") as client:
# Creating wallet to send money from
wallet = generate_faucet_wallet(client, debug=True)

# Create account and amount variables for later transaction
destination_account = "rJPeZVPty1bXXbDR9oKscg2irqABr7sP3t"
destination_amount = IssuedCurrencyAmount(
value="0.001",
currency="TST",
issuer="rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd",
)

# Create a RipplePathFind request and have the client call it
path_request = PathFind(
subcommand=PathFindSubcommand.CREATE,
source_account=wallet.address,
destination_account=destination_account,
destination_amount=destination_amount,
)
path_response = client.request(path_request)
print(path_response)

# Extract out paths from the RipplePathFind response
paths = path_response.result["alternatives"][0]["paths_computed"]
print(paths)

# Create a Payment to send money from wallet to destination_account using path
payment_tx = Payment(
account=wallet.address,
amount=destination_amount,
destination=destination_account,
paths=paths,
)

print("signed: ", autofill_and_sign(payment_tx, client, wallet))

0 comments on commit 71b0a04

Please sign in to comment.