Пример #1
0
 def test_oep4_balance_of(self):
     hex_contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
     func = InvokeFunction('balanceOf')
     self.assertEqual(bytearray(b'\x00\xc1\tbalanceOf'),
                      func.create_invoke_code())
     bytes_address = acct1.get_address().to_bytes()
     func.set_params_value(bytes_address)
     target = bytearray(
         b'\x14F\xb1\xa1\x8a\xf6\xb7\xc9\xf8\xa4`/\x9fs\xee\xb3\x03\x0f\x0c)\xb7Q\xc1\tbalanceOf'
     )
     self.assertEqual(target, func.create_invoke_code())
     result = sdk.rpc.send_neo_vm_transaction_pre_exec(
         hex_contract_address, None, func)
     balance = result['Result']
     balance = ContractDataParser.to_int(balance)
     self.assertGreater(balance, 100)
Пример #2
0
 def test_oep4_symbol(self):
     hex_contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
     func = InvokeFunction('symbol')
     self.assertEqual(bytearray(b'\x00\xc1\x06symbol'),
                      func.create_invoke_code())
     result = sdk.rpc.send_neo_vm_transaction_pre_exec(
         hex_contract_address, None, func)
     symbol = result['Result']
     symbol = ContractDataParser.to_utf8_str(symbol)
     self.assertEqual('DX', symbol)
Пример #3
0
 def test_oep4_name(self):
     hex_contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
     func = InvokeFunction('name')
     self.assertEqual(bytearray(b'\x00\xc1\x04name'),
                      func.create_invoke_code())
     result = sdk.rpc.send_neo_vm_transaction_pre_exec(
         hex_contract_address, None, func)
     name = result['Result']
     name = ContractDataParser.to_utf8_str(name)
     self.assertEqual('DXToken', name)
Пример #4
0
    def transfer_multi(self, transfer_list: list, payer_acct: Account,
                       signers: list, gas_limit: int, gas_price: int):
        """
        This interface is used to call the TransferMulti method in ope4
        that allow transfer amount of token from multiple from-account to multiple to-account multiple times.

        :param transfer_list: a parameter list with each item contains three sub-items:
                base58 encode transaction sender address,
                base58 encode transaction receiver address,
                amount of token in transaction.
        :param payer_acct: an Account class that used to pay for the transaction.
        :param signers: a signer list used to sign this transaction which should contained all sender in args.
        :param gas_limit: an int value that indicate the gas limit.
        :param gas_price: an int value that indicate the gas price.
        :return: the hexadecimal transaction hash value.
        """
        func = InvokeFunction('transferMulti')
        for index, item in enumerate(transfer_list):
            Oep4.__b58_address_check(item[0])
            Oep4.__b58_address_check(item[1])
            if not isinstance(item[2], int):
                raise SDKException(
                    ErrorCode.param_err(
                        'the data type of value should be int.'))
            if item[2] < 0:
                raise SDKException(
                    ErrorCode.param_err(
                        'the value should be equal or great than 0.'))
            from_address_array = Address.b58decode(item[0]).to_bytes()
            to_address_array = Address.b58decode(item[1]).to_bytes()
            transfer_list[index] = [
                from_address_array, to_address_array, item[2]
            ]
        for item in transfer_list:
            func.add_params_value(item)
        params = func.create_invoke_code()
        unix_time_now = int(time.time())
        params.append(0x67)
        bytearray_contract_address = bytearray.fromhex(
            self.__hex_contract_address)
        bytearray_contract_address.reverse()
        for i in bytearray_contract_address:
            params.append(i)
        if len(signers) == 0:
            raise SDKException(ErrorCode.param_err('payer account is None.'))
        payer_address = payer_acct.get_address().to_bytes()
        tx = Transaction(0, 0xd1, unix_time_now, gas_price, gas_limit,
                         payer_address, params, bytearray(), [])
        for signer in signers:
            tx.add_sign_transaction(signer)
        tx_hash = self.__sdk.get_network().send_raw_transaction(tx)
        return tx_hash
Пример #5
0
    def transfer_from(self, spender_acct: Account, b58_from_address: str,
                      b58_to_address: str, value: int, payer_acct: Account,
                      gas_limit: int, gas_price: int):
        """
        This interface is used to call the Allowance method in ope4
        that allow spender to withdraw amount of oep4 token from from-account to to-account.

        :param spender_acct: an Account class that actually spend oep4 token.
        :param b58_from_address: an base58 encode address that actually pay oep4 token for the spender's spending.
        :param b58_to_address: a base58 encode address that receive the oep4 token.
        :param value: the amount of ope4 token in this transaction.
        :param payer_acct: an Account class that used to pay for the transaction.
        :param gas_limit: an int value that indicate the gas limit.
        :param gas_price: an int value that indicate the gas price.
        :return: the hexadecimal transaction hash value.
        """
        func = InvokeFunction('transferFrom')
        Oep4.__b58_address_check(b58_from_address)
        Oep4.__b58_address_check(b58_to_address)
        if not isinstance(spender_acct, Account):
            raise SDKException(
                ErrorCode.param_err(
                    'the data type of spender_acct should be Account.'))
        spender_address_array = spender_acct.get_address().to_bytes()
        from_address_array = Address.b58decode(b58_from_address).to_bytes()
        to_address_array = Address.b58decode(b58_to_address).to_bytes()
        if not isinstance(value, int):
            raise SDKException(
                ErrorCode.param_err('the data type of value should be int.'))
        func.set_params_value(spender_address_array, from_address_array,
                              to_address_array, value)
        params = func.create_invoke_code()
        unix_time_now = int(time.time())
        params.append(0x67)
        bytearray_contract_address = bytearray.fromhex(
            self.__hex_contract_address)
        bytearray_contract_address.reverse()
        for i in bytearray_contract_address:
            params.append(i)
        if payer_acct is None:
            raise SDKException(ErrorCode.param_err('payer account is None.'))
        payer_address_array = payer_acct.get_address().to_bytes()
        tx = Transaction(0, 0xd1, unix_time_now, gas_price, gas_limit,
                         payer_address_array, params, bytearray(), [])

        tx.sign_transaction(spender_acct)
        if spender_acct.get_address_base58() != payer_acct.get_address_base58(
        ):
            tx.add_sign_transaction(payer_acct)
        tx_hash = self.__sdk.get_network().send_raw_transaction(tx)
        return tx_hash