def temporary_transact(tx, host, dapp):

    if host == "http://47.254.66.11:26657":
        from py_nsbcli import Client, Admin
        from hexbytes import HexBytes
        admin = Admin()
        admin.set_rpc_host(host)
        cli = Client(admin)

        if tx['trans_type'] == "invoke":
            from contract.tendermint.option.contract import Option
            opt = Option(cli)
            opt.buy_option(tom, 5, bytes.fromhex(tx['dst'][2:]))
        else:
            from py_nsbcli.system_token import SystemToken
            token_cli = SystemToken(cli)
            print(token_cli.transfer(alice, HexBytes(tx['dst']), tx['fund']))
    else:
        print(dapp.__dict__, host)
        dapp.unlockself(host)
        tx_json = JsonRPC.eth_send_transaction(tx)
        print(tx)
        resp = JsonRPC.send(tx_json, HTTP_HEADER, host)['result']
        get_tx = JsonRPC.eth_get_transaction_receipt(resp)
        while True:
            response = JsonRPC.send(get_tx, HTTP_HEADER, host)
            if response['result'] is None:
                print("Exec...")
                time.sleep(1)
                continue
            else:
                print(response)
                break
def temporary_transact(tx, host):
    if host == "http://47.251.2.73:26657":
        from py_nsbcli import Client, Admin
        from py_nsbcli.system_token import SystemToken
        from hexbytes import HexBytes
        admin = Admin()
        admin.set_rpc_host(host)
        cli = Client(admin)
        token_cli = SystemToken(cli)

        print(token_cli.transfer(alice, HexBytes(tx['dst']), tx['fund']))
    else:
        tx_json = JsonRPC.eth_send_transaction(tx)
        print(tx)
        resp = JsonRPC.send(tx_json, HTTP_HEADER, host)['result']
        get_tx = JsonRPC.eth_get_transaction_receipt(resp)
        while True:
            response = JsonRPC.send(get_tx, HTTP_HEADER, host)
            if response['result'] is None:
                print("Exec...")
                time.sleep(1)
                continue
            else:
                print(response)
                break
Exemple #3
0
 def lazy_function(tx_resp: str, wait_time=25, query_period=1):
     tx_resp_json = JsonRPC.eth_get_transaction_receipt(tx_resp)
     expire_time = wait_time + time.time()
     while time.time() < expire_time:
         try:
             resp = JsonRPC.send(tx_resp_json, rpc_host=host)
             if resp['result'] is not None:
                 return resp
             time.sleep(query_period)
         except Exception:
             raise
Exemple #4
0
    def make_contract(owners, signature, rlped_txs, tx_count, ves, bytescode=None, bin_dir=isc_bin_dir):
        try:
            rlped_txs = HexBytes(rlped_txs)
            encoded_data = AbiEncoder.encodes(
                [
                    owners,
                    [0, 0, 0],
                    HexBytes(ETHSIGN_HEADER + bytes(str(len(rlped_txs)).encode(ENC)) + bytes(rlped_txs)).hex(),
                    signature,
                    keccak(ETHSIGN_HEADER + b'\x36\x35' + HexBytes(signature)),
                    tx_count
                ],
                ['address[]', 'uint256[]', 'bytes', 'bytes', 'bytes32', 'uint256']
            )
            if bytescode is None:
                bytescode = FileLoad.getbytecode(bin_dir)

            ves.unlockself()
            tx_json = JsonRPC.eth_send_transaction({
                'from': ves.address,
                'data': bytescode.decode(ENC) + encoded_data,
                'gas': hex(8000000)
            })
            # print(tx_json)
            response = JsonRPC.send(tx_json, rpc_host=ves.chain_host)
            rp_json = JsonRPC.eth_get_transaction_receipt(response['result'])
        except Exception as e:
            isc_log.debug('ISCBulidError: {}'.format(str(e)))
            raise e
        while True:
            try:

                response = JsonRPC.send(rp_json, rpc_host=ves.chain_host)
                if response['result'] is None:
                    console_logger.info("Contract is deploying, please stand by")
                    time.sleep(2)
                    continue
                console_logger.info("got Transaction_result {}".format(response['result']))

                block_number = response['result']['blockNumber']
                contract_addr = response['result']['contractAddress']

                cd_json = JsonRPC.eth_get_code(contract_addr, block_number)
                response = JsonRPC.send(cd_json, rpc_host=ves.chain_host)
                if response['result'] == '0x':
                    raise IndexError("Contract deployment failed")

                return contract_addr
            except Exception as e:
                isc_log.debug('ISCBulidError: {exec}'.format(exec=str(e)), extra={"addr": ""})
                raise e
Exemple #5
0
    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)
Exemple #6
0
def temporary_transact(tx, host):

    if host == "http://47.251.2.73:26657":
        from py_nsbcli import Client, Admin
        admin = Admin()
        admin.set_rpc_host(host)
        cli = Client(admin)
        from contract.tendermint.delegate.contract import DelegateContract
        opt = DelegateContract(cli)
        print(opt.vote(tom, bytes.fromhex(tx['dst'][2:])))
    else:
        tx_json = JsonRPC.eth_send_transaction(tx)
        print(tx)
        resp = JsonRPC.send(tx_json, HTTP_HEADER, host)['result']
        get_tx = JsonRPC.eth_get_transaction_receipt(resp)
        while True:
            response = JsonRPC.send(get_tx, HTTP_HEADER, host)
            print("result", response)
            break