Skip to content

Commit

Permalink
add marginx to marginx ibc transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
zakir-code committed Oct 12, 2023
1 parent fe320db commit f60ba71
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions fxsdk/client/crosschain.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,10 @@ def ibc_transfer(self, tx_builder: TxBuilder, to_address: str, amount: Coin, cha
return self.build_tx(tx_builder=tx_builder, msgs=[msg])
else:
return self.build_and_broadcast_tx(tx_builder=tx_builder, msgs=[msg], mode=mode)

def ibc_transfer_mx2mx(self, tx_builder: TxBuilder, amount: Coin, from_channel: str, to_channel: str,
mode: Optional[BroadcastMode] = BROADCAST_MODE_UNSPECIFIED):
address = tx_builder.from_address()
to_address = "{}|transfer/{}:{}".format(address.to_string("fx"), to_channel, address.to_string())
self.ibc_transfer(tx_builder=tx_builder, to_address=to_address, amount=amount, channel=from_channel,
target=CrossChainTarget.MarginX, mode=mode)
14 changes: 14 additions & 0 deletions tests/test_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ def test_ibc_transfer_mx2eth(self):
print(tx_response)
self.assertEqual(tx_response.code, 0)

def test_ibc_transfer_mx2mx(self):
grpc_cli = CrossChainClient(grpc_url)
channels = grpc_cli.query_channels()
if len(channels) == 0:
print("no channel found")
return
from_channel = channels[0].channel_id
to_channel = "channel-6"
amount = Coin(denom='FX', amount='100')
tx_response = grpc_cli.ibc_transfer_mx2mx(tx_builder=tx_builder, amount=amount, from_channel=from_channel,
to_channel=to_channel, mode=BROADCAST_MODE_SYNC)
print(tx_response)
self.assertEqual(tx_response.code, 0)


if __name__ == '__main__':
unittest.main()

0 comments on commit f60ba71

Please sign in to comment.