def send(self, trans, passphrase=None): """ transact the contract_methods :param trans: transaction with contract invocation's information :param passphrase: :return: None """ if passphrase is None: passphrase = self.info[trans.chain_host] if trans.chain_type == 'Ethereum': unlock = JsonRPC.personal_unlock_account( self.info[trans.chain_host]['address'], passphrase, 20) tx_response = JsonRPC.send(unlock, HTTP_HEADER, trans.chain_host) print( json.dumps(tx_response, sort_keys=True, indent=4, separators=(', ', ': '))) packet_transaction = JsonRPC.eth_send_transaction(trans.jsonize()) tx_response = JsonRPC.send(packet_transaction, HTTP_HEADER, trans.chain_host) print( json.dumps(tx_response, sort_keys=True, indent=4, separators=(', ', ': '))) tx_hash = tx_response['result'] query = JsonRPC.eth_get_transaction_receipt(tx_hash) while True: tx_response = JsonRPC.send(query, HTTP_HEADER, trans.chain_host) if tx_response['result'] is None: print("transacting") time.sleep(2) continue break print( json.dumps(tx_response, sort_keys=True, indent=4, separators=(', ', ': '))) else: raise TypeError("unsupported chain-type: ", +trans.chain_type)
def unlockself(self, host_name=None): """ assuming self.address is on Ethereum :param host_name: :return: """ if host_name is None: host_name = self.default_domain host_info = self.info[host_name] if host_info['chain_type'] == 'Tendermint': return elif host_info['chain_type'] == 'Ethereum': unlock = JsonRPC.personal_unlock_account(host_info['address'], host_info['password'], 20) response = JsonRPC.send(unlock, HTTP_HEADER, host_info['host']) if not response['result']: raise ValueError("unlock failed. wrong password?") else: raise TypeError("unsupported chain-type: ", +host_info['chain_type'])
# ("0x076122c56613fc1e3ae97d715ca7cb6a35a934c6") nsb_abi_dir = "../nsb/nsb.abi" nsb_bytecode_dir = "../nsb/nsb.bin" nsb_db_dir = "../nsb/actiondata" tx = {"from": eth_base_addr, "gas": hex(400000)} if __name__ == '__main__': nsbt = EthNetStatusBlockchain(eth_base_addr, host_addr, nsb_addr, nsb_abi_dir, "", nsb_bytecode_dir=nsb_bytecode_dir) nsb = nsbt.handle unlock = JsonRPC.personal_unlock_account(eth_base_addr, "123456", 20) tx_response = JsonRPC.send(unlock, HTTP_HEADER, "http://127.0.0.1:8545") # 0x64e604787cbf194841e7b68d7cd28786f6c9a0a3ab9f8b0a0e87cb4387ab0107 # print(HexBytes(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00C').hex()) # = nsbt.addAction("123456781234567812345678123456781") # print(keccakhash) # print(nsbt.getAction("0xbc7e08dc633826033d13aaab04b8e2196cd944351ea0046dae500d4e027939e2")) # print(HexBytes(nsbt.getQueueL()).hex(), HexBytes(nsbt.getQueueR()).hex()) # nsbt.watchProofPool() # print(nsb_addr) #
def unlock_user(user): unlock = JsonRPC.personal_unlock_account(user['name'], user['passphrase'], 20) response = JsonRPC.send(unlock, HTTP_HEADER, user['domain']) if not response['result']: raise ValueError("unlock failed. wrong password?")
def unlockself(address, password, chain_host): unlock = JsonRPC.personal_unlock_account(address, password, 20) response = JsonRPC.send(unlock, HTTP_HEADER, chain_host) if not response['result']: raise ValueError("unlock failed. wrong password?")
def unlock_user(addr): unlock = JsonRPC.personal_unlock_account(addr, "123456", 20) response = JsonRPC.send(unlock, HTTP_HEADER, "http://127.0.0.1:8545") if not response['result']: raise ValueError("unlock failed. wrong password?")