Skip to content

Commit

Permalink
chore: update to xrpl-py 2.0 (#155)
Browse files Browse the repository at this point in the history
## High Level Overview of Change

Title says it all.

### Context of Change

New major version of xrpl-py

### Type of Change

- [x] Refactor (non-breaking change that only restructures code)

## Test Plan

Tests pass locally.
  • Loading branch information
mvadari authored Jul 18, 2023
1 parent 823e1ca commit ab4ee27
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 74 deletions.
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ websockets = "^10.3"
Jinja2 = "^3.1.2"
psutil = "^5.9.2"
docker = "^6.0.0"
xrpl-py = "1.9.0b1"
xrpl-py = "2.1.0b0"
pycryptodome = "^3.17"

[tool.poetry.dev-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ xbridge-cli server start-all
xbridge-cli server list
xbridge-cli explorer
xbridge-cli bridge build --name=bridge --fund-locking
xbridge-cli fund locking_chain raFcdz1g8LWJDJWJE2ZKLRGdmUmsTyxaym
xbridge-cli bridge create-account --from-locking --bridge bridge --from snqs2zzXuMA71w9isKHPTrvFn1HaJ --to rJdTJRJZ6GXCCRaamHJgEqVzB7Zy4557Pi --amount 10
xbridge-cli bridge transfer --bridge bridge --from-locking --amount 10 --from snqs2zzXuMA71w9isKHPTrvFn1HaJ --to snyEJjY2Xi5Dxdh81Jy9Mj3AiYRQM
xbridge-cli fund locking_chain rHLrQ3SjzxmkoYgrZ5d4kgHRPF6MdMWpAV
xbridge-cli bridge create-account --from-locking --bridge bridge --from sEdTSHsMvrzomUN9uYgVEd64CEQqwo2 --to rHLrQ3SjzxmkoYgrZ5d4kgHRPF6MdMWpAV --amount 10
xbridge-cli bridge transfer --bridge bridge --from-locking --amount 10 --from sEdTSHsMvrzomUN9uYgVEd64CEQqwo2 --to sEdTSHsMvrzomUN9uYgVEd64CEQqwo2
2 changes: 2 additions & 0 deletions tests/bridge/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def test_bridge_prod_build_xrp(self):
"--fund-locking",
"--funding-seed",
"snoPBrXtMeMyMHUVTgbuqAfg1SUTb",
"--funding-algorithm",
"secp256k1",
"--verbose",
],
)
Expand Down
44 changes: 25 additions & 19 deletions xbridge_cli/bridge/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
AccountObjects,
AccountObjectType,
AccountSet,
AccountSetFlag,
AccountSetAsfFlag,
Currency,
IssuedCurrency,
Payment,
Expand All @@ -42,7 +42,7 @@

_GENESIS_ACCOUNT = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh"
_GENESIS_SEED = "snoPBrXtMeMyMHUVTgbuqAfg1SUTb"
_GENESIS_WALLET = Wallet(_GENESIS_SEED, 0)
_GENESIS_WALLET = Wallet.from_seed(_GENESIS_SEED, algorithm=CryptoAlgorithm.SECP256K1)

LSF_DISABLE_MASTER = 0x00100000

Expand All @@ -69,6 +69,7 @@
)
@click.option(
"--funding-seed",
"funding_seed",
help=(
"The master key of an account on the locking chain that can fund accounts on "
"the issuing chain. This is only needed for an XRP-XRP bridge."
Expand Down Expand Up @@ -207,19 +208,25 @@ def setup_bridge(
min_create1_rippled = str(min_create1) if min_create1 is not None else None
min_create2_rippled = str(min_create2) if min_create2 is not None else None

funding_wallet_algo = (
CryptoAlgorithm(funding_algorithm)
if funding_algorithm
else CryptoAlgorithm.ED25519
)
if funding_seed is None:
if is_xrp_bridge and funding_seed is None:
if close_ledgers:
funding_seed = "snoPBrXtMeMyMHUVTgbuqAfg1SUTb"
funding_seed = _GENESIS_SEED
funding_wallet_algo = CryptoAlgorithm.SECP256K1
else:
raise XBridgeCLIException(
"Must include `funding_seed` for external XRP-XRP bridge."
)
funding_wallet_algo = (
CryptoAlgorithm(funding_algorithm) if funding_algorithm else None
)

funding_wallet = (
Wallet(funding_seed, 0, algorithm=funding_wallet_algo) if funding_seed else None
Wallet.from_seed(funding_seed, algorithm=funding_wallet_algo)
if funding_seed
else None
)

accounts_locking_check = set(
Expand Down Expand Up @@ -281,13 +288,13 @@ def setup_bridge(

locking_door_seed = bootstrap_locking["DoorAccount"]["Seed"]
locking_door_seed_algo = bootstrap_locking["DoorAccount"]["KeyType"]
locking_door_wallet = Wallet(
locking_door_seed, 0, algorithm=CryptoAlgorithm(locking_door_seed_algo)
locking_door_wallet = Wallet.from_seed(
locking_door_seed, algorithm=CryptoAlgorithm(locking_door_seed_algo)
)
issuing_door_seed = bootstrap_issuing["DoorAccount"]["Seed"]
issuing_door_seed_algo = bootstrap_issuing["DoorAccount"]["KeyType"]
issuing_door_wallet = Wallet(
issuing_door_seed, 0, algorithm=CryptoAlgorithm(issuing_door_seed_algo)
issuing_door_wallet = Wallet.from_seed(
issuing_door_seed, algorithm=CryptoAlgorithm(issuing_door_seed_algo)
)

###################################################################################
Expand Down Expand Up @@ -383,7 +390,9 @@ def setup_bridge(
# disable the master key
if not locking_account_info["Flags"] & LSF_DISABLE_MASTER:
locking_txs.append(
AccountSet(account=locking_door, set_flag=AccountSetFlag.ASF_DISABLE_MASTER)
AccountSet(
account=locking_door, set_flag=AccountSetAsfFlag.ASF_DISABLE_MASTER
)
)

# submit transactions
Expand All @@ -400,12 +409,7 @@ def setup_bridge(

if is_xrp_bridge:
# we need to create the witness reward + submission accounts

assert funding_seed is not None # for typing purposes - checked earlier
funding_wallet_algo = (
CryptoAlgorithm(funding_algorithm) if funding_algorithm else None
)
funding_wallet = Wallet(funding_seed, 0, algorithm=funding_wallet_algo)
assert funding_wallet is not None # for typing purposes

# TODO: add param to customize amount
amount = str(min_create2 * 2) # submit accounts need spare funds
Expand Down Expand Up @@ -505,7 +509,9 @@ def setup_bridge(
# disable the master key
if not issuing_account_info["Flags"] & LSF_DISABLE_MASTER:
issuing_txs.append(
AccountSet(account=issuing_door, set_flag=AccountSetFlag.ASF_DISABLE_MASTER)
AccountSet(
account=issuing_door, set_flag=AccountSetAsfFlag.ASF_DISABLE_MASTER
)
)

# submit transactions
Expand Down
6 changes: 4 additions & 2 deletions xbridge_cli/bridge/create_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ def create_xchain_account(
)
create_amount = xrp_to_drops(amount)

wallet_algorithm = CryptoAlgorithm(algorithm) if algorithm else None
from_wallet = Wallet(from_seed, 0, algorithm=wallet_algorithm)
wallet_algorithm = (
CryptoAlgorithm(algorithm) if algorithm else CryptoAlgorithm.ED25519
)
from_wallet = Wallet.from_seed(from_seed, algorithm=wallet_algorithm)

# submit XChainAccountCreate tx
fund_tx = XChainAccountCreateCommit(
Expand Down
28 changes: 6 additions & 22 deletions xbridge_cli/bridge/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@

import click
from xrpl.clients import JsonRpcClient
from xrpl.models import (
XRP,
Currency,
IssuedCurrency,
Response,
Transaction,
Tx,
XChainCommit,
XChainCreateClaimID,
)
from xrpl.utils import xrp_to_drops
from xrpl.models import Response, Transaction, Tx, XChainCommit, XChainCreateClaimID
from xrpl.wallet import Wallet

from xbridge_cli.exceptions import XBridgeCLIException
Expand Down Expand Up @@ -175,24 +165,18 @@ def send_transfer(
"Must use `--no-close-ledgers` on a non-standalone node."
)

if isinstance(from_issue, IssuedCurrency):
original_issue: Currency = from_issue
else:
original_issue = XRP()
amount = int(xrp_to_drops(amount))

try:
from_wallet = Wallet(from_account, 0)
from_wallet = Wallet.from_seed(from_account)
except ValueError as error:
raise XBridgeCLIException(f"Invalid `from` seed: {from_account}") from error
try:
to_wallet = Wallet(to_account, 0)
to_wallet = Wallet.from_seed(to_account)
except ValueError as error:
raise XBridgeCLIException(f"Invalid `to` seed: {to_account}") from error

transfer_amount = original_issue.to_amount(amount) # type: ignore
transfer_amount = from_issue.to_amount(amount)

# XChainSeqNumCreate
# XChainCreateClaimID
if tutorial:
click.pause(
info=click.style(
Expand Down Expand Up @@ -224,7 +208,7 @@ def send_transfer(
assert len(claim_ids_ledger_entries) == 1, len(claim_ids_ledger_entries)
xchain_claim_id = claim_ids_ledger_entries[0]["NewFields"]["XChainClaimID"]

# XChainTransfer
# XChainCommit
if tutorial:
click.pause(
info=click.style("\nLocking the funds on the source chain...", fg="blue")
Expand Down
5 changes: 4 additions & 1 deletion xbridge_cli/misc/fund.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import List

import click
from xrpl import CryptoAlgorithm
from xrpl.models import AccountInfo, Payment, Transaction
from xrpl.utils import xrp_to_drops
from xrpl.wallet import Wallet
Expand Down Expand Up @@ -56,7 +57,9 @@ def fund_account(
chain_config = get_config().get_chain(chain)
client = chain_config.get_client()

wallet = Wallet("snoPBrXtMeMyMHUVTgbuqAfg1SUTb", 0)
wallet = Wallet.from_seed(
"snoPBrXtMeMyMHUVTgbuqAfg1SUTb", algorithm=CryptoAlgorithm.SECP256K1
)
payments: List[Transaction] = []
for account in accounts:
payments.append(
Expand Down
2 changes: 1 addition & 1 deletion xbridge_cli/misc/trust.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def set_trustline(

trust_sets: List[Transaction] = []
for account in accounts:
wallet = Wallet(account, 0)
wallet = Wallet.from_seed(account)
trust_sets.append(
TrustSet(
account=wallet.classic_address,
Expand Down
36 changes: 26 additions & 10 deletions xbridge_cli/server/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from xrpl import CryptoAlgorithm
from xrpl.wallet import Wallet

from xbridge_cli.exceptions import XBridgeCLIException
from xbridge_cli.server.config.ports import Ports
from xbridge_cli.utils import CryptoAlgorithmChoice, CurrencyDict

Expand Down Expand Up @@ -354,7 +355,7 @@ def generate_witness_config(
@click.option(
"--issuing-seed",
"issuing_seed",
default="snoPBrXtMeMyMHUVTgbuqAfg1SUTb",
default=_GENESIS_SEED,
help="The seed of the issuing chain door account. Defaults to the genesis account.",
)
@click.option(
Expand Down Expand Up @@ -435,8 +436,8 @@ def generate_bootstrap(
if issuing_algorithm
else CryptoAlgorithm.ED25519
)
locking_door = Wallet(locking_seed, 0, algorithm=locking_wallet_algo)
issuing_door = Wallet(issuing_seed, 0, algorithm=issuing_wallet_algo)
locking_door = Wallet.from_seed(locking_seed, algorithm=locking_wallet_algo)
issuing_door = Wallet.from_seed(issuing_seed, algorithm=issuing_wallet_algo)

assert (locking_currency == "XRP" and issuing_currency == "XRP") or (
locking_currency != "XRP" and issuing_currency != "XRP"
Expand Down Expand Up @@ -530,17 +531,22 @@ def generate_all_configs(
currency: The currency that is being transferred across the bridge.
is_docker: Whether the config files are for a docker setup.
verbose: Whether or not to print more verbose information.
Raises:
XBridgeCLIException: If something really weird goes wrong.
"""
# TODO: add support for external networks
abs_config_dir = os.path.abspath(config_dir)

locking_port, issuing_port = _generate_rippled_configs(abs_config_dir, is_docker)
locking_door = Wallet.create(crypto_algorithm=CryptoAlgorithm.SECP256K1)
locking_door = Wallet.create(algorithm=CryptoAlgorithm.SECP256K1)

if currency == "XRP":
locking_currency = "XRP"
issuing_currency = "XRP"
issuing_door = Wallet(_GENESIS_SEED, 0, algorithm=CryptoAlgorithm.SECP256K1)
issuing_door = Wallet.from_seed(
_GENESIS_SEED, algorithm=CryptoAlgorithm.SECP256K1
)
issuing_algorithm = "secp256k1"
else:
assert currency.count(".") == 1
Expand All @@ -553,13 +559,23 @@ def generate_all_configs(
reward_accounts = []
signing_accounts = []
for i in range(num_witnesses):
original_wallet = Wallet.create(crypto_algorithm=CryptoAlgorithm.SECP256K1)
witness_reward_wallet = Wallet(
original_wallet.seed, 0, algorithm=CryptoAlgorithm.ED25519
original_wallet = Wallet.create(algorithm=CryptoAlgorithm.SECP256K1)
if original_wallet.seed is None:
raise XBridgeCLIException(
"Something weird happened, the wallet should have a seed"
)
witness_reward_wallet = Wallet.from_seed(
original_wallet.seed, algorithm=CryptoAlgorithm.ED25519
)
reward_accounts.append(witness_reward_wallet.classic_address)
wallet = Wallet.create(CryptoAlgorithm.SECP256K1)
signing_wallet = Wallet(wallet.seed, 0, algorithm=CryptoAlgorithm.ED25519)
wallet = Wallet.create(algorithm=CryptoAlgorithm.SECP256K1)
if wallet.seed is None:
raise XBridgeCLIException(
"Something weird happened, the wallet should have a seed"
)
signing_wallet = Wallet.from_seed(
wallet.seed, algorithm=CryptoAlgorithm.ED25519
)
signing_accounts.append(signing_wallet.classic_address)
ctx.invoke(
generate_witness_config,
Expand Down
16 changes: 6 additions & 10 deletions xbridge_cli/utils/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
import click
from xrpl.clients.sync_client import SyncClient
from xrpl.models import GenericRequest, Response, Transaction
from xrpl.transaction import (
safe_sign_and_autofill_transaction,
send_reliable_submission,
submit_transaction,
)
from xrpl.transaction import autofill_and_sign, submit, submit_and_wait
from xrpl.wallet import Wallet


Expand Down Expand Up @@ -49,20 +45,20 @@ def submit_tx(
if close_ledgers:
results = []
for tx in txs:
signed_tx = safe_sign_and_autofill_transaction(tx, wallet, client)
results.append(submit_transaction(signed_tx, client))
signed_tx = autofill_and_sign(tx, client, wallet)
results.append(submit(signed_tx, client))
client.request(GenericRequest(method="ledger_accept"))
tx_results = [
result.result.get("error") or result.result.get("engine_result")
for result in results
]
else:
# TODO: improve runtime when there is a batch send_reliable_submission
# TODO: improve runtime when there is a batch submit_and_wait
results = []
tx_results = []
for tx in txs:
signed_tx = safe_sign_and_autofill_transaction(tx, wallet, client)
result = send_reliable_submission(signed_tx, client)
signed_tx = autofill_and_sign(tx, client, wallet)
result = submit_and_wait(signed_tx, client)
results.append(result)
tx_results.append(result.result["meta"]["TransactionResult"])

Expand Down

0 comments on commit ab4ee27

Please sign in to comment.