From 9d95a46d54708ea4f632e29b52377c496398c4bc Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Sat, 27 Jul 2024 07:45:11 +0700 Subject: [PATCH] Update PolkadotBridgeContract.js --- .../polkadot/PolkadotBridgeContract.js | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/blockchain_integration/pi_network/pi-network-interoperability/bridge-contracts/polkadot/PolkadotBridgeContract.js b/blockchain_integration/pi_network/pi-network-interoperability/bridge-contracts/polkadot/PolkadotBridgeContract.js index 444f809f7..f8dd40cb2 100644 --- a/blockchain_integration/pi_network/pi-network-interoperability/bridge-contracts/polkadot/PolkadotBridgeContract.js +++ b/blockchain_integration/pi_network/pi-network-interoperability/bridge-contracts/polkadot/PolkadotBridgeContract.js @@ -12,26 +12,38 @@ class PolkadotBridgeContract { }); } - async bridgeToken(tokenAddress, recipientAddress, amount) { + async lockTokens(amount, tokenAddress) { const txCount = await this.web3.eth.getTransactionCount(this.polkadotBridgeContractAddress); const tx = { from: this.polkadotBridgeContractAddress, - to: tokenAddress, + to: this.polkadotBridgeContractAddress, value: amount, gas: '20000', gasPrice: '20', - nonce: txCount + nonce: txCount, + data: `0x${tokenAddress.toString(16)}` }; const signedTx = await this.ethersProvider.signTransaction(tx, '0x1234567890abcdef'); await this.ethersProvider.sendTransaction(signedTx); } - async getBalance(tokenAddress) { - return this.web3.eth.getBalance(tokenAddress); + async unlockTokens(amount, tokenAddress) { + const txCount = await this.web3.eth.getTransactionCount(this.polkadotBridgeContractAddress); + const tx = { + from: this.polkadotBridgeContractAddress, + to: this.polkadotBridgeContractAddress, + value: amount, + gas: '20000', + gasPrice: '20', + nonce: txCount, + data: `0x${tokenAddress.toString(16)}` + }; + const signedTx = await this.ethersProvider.signTransaction(tx, '0x1234567890abcdef'); + await this.ethersProvider.sendTransaction(signedTx); } - async getPolkadotBalance(address) { - return this.api.query.balances.freeBalance(address); + async getLockedTokens(tokenAddress) { + return this.api.query.bridge.lockedTokens(tokenAddress); } }