def claim(self, keypair, fee=DEFAULT_FEE, tx_ttl=DEFAULT_TX_TTL): """Claim name, if preclaim is missing on block, then a error is raised If preclaim block height is greater then or equal to current block, then you must wait for one block to claim claim a transaction and must not be included in preclaim block TTL Transaction must be signed, by name owner""" if self.preclaimed_block_height is None: raise MissingPreclaim('You must call preclaim before claiming a name') current_block_height = self.client.get_height() if self.preclaimed_block_height >= current_block_height: raise TooEarlyClaim( 'You must wait for one block to call claim.' 'Use `claim_blocking` if you have a lot of time on your hands' ) # compute the absolute ttl ttl = self.client.compute_absolute_ttl(tx_ttl) claim_transaction = self.client.cli.post_name_claim(body=dict( account=keypair.get_address(), name=AEName._encode_name(self.domain), name_salt=self.preclaim_salt, fee=fee, ttl=ttl )) signed_tx = self.client.post_transaction(keypair, claim_transaction) self.status = AEName.Status.CLAIMED return signed_tx.tx_hash, self.preclaim_salt
def claim(self, keypair, fee=1): if self.preclaimed_block_height is None: raise MissingPreclaim('You must call preclaim before claiming a name') current_block_height = self.client.get_height() if self.preclaimed_block_height >= current_block_height: raise TooEarlyClaim( 'You must wait for one block to call claim.' 'Use `claim_blocking` if you have a lot of time on your hands' ) claim_transaction = self.client.external_http_post( '/tx/name/claim', json=dict( account=keypair.get_address(), name=AEName._encode_name(self.domain), name_salt=self.preclaim_salt, fee=fee, ) ) signable_claim_tx = SignableTransaction(claim_transaction) signed_transaction, b58signature = keypair.sign_transaction(signable_claim_tx) self.client.send_signed_transaction(signed_transaction) self.status = AEName.Status.CLAIMED return claim_transaction['tx_hash'], self.preclaim_salt
def claim(self, account, name_salt, preclaim_tx_hash, fee=defaults.FEE, tx_ttl=defaults.TX_TTL): self.preclaim_salt = name_salt # get the preclaim height try: pre_claim_tx = self.client.get_transaction_by_hash( hash=preclaim_tx_hash) self.preclaimed_block_height = pre_claim_tx.block_height except OpenAPIClientException: raise MissingPreclaim( f"Preclaim transaction {preclaim_tx_hash} not found") # if the commitment_id mismatch pre_claim_commitment_id = pre_claim_tx.tx.commitment_id commitment_id, _ = hashing.commitment_id(self.domain, salt=name_salt) if pre_claim_commitment_id != commitment_id: raise NameCommitmentIdMismatch( f"Committment id mismatch, wanted {pre_claim_commitment_id} got {commitment_id}" ) # if the transaction has not been mined if self.preclaimed_block_height <= 0: raise NameTooEarlyClaim( f"The pre-claim transaction has not been mined yet") # get the current height current_height = self.client.get_current_key_block_height() safe_height = self.preclaimed_block_height + self.client.config.key_block_confirmation_num if current_height < safe_height: raise NameTooEarlyClaim( f"It is not safe to execute the name claim before height {safe_height}, current height: {current_height}" ) # name encode name name = hashing.name_id(self.domain) # get the transaction builder txb = self.client.tx_builder # get the account nonce and ttl nonce, ttl = self.client._get_nonce_ttl(account.get_address(), tx_ttl) # create transaction tx = txb.tx_name_claim(account.get_address(), name, self.preclaim_salt, fee, ttl, nonce) # sign the transaction tx_signed = self.client.sign_transaction(account, tx.tx) # post the transaction to the chain self.client.broadcast_transaction(tx_signed.tx, tx_signed.hash) # update status self.status = AEName.Status.CLAIMED return tx_signed
def claim(self, account, fee=DEFAULT_FEE, tx_ttl=DEFAULT_TX_TTL): if self.preclaimed_block_height is None: raise MissingPreclaim( 'You must call preclaim before claiming a name') # name encoded TODO: shall this goes into transactions? name = AEName._encode_name(self.domain) # get the transaction builder txb = TxBuilder(self.client, account) # create claim transaction tx, sg, tx_hash = txb.tx_name_claim(name, self.preclaim_salt, fee, tx_ttl) # post the transaction to the chain txb.post_transaction(tx, tx_hash) # ensure tx if self.client.blocking_mode: txb.wait_tx(tx_hash) # update status self.status = AEName.Status.CLAIMED return tx_hash
def claim(self, keypair, fee=DEFAULT_FEE, tx_ttl=DEFAULT_TX_TTL): if self.preclaimed_block_height is None: raise MissingPreclaim('You must call preclaim before claiming a name') current_block_height = self.client.get_height() if self.preclaimed_block_height >= current_block_height: raise TooEarlyClaim( 'You must wait for one block to call claim.' 'Use `claim_blocking` if you have a lot of time on your hands' ) # compute the absolute ttl ttl = self.client.compute_absolute_ttl(tx_ttl) claim_transaction = self.client.cli.post_name_claim(body=dict( account=keypair.get_address(), name=AEName._encode_name(self.domain), name_salt=self.preclaim_salt, fee=fee, ttl=ttl )) signed_tx = self.client.post_transaction(keypair, claim_transaction) self.status = AEName.Status.CLAIMED return signed_tx.tx_hash, self.preclaim_salt
def claim(self, fee=1): if self.preclaimed_block_height is None: raise MissingPreclaim( 'You must call preclaim before claiming a name') current_block_height = self.client.get_height() if self.preclaimed_block_height >= current_block_height: raise TooEarlyClaim( 'You must wait for one block to call claim.' 'Use `claim_blocking` if you have a lot of time on your hands') response = self.client.internal_http_post('name-claim-tx', json={ 'name': self.domain, 'name_salt': self.preclaim_salt, 'fee': fee }) try: self.name_hash = response['name_hash'] self.status = AEName.Status.CLAIMED except KeyError: raise ClaimFailed(response)
def claim(self, preclaim_tx_hash, account, name_salt, name_fee=defaults.NAME_FEE, fee=defaults.FEE, tx_ttl=defaults.TX_TTL) -> transactions.TxObject: """ Create and executes a claim transaction; performs a preliminary check to verify that the pre-claim exists and it has been confirmed :param preclaim_tx_hash: the transaction hash of the pre-claim transaction :param account: the account performing the transaction :param name_salt: the salt used to calculated the commitment_id in the pre-claim phase :param name_fee: the initial fee for the claim [optional, automatically calculated] :param fee: the fee for the transaction, [optional, calculated automatically] :param tx_ttl: relative number of blocks for the validity of the transaction :return: the TxObject of the claim :raises MissingPreclaim: if the pre-claim transaction cannot be found :raises NameCommitmentIdMismatch: if the commitment_id does not match the one from the pre-claim transaction :raises NameTooEarlyClaim: if the pre-claim transaction has not been confirmed yet :raises TypeError: if the value of the name_fee is not sufficient to successfully execute the claim """ self.preclaim_salt = name_salt # parse the amounts name_fee, fee = utils._amounts_to_aettos(name_fee, fee) # get the pre-claim height try: pre_claim_tx = self.client.get_transaction_by_hash( hash=preclaim_tx_hash) self.preclaimed_block_height = pre_claim_tx.block_height except OpenAPIClientException: raise MissingPreclaim( f"Pre-claim transaction {preclaim_tx_hash} not found") # if the commitment_id mismatch pre_claim_commitment_id = pre_claim_tx.tx.commitment_id commitment_id, _ = hashing.commitment_id(self.domain, salt=name_salt) if pre_claim_commitment_id != commitment_id: raise NameCommitmentIdMismatch( f"Commitment id mismatch, wanted {pre_claim_commitment_id} got {commitment_id}" ) # if the transaction has not been mined if self.preclaimed_block_height <= 0: raise NameTooEarlyClaim( f"The pre-claim transaction has not been mined yet") # get the current height current_height = self.client.get_current_key_block_height() safe_height = self.preclaimed_block_height + self.client.config.key_block_confirmation_num if current_height < safe_height: raise NameTooEarlyClaim( f"It is not safe to execute the name claim before height {safe_height}, current height: {current_height}" ) # get the transaction builder txb = self.client.tx_builder # get the account nonce and ttl nonce, ttl = self.client._get_nonce_ttl(account.get_address(), tx_ttl) # create transaction # check the protocol version min_name_fee = AEName.get_minimum_name_fee(self.domain) if name_fee != defaults.NAME_FEE and name_fee < min_name_fee: raise TypeError( f"the provided fee {name_fee} is not enough to execute the claim, required: {min_name_fee}" ) name_fee = max(min_name_fee, name_fee) tx = txb.tx_name_claim_v2(account.get_address(), self.domain, self.preclaim_salt, name_fee, fee, ttl, nonce) # sign the transaction tx_signed = self.client.sign_transaction(account, tx) # post the transaction to the chain self.client.broadcast_transaction(tx_signed) # update status self.status = AEName.Status.CLAIMED return tx_signed
def claim(self, preclaim_tx_hash, account, name_salt, name_fee=defaults.NAME_FEE, fee=defaults.FEE, tx_ttl=defaults.TX_TTL): self.preclaim_salt = name_salt # get the preclaim height try: pre_claim_tx = self.client.get_transaction_by_hash( hash=preclaim_tx_hash) self.preclaimed_block_height = pre_claim_tx.block_height except OpenAPIClientException: raise MissingPreclaim( f"Preclaim transaction {preclaim_tx_hash} not found") # first get the protocol version protocol = self.client.get_consensus_protocol_version() # if the commitment_id mismatch pre_claim_commitment_id = pre_claim_tx.tx.commitment_id commitment_id, _ = hashing.commitment_id(self.domain, salt=name_salt) if pre_claim_commitment_id != commitment_id: raise NameCommitmentIdMismatch( f"Commitment id mismatch, wanted {pre_claim_commitment_id} got {commitment_id}" ) # if the transaction has not been mined if self.preclaimed_block_height <= 0: raise NameTooEarlyClaim( f"The pre-claim transaction has not been mined yet") # get the current height current_height = self.client.get_current_key_block_height() safe_height = self.preclaimed_block_height + self.client.config.key_block_confirmation_num if current_height < safe_height: raise NameTooEarlyClaim( f"It is not safe to execute the name claim before height {safe_height}, current height: {current_height}" ) # get the transaction builder txb = self.client.tx_builder # get the account nonce and ttl nonce, ttl = self.client._get_nonce_ttl(account.get_address(), tx_ttl) # create transaction # check the protocol version if protocol < identifiers.PROTOCOL_LIMA: tx = txb.tx_name_claim(account.get_address(), self.domain, self.preclaim_salt, fee, ttl, nonce) else: min_name_fee = AEName.get_minimum_name_fee(self.domain) if name_fee != defaults.NAME_FEE and name_fee < min_name_fee: raise TypeError( f"the provided fee {name_fee} is not enough to execute the claim, required: {min_name_fee}" ) name_fee = max(min_name_fee, name_fee) tx = txb.tx_name_claim_v2(account.get_address(), self.domain, self.preclaim_salt, name_fee, fee, ttl, nonce) # sign the transaction tx_signed = self.client.sign_transaction(account, tx) # post the transaction to the chain self.client.broadcast_transaction(tx_signed) # update status self.status = AEName.Status.CLAIMED return tx_signed