示例#1
0
 async def init(self, founder: Account, payer: Account, gas_price: int,
                gas_limit: int):
     tx = self.new_init_tx(payer.get_address(), gas_price, gas_limit)
     tx.sign_transaction(founder)
     if founder.get_address_bytes() != payer.get_address_bytes():
         tx.add_sign_transaction(payer)
     tx_hash = await self._sdk.default_aio_network.send_raw_transaction(tx)
     return tx_hash
 def revoke(self, claim_id: str, issuer: Account, payer: Account,
            gas_price: int, gas_limit: int):
     tx = self.new_revoke_tx(claim_id, issuer.get_address(),
                             payer.get_address(), gas_price, gas_limit)
     tx.sign_transaction(issuer)
     if issuer.get_address_bytes() != payer.get_address_bytes():
         tx.add_sign_transaction(payer)
     tx_hash = self._sdk.default_network.send_raw_transaction(tx)
     return tx_hash
示例#3
0
 def init(self, founder: Account, payer: Account, gas_price: int,
          gas_limit: int):
     """
     Contract owner can use this interface to activate oep-4 token.
     """
     tx = self.new_init_tx(payer.get_address(), gas_price, gas_limit)
     tx.sign_transaction(founder)
     if founder.get_address_bytes() != payer.get_address_bytes():
         tx.add_sign_transaction(payer)
     tx_hash = self._sdk.default_network.send_raw_transaction(tx)
     return tx_hash
示例#4
0
 def transfer(self, from_acct: Account, to_address: Union[str, Address],
              amount: int, payer: Account, gas_price: int, gas_limit: int):
     """
     This interface is used to send a transfer transaction that only for ONT or ONG.
     """
     tx = self.new_transfer_tx(from_acct.get_address(), to_address, amount,
                               payer.get_address(), gas_price, gas_limit)
     tx.sign_transaction(from_acct)
     if from_acct.get_address_bytes() != payer.get_address_bytes():
         tx.add_sign_transaction(payer)
     return self._sdk.default_network.send_raw_transaction(tx)
示例#5
0
 async def transfer(self, from_acct: Account,
                    to_address: Union[str, Address], amount: int,
                    payer: Account, gas_price: int, gas_limit: int) -> str:
     """
     This interface is used to transfer amount of tokens to to_address asynchronously.
     """
     tx = self.new_transfer_tx(from_acct.get_address(), to_address, amount,
                               payer.get_address(), gas_price, gas_limit)
     tx.sign_transaction(from_acct)
     if from_acct.get_address_bytes() != payer.get_address_bytes():
         tx.add_sign_transaction(payer)
     tx_hash = await self._sdk.default_aio_network.send_raw_transaction(tx)
     return tx_hash
示例#6
0
 async def transfer_from(self, spender: Account, owner: Union[str, bytes,
                                                              Address],
                         to_address: Union[str, bytes, Address], value: int,
                         payer: Account, gas_price: int,
                         gas_limit: int) -> str:
     tx = self.new_transfer_from_tx(spender.get_address(),
                                    owner, to_address, value,
                                    payer.get_address(), gas_price,
                                    gas_limit)
     tx.sign_transaction(spender)
     if spender.get_address_bytes() != payer.get_address_bytes():
         tx.add_sign_transaction(payer)
     tx_hash = await self._sdk.default_aio_network.send_raw_transaction(tx)
     return tx_hash
示例#7
0
 async def approve(self, owner: Account,
                   spender: Union[str, bytes, Address], amount: int,
                   payer: Account, gas_price: int, gas_limit: int) -> str:
     """
     This interface is used to allow 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.
     """
     tx = self.new_approve_tx(owner.get_address(), spender, amount,
                              payer.get_address(), gas_price, gas_limit)
     tx.sign_transaction(owner)
     if owner.get_address_bytes() != payer.get_address_bytes():
         tx.add_sign_transaction(payer)
     tx_hash = await self._sdk.default_aio_network.send_raw_transaction(tx)
     return tx_hash
示例#8
0
 def transfer_from(self, spender: Account, owner: Union[str, bytes,
                                                        Address],
                   to_address: Union[str, bytes, Address], value: int,
                   payer: Account, gas_price: int, gas_limit: int) -> str:
     """
     Transfers value amount of tokens from address owner to address to_address, and MUST fire the Transfer event.
     """
     tx = self.new_transfer_from_tx(spender.get_address(),
                                    owner, to_address, value,
                                    payer.get_address(), gas_price,
                                    gas_limit)
     tx.sign_transaction(spender)
     if spender.get_address_bytes() != payer.get_address_bytes():
         tx.add_sign_transaction(payer)
     tx_hash = self._sdk.default_network.send_raw_transaction(tx)
     return tx_hash
示例#9
0
 async def approve(self, approver: Account, spender: Union[str, Address],
                   amount: int, payer: Account, gas_price: int,
                   gas_limit: int) -> str:
     """
     This is an interface used to send an approve transaction
     which allow receiver to spend a amount of ONT or ONG asset in sender's account.
     """
     if amount <= 0:
         raise SDKException(
             ErrorCode.other_error(
                 'the amount should be greater than than zero.'))
     tx = self.new_approve_tx(approver.get_address(), spender, amount,
                              payer.get_address(), gas_price, gas_limit)
     tx.sign_transaction(approver)
     if approver.get_address_bytes() != payer.get_address_bytes():
         tx.add_sign_transaction(payer)
     return await self._sdk.default_aio_network.send_raw_transaction(tx)
示例#10
0
 def transfer_from(self, spender: Account, from_address: Union[str,
                                                               Address],
                   receiver: Union[str, Address], amount: int,
                   payer: Account, gas_price: int, gas_limit: int) -> str:
     """
     This interface is used to generate a Transaction object for transfer that  allow one account to
     transfer a amount of ONT or ONG Asset to another account, in the condition of the first account had approved.
     """
     if amount <= 0:
         raise SDKException(
             ErrorCode.other_error(
                 'the amount should be greater than than zero.'))
     tx = self.new_transfer_from_tx(spender.get_address(),
                                    from_address, receiver, amount,
                                    payer.get_address(), gas_price,
                                    gas_limit)
     tx.sign_transaction(spender)
     if spender.get_address_bytes() != payer.get_address_bytes():
         tx.add_sign_transaction(payer)
     return self._sdk.default_network.send_raw_transaction(tx)
示例#11
0
 async def add_public_key(self,
                          ont_id: str,
                          operator: Account,
                          hex_new_public_key: str,
                          payer: Account,
                          gas_price: int,
                          gas_limit: int,
                          is_recovery: bool = False):
     """
     This interface is used to send a Transaction object which is used to add public key.
     """
     if not isinstance(operator, Account) or not isinstance(payer, Account):
         raise SDKException(ErrorCode.require_acct_params)
     if is_recovery:
         bytes_operator = operator.get_address_bytes()
     else:
         bytes_operator = operator.get_public_key_bytes()
     b58_payer_address = payer.get_address_base58()
     tx = self.new_add_public_key_tx(ont_id, bytes_operator,
                                     hex_new_public_key, b58_payer_address,
                                     gas_price, gas_limit, is_recovery)
     tx.sign_transaction(operator)
     tx.add_sign_transaction(payer)
     return await self._sdk.default_aio_network.send_raw_transaction(tx)