Exemple #1
0
 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
Exemple #2
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
Exemple #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
Exemple #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)
Exemple #5
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
Exemple #6
0
 def approve(self, owner: Account, spender: Union[str, bytes, Address], amount: int, payer: Account, gas_price: int,
             gas_limit: int) -> str:
     """
     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.
     """
     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 = self._sdk.default_network.send_raw_transaction(tx)
     return tx_hash
Exemple #7
0
 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 synchronously.
     """
     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 = self._sdk.default_network.send_raw_transaction(tx)
     return tx_hash
Exemple #8
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
Exemple #9
0
 def withdraw(self, claimer: Account, receiver: Union[str,
                                                      Address], amount: int,
              payer: Account, gas_price: int, gas_limit: int) -> str:
     """
     This interface is used to withdraw a amount of ong and transfer them to receive address.
     """
     if amount <= 0:
         raise SDKException(
             ErrorCode.other_error(
                 'the amount should be greater than than zero.'))
     tx = self.new_withdraw_tx(claimer.get_address(), receiver, amount,
                               payer.get_address(), gas_price, gas_limit)
     tx.sign_transaction(claimer)
     if claimer.get_address_bytes() != payer.get_address_bytes():
         tx.add_sign_transaction(payer)
     return self._sdk.default_network.send_raw_transaction(tx)
Exemple #10
0
    def revoke_public_key(self, ont_id: str, operator: Account, revoked_pub_key: str, payer: Account,
                          gas_limit: int, gas_price: int, is_recovery: bool = False):
        """
        This interface is used to send a Transaction object which is used to remove public key.

        :param ont_id: OntId.
        :param operator: an Account object which indicate who will sign for the transaction.
        :param hex_remove_public_key: a hexadecimal public key string which will be removed.
        :param payer: an Account object which indicate who will 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.
        :param is_recovery: indicate whether ctrl account is a recovery account.
        :return: a hexadecimal transaction hash value.
        """
        if not isinstance(operator, Account) or not isinstance(payer, Account):
            raise SDKException(ErrorCode.require_acct_params)
        b58_payer_address = payer.get_address_base58()
        if is_recovery:
            bytes_operator = operator.get_address_bytes()
        else:
            bytes_operator = operator.get_public_key_bytes()
        tx = self.new_revoke_public_key_transaction(ont_id, bytes_operator, revoked_pub_key, b58_payer_address,
                                                    gas_limit, gas_price)
        tx.sign_transaction(operator)
        tx.add_sign_transaction(payer)
        return self.__sdk.get_network().send_raw_transaction(tx)
Exemple #11
0
 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 self._sdk.default_network.send_raw_transaction(tx)
Exemple #12
0
 def make_transfer(self, contract_address: str, new_admin_ont_id: str, key_no: str, payer: Account, gas_limit: str,
                   gas_price: str):
     param = {"contract_address": a2b_hex(contract_address.encode()),
              'new_admin_ont_id': new_admin_ont_id.encode('utf-8'), 'key_no': key_no}
     invoke_code = build_native_invoke_code(bytearray.fromhex(self.contract_address), b'\x00', "transfer", param)
     unix_time_now = int(time())
     tx = Transaction(0, 0xd1, unix_time_now, gas_price, gas_limit, payer.get_address_bytes(), invoke_code,
                      bytearray(), [])
     return tx
Exemple #13
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)
 def revoke(self, claim_id: str, issuer_acct: Account, payer_acct: Account,
            gas_limit: int, gas_price: int):
     if gas_limit < 0:
         raise SDKException(ErrorCode.other_error('Gas limit less than 0.'))
     if gas_price < 0:
         raise SDKException(ErrorCode.other_error('Gas price less than 0.'))
     func = InvokeFunction('Revoke')
     func.set_params_value(claim_id, issuer_acct.get_address_bytes())
     tx_hash = self.__sdk.get_network().send_neo_vm_transaction(
         self.__hex_contract_address, issuer_acct, payer_acct, gas_limit,
         gas_price, func, False)
     return tx_hash
Exemple #15
0
 def revoke_public_key(self, ont_id: str, operator: Account, revoked_pub_key: str, payer: Account,
                       gas_limit: int, gas_price: int, is_recovery: bool = False):
     """
     This interface is used to send a Transaction object which is used to remove public key.
     """
     if not isinstance(operator, Account) or not isinstance(payer, Account):
         raise SDKException(ErrorCode.require_acct_params)
     b58_payer_address = payer.get_address_base58()
     if is_recovery:
         bytes_operator = operator.get_address_bytes()
     else:
         bytes_operator = operator.get_public_key_bytes()
     tx = self.new_revoke_public_key_tx(ont_id, bytes_operator, revoked_pub_key, b58_payer_address, gas_limit,
                                        gas_price)
     tx.sign_transaction(operator)
     tx.add_sign_transaction(payer)
     return self._sdk.default_network.send_raw_transaction(tx)