Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update xrpl-dev-portal to use xrpl-py 2.0 #1933

Merged
merged 19 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from xrpl.core import keypairs
from xrpl.utils import xrp_to_drops
from xrpl.models.transactions import Payment
from xrpl.transaction import safe_sign_transaction
from xrpl.transaction import sign
from xrpl.wallet.main import Wallet


def create_wallet(silent: False):
Expand Down Expand Up @@ -63,24 +64,23 @@ def sign_transaction(xrp_amount, destination, ledger_seq, wallet_seq, password):
seed = crypt.decrypt(seed)

print("4. Initializing wallet using decrypted private key")
_wallet = wallet.Wallet(seed=seed.decode(), sequence=0)
_wallet = Wallet.from_seed(seed=seed.decode())

validated_seq = ledger_seq
_wallet.sequence = wallet_seq

print("5. Constructing payment transaction...")
my_tx_payment = Payment(
account=_wallet.classic_address,
account=_wallet.address,
amount=xrp_to_drops(xrp=xrp_amount),
destination=destination,
last_ledger_sequence=validated_seq + 100,
# +100 to catch up with the ledger when we transmit the signed tx blob to Machine 2
sequence=_wallet.sequence,
sequence=wallet_seq,
fee="10"
)

print("6. Signing transaction...")
my_tx_payment_signed = safe_sign_transaction(transaction=my_tx_payment, wallet=_wallet)
my_tx_payment_signed = sign(transaction=my_tx_payment, wallet=_wallet)

img = qrcode.make(my_tx_payment_signed.to_dict())

Expand Down
13 changes: 6 additions & 7 deletions content/_code-samples/airgapped-wallet/py/airgapped-wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from cryptography.fernet import Fernet
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from xrpl import wallet
from xrpl.wallet import Wallet
from xrpl.core import keypairs
from xrpl.utils import xrp_to_drops
from xrpl.models.transactions import Payment
from xrpl.transaction import safe_sign_transaction
from xrpl.transaction import sign


def create_wallet():
Expand Down Expand Up @@ -58,25 +58,24 @@ def sign_transaction(_xrp_amount, _destination, _ledger_seq, _wallet_seq, passwo

# Decrypts the wallet's private key
_seed = crypt.decrypt(_seed)
_wallet = wallet.Wallet(seed=_seed.decode(), sequence=0)
_wallet = Wallet.from_seed(seed=_seed.decode())

validated_seq = _ledger_seq
_wallet.sequence = _wallet_seq

# Construct Payment transaction
my_tx_payment = Payment(
account=_wallet.classic_address,
account=_wallet.address,
amount=xrp_to_drops(xrp=_xrp_amount),
destination=_destination,
last_ledger_sequence=validated_seq + 100,
# +100 to catch up with the ledger when we transmit the signed tx blob to Machine 2
sequence=_wallet.sequence,
sequence=_wallet_seq,
fee="10"
)

# Signs transaction and displays the signed_tx blob in QR code
# Scan the QR code and transmit the signed_tx blob to an online machine (Machine 2) to relay it to the XRPL
my_tx_payment_signed = safe_sign_transaction(transaction=my_tx_payment, wallet=_wallet)
my_tx_payment_signed = sign(transaction=my_tx_payment, wallet=_wallet)

img = qrcode.make(my_tx_payment_signed.to_dict())
img.save(get_path("/Wallet/transactionID.png"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from xrpl.clients import JsonRpcClient
from xrpl.models.transactions import Payment
from xrpl.transaction import send_reliable_submission
from xrpl.transaction import submit_and_wait


def connect_node(_node):
Expand All @@ -27,7 +27,7 @@ def send_transaction(transaction_dict):
# Since we manually inserted the tx blob, we need to initialize it into a Payment so xrpl-py could process it
my_tx_signed = Payment.from_dict(transaction_dict)

tx = send_reliable_submission(transaction=my_tx_signed, client=client)
tx = submit_and_wait(transaction=my_tx_signed, client=client)

tx_hash = tx.result['hash']
tx_destination = tx.result['Destination']
Expand Down
7 changes: 3 additions & 4 deletions content/_code-samples/airgapped-wallet/py/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Django==3.2.19
ECPy==1.2.5
h11==0.12.0
httpcore==0.13.6
httpx==0.23.0
idna==3.2
image==1.5.33
pifacedigitalio==3.0.5
Expand All @@ -21,6 +20,6 @@ rfc3986==1.5.0
six==1.16.0
sniffio==1.2.0
sqlparse==0.4.4
typing-extensions==3.10.0.0
websockets==9.1
xrpl-py==1.1.1
typing-extensions==4.2.0
websockets==10.0
xrpl-py==2.0.0
4 changes: 2 additions & 2 deletions content/_code-samples/build-a-wallet/py/3_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ def prompt_for_account(self):
try:
# Check if it's a valid seed
seed_bytes, alg = xrpl.core.addresscodec.decode_seed(value)
wallet = xrpl.wallet.Wallet(seed=value, sequence=0)
wallet = xrpl.wallet.Wallet.from_seed(seed=value)
x_address = wallet.get_xaddress(is_test=self.test_network)
classic_address = wallet.classic_address
classic_address = wallet.address
except Exception as e:
print(e)
exit(1)
Expand Down
4 changes: 2 additions & 2 deletions content/_code-samples/build-a-wallet/py/4_tx_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ def prompt_for_account(self):
try:
# Check if it's a valid seed
seed_bytes, alg = xrpl.core.addresscodec.decode_seed(value)
wallet = xrpl.wallet.Wallet(seed=value, sequence=0)
wallet = xrpl.wallet.Wallet.from_seed(seed=value)
x_address = wallet.get_xaddress(is_test=self.test_network)
classic_address = wallet.classic_address
classic_address = wallet.address
except Exception as e:
print(e)
exit(1)
Expand Down
10 changes: 5 additions & 5 deletions content/_code-samples/build-a-wallet/py/5_send_xrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ async def send_xrp(self, paydata):
# Autofill provides a sequence number, but this may fail if you try to
# send too many transactions too fast. You can send transactions more
# rapidly if you track the sequence number more carefully.
tx_signed = await xrpl.asyncio.transaction.safe_sign_and_autofill_transaction(
tx, self.wallet, self.client)
await xrpl.asyncio.transaction.submit_transaction(tx_signed, self.client)
tx_signed = await xrpl.asyncio.transaction.autofill_and_sign(
tx, self.client, self.wallet)
await xrpl.asyncio.transaction.submit(tx_signed, self.client)
wx.CallAfter(self.gui.add_pending_tx, tx_signed)


Expand Down Expand Up @@ -380,9 +380,9 @@ def prompt_for_account(self):
try:
# Check if it's a valid seed
seed_bytes, alg = xrpl.core.addresscodec.decode_seed(value)
wallet = xrpl.wallet.Wallet(seed=value, sequence=0)
wallet = xrpl.wallet.Wallet.from_seed(seed=value)
x_address = wallet.get_xaddress(is_test=self.test_network)
classic_address = wallet.classic_address
classic_address = wallet.address
except Exception as e:
print(e)
exit(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ async def send_xrp(self, paydata):
# Autofill provides a sequence number, but this may fail if you try to
# send too many transactions too fast. You can send transactions more
# rapidly if you track the sequence number more carefully.
tx_signed = await xrpl.asyncio.transaction.safe_sign_and_autofill_transaction(
tx, self.wallet, self.client)
await xrpl.asyncio.transaction.submit_transaction(tx_signed, self.client)
tx_signed = await xrpl.asyncio.transaction.autofill_and_sign(
tx, self.client, self.wallet)
await xrpl.asyncio.transaction.submit(tx_signed, self.client)
wx.CallAfter(self.gui.add_pending_tx, tx_signed)


Expand Down Expand Up @@ -541,9 +541,9 @@ def prompt_for_account(self):
try:
# Check if it's a valid seed
seed_bytes, alg = xrpl.core.addresscodec.decode_seed(value)
wallet = xrpl.wallet.Wallet(seed=value, sequence=0)
wallet = xrpl.wallet.Wallet.from_seed(seed=value)
x_address = wallet.get_xaddress(is_test=self.test_network)
classic_address = wallet.classic_address
classic_address = wallet.address
except Exception as e:
print(e)
exit(1)
Expand Down
10 changes: 5 additions & 5 deletions content/_code-samples/build-a-wallet/py/7_owned_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ async def send_xrp(self, paydata):
# Autofill provides a sequence number, but this may fail if you try to
# send too many transactions too fast. You can send transactions more
# rapidly if you track the sequence number more carefully.
tx_signed = await xrpl.asyncio.transaction.safe_sign_and_autofill_transaction(
tx, self.wallet, self.client)
await xrpl.asyncio.transaction.submit_transaction(tx_signed, self.client)
tx_signed = await xrpl.asyncio.transaction.autofill_and_sign(
tx, self.client, self.wallet)
await xrpl.asyncio.transaction.submit(tx_signed, self.client)
wx.CallAfter(self.gui.add_pending_tx, tx_signed)


Expand Down Expand Up @@ -588,9 +588,9 @@ def prompt_for_account(self):
try:
# Check if it's a valid seed
seed_bytes, alg = xrpl.core.addresscodec.decode_seed(value)
wallet = xrpl.wallet.Wallet(seed=value, sequence=0)
wallet = xrpl.wallet.Wallet.from_seed(seed=value)
x_address = wallet.get_xaddress(is_test=self.test_network)
classic_address = wallet.classic_address
classic_address = wallet.address
except Exception as e:
print(e)
exit(1)
Expand Down
12 changes: 6 additions & 6 deletions content/_code-samples/build-a-wallet/py/8_regular_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async def set_regular_key(self, wallet):
))
if response.is_successful():
print("set regular key: got account")
if response.result["account_data"].get("RegularKey") == wallet.classic_address:
if response.result["account_data"].get("RegularKey") == wallet.address:
print("set regular key: regular key matches")
self.wallet = wallet
wx.CallAfter(self.gui.enable_readwrite)
Expand Down Expand Up @@ -220,9 +220,9 @@ async def send_xrp(self, paydata):
# Autofill provides a sequence number, but this may fail if you try to
# send too many transactions too fast. You can send transactions more
# rapidly if you track the sequence number more carefully.
tx_signed = await xrpl.asyncio.transaction.safe_sign_and_autofill_transaction(
tx, self.wallet, self.client)
await xrpl.asyncio.transaction.submit_transaction(tx_signed, self.client)
tx_signed = await xrpl.asyncio.transaction.autofill_and_sign(
tx, self.client, self.wallet)
await xrpl.asyncio.transaction.submit(tx_signed, self.client)
wx.CallAfter(self.gui.add_pending_tx, tx_signed)


Expand Down Expand Up @@ -638,9 +638,9 @@ def prompt_for_account(self, for_regular_key=False):
try:
# Check if it's a valid seed
seed_bytes, alg = xrpl.core.addresscodec.decode_seed(value)
wallet = xrpl.wallet.Wallet(seed=value, sequence=0)
wallet = xrpl.wallet.Wallet.from_seed(seed=value)
x_address = wallet.get_xaddress(is_test=self.test_network)
classic_address = wallet.classic_address
classic_address = wallet.address
except Exception as e:
print(e)
exit(1)
Expand Down
4 changes: 2 additions & 2 deletions content/_code-samples/build-a-wallet/py/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
xrpl-py==1.3.0
wxPython==4.1.1
xrpl-py==2.0.0
wxPython==4.2.1
toml==0.10.2
requests==2.25.1
10 changes: 4 additions & 6 deletions content/_code-samples/checks/py/cancel_check.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from xrpl.wallet import Wallet, generate_faucet_wallet
from xrpl.wallet import generate_faucet_wallet
from xrpl.clients import JsonRpcClient
from xrpl.models import CheckCancel
from xrpl.transaction import (safe_sign_and_autofill_transaction,
send_reliable_submission)
from xrpl.transaction import submit_and_wait

client = JsonRpcClient("https://s.altnet.rippletest.net:51234") # Connect to the testnetwork

Expand All @@ -17,11 +16,10 @@
sender_wallet = generate_faucet_wallet(client=client)

# Build check cancel transaction
check_txn = CheckCancel(account=sender_wallet.classic_address, check_id=check_id)
check_txn = CheckCancel(account=sender_wallet.address, check_id=check_id)

# Sign and submit transaction
stxn = safe_sign_and_autofill_transaction(check_txn, sender_wallet, client)
stxn_response = send_reliable_submission(stxn, client)
stxn_response = submit_and_wait(check_txn, client, sender_wallet)

# Parse response for result
stxn_result = stxn_response.result
Expand Down
26 changes: 10 additions & 16 deletions content/_code-samples/checks/py/cash_check.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from xrpl.clients import JsonRpcClient
from xrpl.models import CheckCash, IssuedCurrencyAmount
from xrpl.transaction import (safe_sign_and_autofill_transaction,
send_reliable_submission)
from xrpl.utils import str_to_hex, xrp_to_drops
from xrpl.transaction import submit_and_wait
from xrpl.utils import xrp_to_drops
from xrpl.wallet import generate_faucet_wallet

# Connect to a network
Expand All @@ -21,13 +20,11 @@
sender_wallet = generate_faucet_wallet(client=client)

# Build check cash transaction
check_txn = CheckCash(account=sender_wallet.classic_address, check_id=check_id, amount=xrp_to_drops(amount))
check_txn = CheckCash(account=sender_wallet.address, check_id=check_id, amount=xrp_to_drops(amount))

# Sign transaction
stxn = safe_sign_and_autofill_transaction(check_txn, sender_wallet, client)
# Autofill, sign, then submit transaction and wait for result
stxn_response = submit_and_wait(check_txn, client, sender_wallet)

# Submit transaction and wait for result
stxn_response = send_reliable_submission(stxn, client)

# Parse response for result
stxn_result = stxn_response.result
Expand All @@ -49,22 +46,19 @@
amount = 10.00

# Token issuer address
issuer = generate_faucet_wallet(client=client).classic_address
issuer = generate_faucet_wallet(client=client).address

# Create sender wallet object
sender_wallet = generate_faucet_wallet(client=client)

# Build check cash transaction
check_txn = CheckCash(account=sender_wallet.classic_address, check_id=check_id, amount=IssuedCurrencyAmount(
currency=str_to_hex(token),
check_txn = CheckCash(account=sender_wallet.address, check_id=check_id, amount=IssuedCurrencyAmount(
currency=token,
issuer=issuer,
value=amount))

# Sign transaction
stxn = safe_sign_and_autofill_transaction(check_txn, sender_wallet, client)

# Submit transaction and wait for result
stxn_response = send_reliable_submission(stxn, client)
# Autofill, sign, then submit transaction and wait for result
stxn_response = submit_and_wait(check_txn, client, sender_wallet)

# Parse response for result
stxn_result = stxn_response.result
Expand Down
37 changes: 17 additions & 20 deletions content/_code-samples/checks/py/create_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

from xrpl.clients import JsonRpcClient
from xrpl.models import CheckCreate, IssuedCurrencyAmount
from xrpl.transaction import (safe_sign_and_autofill_transaction,
send_reliable_submission)
from xrpl.utils import datetime_to_ripple_time, str_to_hex, xrp_to_drops
from xrpl.transaction import submit_and_wait
from xrpl.utils import datetime_to_ripple_time, xrp_to_drops
from xrpl.wallet import generate_faucet_wallet

client = JsonRpcClient("https://s.altnet.rippletest.net:51234") # Connect to the testnetwork
Expand All @@ -26,16 +25,15 @@
sender_wallet = generate_faucet_wallet(client=client)

# Build check create transaction
check_txn = CheckCreate(account=sender_wallet.classic_address, destination=receiver_addr,
send_max=IssuedCurrencyAmount(
currency=str_to_hex(token),
issuer=issuer,
value=amount),
expiration=expiry_date)
check_txn = CheckCreate(account=sender_wallet.address, destination=check_receiver_addr,
send_max=IssuedCurrencyAmount(
currency=token_name,
issuer=token_issuer,
value=amount_to_deliver),
expiration=expiry_date)

# Sign, submit transaction and wait for result
stxn = safe_sign_and_autofill_transaction(check_txn, sender_wallet, client)
stxn_response = send_reliable_submission(stxn, client)
# Autofill, sign, then submit transaction and wait for result
stxn_response = submit_and_wait(check_txn, client, sender_wallet)

# Parse response for result
stxn_result = stxn_response.result
Expand All @@ -61,14 +59,13 @@
sender_wallet = generate_faucet_wallet(client=client)

# Build check create transaction
check_txn = CheckCreate(account=sender_wallet.classic_address,
destination=receiver_addr,
send_max=xrp_to_drops(amount),
expiration=expiry_date)

# Sign, submit transaction and wait for result
stxn = safe_sign_and_autofill_transaction(check_txn, sender_wallet, client)
stxn_response = send_reliable_submission(stxn, client)
check_txn = CheckCreate(account=sender_wallet.address,
destination=check_receiver_addr,
send_max=xrp_to_drops(amount_to_deliver),
expiration=expiry_date)

# Autofill, sign, then submit transaction and wait for result
stxn_response = submit_and_wait(check_txn, client, sender_wallet)

# Parse response for result
stxn_result = stxn_response.result
Expand Down
Loading
Loading