diff --git a/poetry.lock b/poetry.lock index 3699a184..c7bd975a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1293,20 +1293,20 @@ files = [ [[package]] name = "xrpl-py" -version = "1.9.0b1" +version = "2.1.0b0" description = "A complete Python library for interacting with the XRP ledger" optional = false python-versions = ">=3.7,<4.0" files = [ - {file = "xrpl_py-1.9.0b1-py3-none-any.whl", hash = "sha256:34b991368920138448349086033d7760d3a416add7f2153a9c9cf0541a04ef84"}, - {file = "xrpl_py-1.9.0b1.tar.gz", hash = "sha256:f8f813fb8673028d4c1f7ade057130254d333422ebfc9715e1fa9fb9fd68a8b0"}, + {file = "xrpl_py-2.1.0b0-py3-none-any.whl", hash = "sha256:e3c680d02401f49081da55eac24972ada4e252b5b9e50645d43a6a2091a36c31"}, + {file = "xrpl_py-2.1.0b0.tar.gz", hash = "sha256:1b91b0e4ad67caacc996b6b4fcadde0b767996d40aff597c70785221c4661ed5"}, ] [package.dependencies] base58 = ">=2.1.0,<3.0.0" Deprecated = ">=1.2.13,<2.0.0" ECPy = ">=1.2.5,<2.0.0" -httpx = ">=0.18.1,<0.24.0" +httpx = ">=0.18.1,<0.25.0" pycryptodome = ">=3.16.0,<4.0.0" types-Deprecated = ">=1.2.9,<2.0.0" typing-extensions = ">=4.2.0,<5.0.0" @@ -1333,4 +1333,4 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools" [metadata] lock-version = "2.0" python-versions = "^3.7.1" -content-hash = "aa77cf2f2e5959925d4eb06daa70989b5afb2564c959403e5b386eb3874dbcd0" +content-hash = "2f1d130701b2ba788442f84864281c7d8b20b6d8f210188fff5814c0445fc256" diff --git a/pyproject.toml b/pyproject.toml index 6c9c7dc6..2b409520 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] diff --git a/scripts/start.sh b/scripts/start.sh index 32deecb9..7f28d451 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -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 diff --git a/tests/bridge/test_build.py b/tests/bridge/test_build.py index 8df17a6d..4c1bdbee 100644 --- a/tests/bridge/test_build.py +++ b/tests/bridge/test_build.py @@ -127,6 +127,8 @@ def test_bridge_prod_build_xrp(self): "--fund-locking", "--funding-seed", "snoPBrXtMeMyMHUVTgbuqAfg1SUTb", + "--funding-algorithm", + "secp256k1", "--verbose", ], ) diff --git a/xbridge_cli/bridge/build.py b/xbridge_cli/bridge/build.py index 2138b812..4b6c8186 100644 --- a/xbridge_cli/bridge/build.py +++ b/xbridge_cli/bridge/build.py @@ -16,7 +16,7 @@ AccountObjects, AccountObjectType, AccountSet, - AccountSetFlag, + AccountSetAsfFlag, Currency, IssuedCurrency, Payment, @@ -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 @@ -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." @@ -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( @@ -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) ) ################################################################################### @@ -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 @@ -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 @@ -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 diff --git a/xbridge_cli/bridge/create_account.py b/xbridge_cli/bridge/create_account.py index 8634198a..6b1a630d 100644 --- a/xbridge_cli/bridge/create_account.py +++ b/xbridge_cli/bridge/create_account.py @@ -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( diff --git a/xbridge_cli/bridge/transfer.py b/xbridge_cli/bridge/transfer.py index 92f40482..a1c0b1e0 100644 --- a/xbridge_cli/bridge/transfer.py +++ b/xbridge_cli/bridge/transfer.py @@ -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 @@ -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( @@ -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") diff --git a/xbridge_cli/misc/fund.py b/xbridge_cli/misc/fund.py index cb168986..d29ceb23 100644 --- a/xbridge_cli/misc/fund.py +++ b/xbridge_cli/misc/fund.py @@ -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 @@ -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( diff --git a/xbridge_cli/misc/trust.py b/xbridge_cli/misc/trust.py index a2fdf02d..34ee4ec4 100644 --- a/xbridge_cli/misc/trust.py +++ b/xbridge_cli/misc/trust.py @@ -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, diff --git a/xbridge_cli/server/config/config.py b/xbridge_cli/server/config/config.py index b9e746e5..6d551729 100644 --- a/xbridge_cli/server/config/config.py +++ b/xbridge_cli/server/config/config.py @@ -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 @@ -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( @@ -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" @@ -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 @@ -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, diff --git a/xbridge_cli/utils/transaction.py b/xbridge_cli/utils/transaction.py index 1d3d71f3..da9543fb 100644 --- a/xbridge_cli/utils/transaction.py +++ b/xbridge_cli/utils/transaction.py @@ -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 @@ -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"])