IPC is used instead of RPC, new API of web3py 4.0.0b9 is used to build a transaction to invoke the contract methods
This commit is contained in:
parent
aabeb9385c
commit
6dddac7d6b
|
@ -17,8 +17,8 @@ bridge_config = load('/home/koal/parity/bridge/erc20.toml')
|
|||
bridge_db = load('/home/koal/parity/bridge/erc20_db.toml')
|
||||
|
||||
_IPC_file = bridge_config['home']['ipc']
|
||||
#web3 = Web3(Web3.IPCProvider(_IPC_file))
|
||||
web3 = Web3(Web3.HTTPProvider("http://127.0.0.1:38545"))
|
||||
web3 = Web3(Web3.IPCProvider(_IPC_file))
|
||||
#web3 = Web3(Web3.HTTPProvider("http://127.0.0.1:38545"))
|
||||
|
||||
_gasPrice = bridge_config['transactions']['withdraw_relay']['gas_price']
|
||||
|
||||
|
@ -37,9 +37,7 @@ tx = {'from': actor, 'to': bridgeContractAddress, 'value': value ,'gasPrice': _g
|
|||
|
||||
print("Sending", value, "to Home bridge")
|
||||
|
||||
web3.personal.unlockAccount(actor, "11", "0x5")
|
||||
|
||||
txHash = web3.eth.sendTransaction(tx)
|
||||
txHash = web3.personal.sendTransaction(tx, "11")
|
||||
wait_for_transaction_receipt(web3, txHash)
|
||||
|
||||
print("TX:", txHash.hex())
|
||||
|
|
|
@ -19,9 +19,9 @@ except:
|
|||
bridge_config = load('/home/koal/parity/bridge/erc20.toml')
|
||||
bridge_db = load('/home/koal/parity/bridge/erc20_db.toml')
|
||||
|
||||
#_IPC_file = bridge_config['home']['ipc']
|
||||
#web3 = Web3(Web3.IPCProvider(_IPC_file))
|
||||
web3 = Web3(Web3.HTTPProvider("http://127.0.0.1:48545"))
|
||||
_IPC_file = bridge_config['foreign']['ipc']
|
||||
web3 = Web3(Web3.IPCProvider(_IPC_file))
|
||||
#web3 = Web3(Web3.HTTPProvider("http://127.0.0.1:48545"))
|
||||
|
||||
_gasPrice = bridge_config['transactions']['withdraw_confirm']['gas_price']
|
||||
|
||||
|
@ -52,14 +52,22 @@ ContractFactory = web3.eth.contract(
|
|||
|
||||
TokenContract = ContractFactory(tokenContractAddress)
|
||||
|
||||
balance = TokenContract.call().balanceOf(actor)
|
||||
balance = TokenContract.functions.balanceOf(actor).call()
|
||||
value = randint(balance // 4, balance // 2)
|
||||
|
||||
print("Sending", value, "to Home bridge")
|
||||
|
||||
web3.personal.unlockAccount(actor, "11", "0x5")
|
||||
#web3.personal.unlockAccount(actor, "11", "0x5")
|
||||
|
||||
txHash = TokenContract.transact({'from': actor, 'gasPrice': _gasPrice}).approveAndCall(bridgeContractAddress, value, b'')
|
||||
txTmpl = {'from': actor,
|
||||
'gasPrice': _gasPrice}
|
||||
|
||||
txToSend = TokenContract.functions.approveAndCall(bridgeContractAddress, value, b'').buildTransaction(txTmpl)
|
||||
|
||||
# This is needed since sendTransaction does not expect this argument parameter and does not skip it by some reason
|
||||
txToSend.pop('chainId', None)
|
||||
|
||||
txHash = web3.personal.sendTransaction(txToSend, "11")
|
||||
wait_for_transaction_receipt(web3, txHash)
|
||||
|
||||
print("TX:", txHash.hex())
|
||||
|
|
Loading…
Reference in New Issue