Skip to content

Commit

Permalink
Merge branch 'main' into large-runner
Browse files Browse the repository at this point in the history
  • Loading branch information
mvadari authored Oct 25, 2023
2 parents b71b9aa + 6d0acd9 commit 95164b5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Throw an error if a transaction fails instead of continuing
- Support door accounts with multiple bridges

### Changed

Expand Down
2 changes: 0 additions & 2 deletions tests/bridge/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def test_register(self):
send_wallet.seed,
"--to",
wallet_to_create.classic_address,
"--verbose",
],
)
assert runner_result.exit_code == 0, runner_result.output
Expand Down Expand Up @@ -155,7 +154,6 @@ def test_register_bootstrap(self):
send_wallet.seed,
"--to",
wallet_to_create.classic_address,
"--verbose",
],
)
assert runner_result.exit_code == 0, runner_result.output
Expand Down
16 changes: 8 additions & 8 deletions xbridge_cli/bridge/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ def setup_bridge(
raise XBridgeCLIException(obj_error)
locking_door_objs = locking_objs_result["account_objects"]
if len(locking_door_objs) > 0:
assert (
len(locking_door_objs) == 1
), "Cannot have multiple bridges on one account"
if XChainBridge.from_xrpl(locking_door_objs[0]["XChainBridge"]) == bridge_obj:
if any(
XChainBridge.from_xrpl(obj["XChainBridge"]) == bridge_obj
for obj in locking_door_objs
):
locking_bridge_exists = True
else:
raise XBridgeCLIException(
Expand Down Expand Up @@ -457,10 +457,10 @@ def setup_bridge(
raise XBridgeCLIException(obj_error)
issuing_door_objs = issuing_objs_result["account_objects"]
if len(issuing_door_objs) > 0:
assert (
len(issuing_door_objs) == 1
), "Cannot have multiple bridges on one account"
if XChainBridge.from_xrpl(issuing_door_objs[0]["XChainBridge"]) == bridge_obj:
if any(
XChainBridge.from_xrpl(obj["XChainBridge"]) == bridge_obj
for obj in issuing_door_objs
):
issuing_bridge_exists = True
else:
raise XBridgeCLIException(
Expand Down
29 changes: 22 additions & 7 deletions xbridge_cli/bridge/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ def _get_account_objects(
return cast(List[Dict[str, Any]], object_result.result["account_objects"])


# TODO: add support for door accounts that have multiple bridges
def _get_bridge(client: JsonRpcClient, door_account: str) -> Dict[str, Any]:
# TODO: filter by bridge when that's implemented
objects = _get_account_objects(client, door_account)
bridge_objects = [obj for obj in objects if obj["LedgerEntryType"] == "Bridge"]
def _get_bridge(
client: JsonRpcClient, door_account: str, currency: str
) -> Dict[str, Any]:
objects = _get_account_objects(client, door_account, AccountObjectType.BRIDGE)
bridge_objects = [
obj
for obj in objects
if obj["XChainBridge"]["LockingChainIssue"]["currency"] == currency
]
assert len(bridge_objects) == 1
return bridge_objects[0]

Expand Down Expand Up @@ -87,6 +91,14 @@ def _get_bootstrap_chain_and_door(chain_json: Dict[str, Any]) -> Tuple[str, str]
"issuing_chain_door)."
),
)
@click.option(
"--currency",
type=str,
default="XRP",
help=(
"The currency that is being transferred across the bridge. The default is XRP."
),
)
@click.option(
"-v",
"--verbose",
Expand All @@ -98,6 +110,7 @@ def register_bridge(
chains: Optional[Tuple[str, str]],
doors: Optional[Tuple[str, str]],
bootstrap: Optional[str],
currency: str = "XRP",
verbose: int = 0,
) -> None:
"""
Expand All @@ -108,6 +121,8 @@ def register_bridge(
name: The name of the bridge (only used locally).
chains: The locking chain and issuing chain.
doors: The locking chain door and issuing chain door.
currency: The currency that is being transferred across the bridge. The default
is XRP.
bootstrap: The bootstrap file.
verbose: Whether or not to print more verbose information.
Expand Down Expand Up @@ -154,8 +169,8 @@ def register_bridge(
quorum = signer_list1["SignerQuorum"]

# TODO: determine whether the bridge was set up properly.
bridge1 = _get_bridge(locking_client, doors[0])
bridge2 = _get_bridge(issuing_client, doors[1])
bridge1 = _get_bridge(locking_client, doors[0], currency)
bridge2 = _get_bridge(issuing_client, doors[1], currency)
assert bridge1["XChainBridge"] == bridge2["XChainBridge"]
assert bridge1["XChainAccountCreateCount"] == bridge2["XChainAccountClaimCount"]
assert bridge2["XChainAccountCreateCount"] == bridge1["XChainAccountClaimCount"]
Expand Down

0 comments on commit 95164b5

Please sign in to comment.