Beispiel #1
0
 def lazy_function():
     sig = ContractFunction.check_sig(function_sign)
     return JsonRPC.send(JsonRPC.eth_send_transaction(
         dict(tx,
              data=sig +
              AbiEncoder.encodes(function_args, function_args_type))),
                         rpc_host=host)['result']
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
Beispiel #4
0
 def lazy_function(transaction=None):
     if transaction is None:
         transaction = {}
     return JsonRPC.send(JsonRPC.eth_send_transaction(
         dict(transaction,
              data=function_sign +
              AbiEncoder.encodes(function_args, function_args_type))),
                         rpc_host=host)['result']
Beispiel #5
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
Beispiel #6
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)
Beispiel #7
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
Beispiel #8
0
    print(ves.nsb.is_active_isc(isc.address))

    user_table = [(dapp_x, ves), (dapp_y, ves)]

    unlock_table = [enc_info_x, enc_info_relay_y]

    session_id = int(session_content[0])

    from uiputils.ethtools import AbiEncoder
    import random
    testnumber = random.randint(0, 100)
    tx = JsonRPC.eth_send_transaction({
        'from':
        dapp_x.info['http://127.0.0.1:8545']['address'],
        'to':
        "0x7c7b26fa65e091f7b9f23db77ad5f714f1dae5ea",
        "data":
        "0x67eb4a3c" + AbiEncoder.encodes([testnumber], ['uint']),
        "gas":
        hex(7999999)
    })
    dapp_x.unlockself('http://127.0.0.1:8545')
    console_logger.info('genuineValue set: {0}\n response: {1}'.format(
        testnumber, JsonRPC.send(tx, HTTP_HEADER, 'http://127.0.0.1:8545')))

    for idx, [u, v] in enumerate(user_table):
        # assert tx_intent is on ISC

        # Part_A # inited ##############################################################################################

        # compute on_chain_tx
        tx = tx_intents.intents[idx].jsonize()
Beispiel #9
0
        print(tx)
        atte = u.init_attestation(tx, StateType.inited,
                                  int(session_content[0]), 0)
        # update

        # relay
        atte_rec = v.receive(atte.encode())
        rlped_data = v.sign_attestation(atte_rec)
        # update

        # check
        u.receive(rlped_data)

        # open
        unlock_user(tx['from'])
        tx_json = JsonRPC.eth_send_transaction(tx)
        print(
            JsonRPC.send(tx_json, HTTP_HEADER,
                         tx_intents.intents[idx].chain_host))
        # verify_transaction_state?
        atte = u.init_attestation(tx, StateType.open, int(session_content[0]),
                                  0)

        #
        v.receive(atte.encode())
        atte = v.init_attestation(tx, StateType.opened,
                                  int(session_content[0]), 0)

        # ves check
        ves.receive(atte.encode())
        # close