Beispiel #1
0
 def new_transfer_tx(self, from_address: Union[str, Address], to_address: Union[str, Address], amount: int,
                     payer: Union[str, Address], gas_price: int, gas_limit: int) -> InvokeTransaction:
     """
     This interface is used to generate a transaction which can transfer amount of tokens to to_address.
     """
     func = InvokeFunction('transfer')
     func.set_params_value(Address.b58decode(from_address), Address.b58decode(to_address), amount)
     params = InvokeTransaction.generate_invoke_code(self._contract_address, func)
     tx = InvokeTransaction(payer, gas_price, gas_limit, params)
     return tx
Beispiel #2
0
 def new_approve_tx(self, owner: Union[str, bytes, Address], spender: Union[str, bytes, Address], amount: int,
                    payer: Union[str, bytes, Address], gas_price: int, gas_limit: int) -> InvokeTransaction:
     """
     This interface is used to generate a transaction which allows spender to
     withdraw from owner account multiple times, up to the _value amount.
     If this function is called again it overwrites the current allowance with amount value.
     """
     if not isinstance(amount, int):
         raise SDKException(ErrorCode.param_err('the data type of amount should be int.'))
     if amount < 0:
         raise SDKException(ErrorCode.param_err('the amount should be equal or great than 0.'))
     func = InvokeFunction('approve')
     func.set_params_value(Address.b58decode(owner), Address.b58decode(spender), amount)
     params = InvokeTransaction.generate_invoke_code(self._contract_address, func)
     tx = InvokeTransaction(payer, gas_price, gas_limit, params)
     return tx
Beispiel #3
0
 def new_transfer_multi_tx(self, transfer_list: list, payer: Union[str, bytes, Address], gas_price: int,
                           gas_limit: int) -> InvokeTransaction:
     """
     This interface is used to generate a transaction which can
     transfer amount of token from from-account to to-account multiple times.
     """
     func = InvokeFunction('transferMulti')
     for index, item in enumerate(transfer_list):
         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.'))
         transfer_list[index] = [Address.b58decode(item[0]), Address.b58decode(item[1]), item[2]]
     for item in transfer_list:
         func.add_params_value(item)
     params = InvokeTransaction.generate_invoke_code(self._contract_address, func)
     tx = InvokeTransaction(payer, gas_price, gas_limit, params)
     return tx