Skip to content

Commit a5541b5

Browse files
committed
✨ added bridge functionalities
1 parent fad4e20 commit a5541b5

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 0.1.36.3
4+
- Added `bridge` and `bridge_withdraw` commands
5+
36
## 0.1.36.2
47
- Fixed a problem with the garbage collector causing memory leaks
58

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "communex"
3-
version = "0.1.36.2"
3+
version = "0.1.36.3"
44
description = "A library for Commune network focused on simplicity"
55
authors = ["agicommies <[email protected]>"]
66
license = "MIT"

src/communex/cli/balance.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,45 @@ def transfer_dao_funds(
297297

298298
client = context.com_client()
299299
client.add_transfer_dao_treasury_proposal(keypair, cid, nano_amount, dest)
300+
301+
302+
@balance_app.command()
303+
def bridge(
304+
ctx: Context,
305+
key: str,
306+
amount: float,
307+
):
308+
context = make_custom_context(ctx)
309+
client = context.com_client()
310+
311+
nano_amount = to_nano(amount)
312+
keypair = context.load_key(key, None)
313+
314+
with context.progress_status(f"Bridging {amount} tokens..."):
315+
try:
316+
client.bridge(keypair, nano_amount)
317+
except Exception as e:
318+
context.error(f"Failed to bridge {amount} tokens: {e}")
319+
else:
320+
context.info(f"Bridged {amount}$j successfully")
321+
322+
323+
@balance_app.command()
324+
def bridge_withdraw(
325+
ctx: Context,
326+
key: str,
327+
amount: float,
328+
):
329+
context = make_custom_context(ctx)
330+
client = context.com_client()
331+
332+
nano_amount = to_nano(amount)
333+
keypair = context.load_key(key, None)
334+
335+
with context.progress_status(f"Withdrawing {amount} tokens..."):
336+
try:
337+
client.bridge_withdraw(keypair, nano_amount)
338+
except Exception as e:
339+
context.error(f"Failed to withdraw {amount} tokens: {e}")
340+
else:
341+
context.info(f"Withdrew {amount}$j successfully")

src/communex/client.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,58 @@ def transfer_stake(
15061506

15071507
return response
15081508

1509+
def bridge(
1510+
self,
1511+
key: Keypair,
1512+
amount: int,
1513+
):
1514+
"""
1515+
Bridge tokens from the Subspace network to the Torus network.
1516+
1517+
Args:
1518+
key: The keypair associated with the account that is bridging the tokens.
1519+
amount: The amount of tokens to bridge, in nanotokens.
1520+
1521+
Returns:
1522+
A receipt of the bridging transaction.
1523+
1524+
Raises:
1525+
InsufficientBalanceError: If the account does not have enough balance.
1526+
ChainTransactionError: If the transaction fails.
1527+
"""
1528+
1529+
params = {"amount": amount}
1530+
1531+
response = self.compose_call("bridge", key=key, params=params)
1532+
1533+
return response
1534+
1535+
def bridge_withdraw(
1536+
self,
1537+
key: Keypair,
1538+
amount: int,
1539+
):
1540+
"""
1541+
Withdraw bridged tokens from the Torus network to the Subspace network.
1542+
1543+
Args:
1544+
key: The keypair associated with the account that is withdrawing the tokens.
1545+
amount: The amount of tokens to withdraw, in nanotokens.
1546+
1547+
Returns:
1548+
A receipt of the withdrawal transaction.
1549+
1550+
Raises:
1551+
InsufficientBalanceError: If the account does not have enough balance.
1552+
ChainTransactionError: If the transaction fails.
1553+
"""
1554+
1555+
params = {"amount": amount}
1556+
1557+
response = self.compose_call("bridge_withdraw", key=key, params=params)
1558+
1559+
return response
1560+
15091561
def multiunstake(
15101562
self,
15111563
key: Keypair,

0 commit comments

Comments
 (0)