tfchain/TFChainWallet.py
def verify(self, outputid, amount=None, secret_hash=None, min_refund_time=None, sender=False, receiver=False, contract=None):
        """
        Verify the status and content of the Atomic Swap Contract linked to the given outputid.
        An exception is returned if the contract does not exist, has already been spent
        or is not valid according to this validation

        Returns the verified contract.

        @param outputid: str or Hash that identifies the coin output to whuich this contract is linked
        @param amount: validate amount if defined, int or str that defines the amount of TFT to set, see explanation above
        @param secret_hash: validate secret hash if defined, str or BinaryData
        @param min_refund_time: validate contract's refund time if defined, 0 if expected to be refundable, else the minimun time expected until it becomes refundable
        @param sender: if True it is expected that this wallet is registered as the sender of this contract
        @param receiver: if True it is expected that this wallet is registered as the receiver of this contract
        @param contract: if contract fetched in a previous call already, one can verify it also by directly passing it to this method
        """
        if contract is None:
            co = None
            spend_txn = None
            # try to fetch the contract
            try:
                # try to fetch the coin output that is expected to contain the secret
                co, _, spend_txn = self._wallet.client.coin_output_get(outputid)
            except tfchain.errors.ExplorerNoContent as exc:
                raise tfchain.errors.AtomicSwapContractNotFound(outputid=outputid) from exc
            # check if the contract hasn't been spent already
            if spend_txn is not None:
                # if a spend transaction exists,
                # it means the contract was already spend, and can therefore no longer be redeemed
                raise tfchain.errors.AtomicSwapContractSpent(contract=AtomicSwapContract(
                    coinoutput=co, unspent=False, current_timestamp=self._chain_time), transaction=spend_txn)

            # create the unspent contract
            contract = AtomicSwapContract(coinoutput=co, unspent=True, current_timestamp=self._chain_time)
        elif not isinstance(contract, AtomicSwapContract):
            raise TypeError("contract was expected to be an AtomicSwapContract, not to be of type {}".format(type(contract)))
        else:
            # verify the outputid is the same
            if contract.outputid != outputid:
                raise tfchain.errors.AtomicSwapContractInvalid(
                    message="output identifier is expected to be {}, not {}".format(str(outputid), str(contract.outputid)),
                    contract=contract)

        # if amount is given verify it
        if amount is not None:
            amount = Currency(value=amount)
            if amount != contract.amount:
                raise tfchain.errors.AtomicSwapContractInvalid(
                    message="amount is expected to be {}, not {}".format(amount.str(with_unit=True), contract.amount.str(with_unit=True)),
                    contract=contract)

        # if secret hash is given verify it
        if secret_hash is not None:
            # normalize secret hash
            secret_hash = AtomicSwapSecretHash(value=secret_hash)
            if secret_hash != contract.secret_hash:
                raise tfchain.errors.AtomicSwapContractInvalid(
                    message="secret_hash is expected to be {}, not {}".format(str(secret_hash), str(contract.secret_hash)),
                    contract=contract)

        # if min_refund_time is given verify it
        if min_refund_time is not None:
            chain_time = self._chain_time
            if isinstance(min_refund_time, str):
                min_refund_time = OutputLock(value=min_refund_time, current_timestamp=chain_time).value
            elif not isinstance(min_refund_time, int):
                raise TypeError("expected minimum refund time to be an integer or string, not to be of type {}".format(type(min_refund_time)))
            min_duration = max(0, min_refund_time-chain_time)
            chain_time = self._chain_time
            if chain_time >= contract.refund_timestamp:
                contract_duration = 0
            else:
                contract_duration = contract.refund_timestamp - chain_time
            if min_duration <= 0:
                if contract_duration != 0:
                    raise tfchain.errors.AtomicSwapContractInvalid(
                        message="contract cannot be refunded yet while it was expected to be possible already",
                        contract=contract)
            elif contract_duration < min_duration:
                if contract_duration == 0:
                    raise tfchain.errors.AtomicSwapContractInvalid(
                        message="contract was expected to be non-refundable for at least {} more, but it can be refunded already since {}".format(
                            duration.toString(min_duration), epoch2HRDateTime(contract.refund_timestamp)),
                        contract=contract)
                elif contract_duration < min_duration:
                    raise tfchain.errors.AtomicSwapContractInvalid(
                        message="contract was expected to be available for redemption for at least {}, but it is only available for {}".format(
                            duration.toString(min_duration), duration.toString(contract_duration)),
                        contract=contract)

        # if expected to be authorized to be the sender, verify this
        if sender and contract.sender not in self._wallet.addresses:
            raise tfchain.errors.AtomicSwapContractInvalid(
                message="wallet not registered as sender of this contract", contract=contract)

        # if expected to be authorized to be the receiver, verify this
        if receiver and contract.receiver not in self._wallet.addresses:
            raise tfchain.errors.AtomicSwapContractInvalid(
                message="wallet not registered as receiver of this contract", contract=contract)

        # return the contract for further optional consumption,
        # according to our validations it is valid
        return contract

        Verify the status and content of the Atomic Swap Contract linked to the given outputid.
        An exception is returned if the contract does not exist, has already been spent
        or is not valid according to this validation

        Returns the verified contract.

        @param outputid: str or Hash that identifies the coin output to whuich this contract is linked
        @param amount: validate amount if defined, int or str that defines the amount of TFT to set, see explanation above
        @param secret_hash: validate secret hash if defined, str or BinaryData
        @param min_refund_time: validate contract's refund time if defined, 0 if expected to be refundable, else the minimun time expected until it becomes refundable
        @param sender: if True it is expected that this wallet is registered as the sender of this contract
        @param receiver: if True it is expected that this wallet is registered as the receiver of this contract
        @param contract: if contract fetched in a previous call already, one can verify it also by directly passing it to this method
        
Verify the status and content of the Atomic Swap Contract linked to the given outputid.
An exception is returned if the contract does not exist, has already been spent
or is not valid according to this validation

Returns the verified contract.
Verify the status and content of the Atomic Swap Contract linked to the given outputid . An exception is returned if the contract does not exist has already been spent or is not valid according to this validation Returns the verified contract .
def verify(self, outputid, amount=None, secret_hash=None, min_refund_time=None, sender=False, receiver=False, contract=None):
        if contract is None:
            co = None
            spend_txn = None
            try:
                co, _, spend_txn = self._wallet.client.coin_output_get(outputid)
            except tfchain.errors.ExplorerNoContent as exc:
                raise tfchain.errors.AtomicSwapContractNotFound(outputid=outputid) from exc
            if spend_txn is not None:
                raise tfchain.errors.AtomicSwapContractSpent(contract=AtomicSwapContract(
                    coinoutput=co, unspent=False, current_timestamp=self._chain_time), transaction=spend_txn)
            contract = AtomicSwapContract(coinoutput=co, unspent=True, current_timestamp=self._chain_time)
        elif not isinstance(contract, AtomicSwapContract):
            raise TypeError("contract was expected to be an AtomicSwapContract, not to be of type {}".format(type(contract)))
        else:
            if contract.outputid != outputid:
                raise tfchain.errors.AtomicSwapContractInvalid(
                    message="output identifier is expected to be {}, not {}".format(str(outputid), str(contract.outputid)),
                    contract=contract)
        if amount is not None:
            amount = Currency(value=amount)
            if amount != contract.amount:
                raise tfchain.errors.AtomicSwapContractInvalid(
                    message="amount is expected to be {}, not {}".format(amount.str(with_unit=True), contract.amount.str(with_unit=True)),
                    contract=contract)
        if secret_hash is not None:
            secret_hash = AtomicSwapSecretHash(value=secret_hash)
            if secret_hash != contract.secret_hash:
                raise tfchain.errors.AtomicSwapContractInvalid(
                    message="secret_hash is expected to be {}, not {}".format(str(secret_hash), str(contract.secret_hash)),
                    contract=contract)
        if min_refund_time is not None:
            chain_time = self._chain_time
            if isinstance(min_refund_time, str):
                min_refund_time = OutputLock(value=min_refund_time, current_timestamp=chain_time).value
            elif not isinstance(min_refund_time, int):
                raise TypeError("expected minimum refund time to be an integer or string, not to be of type {}".format(type(min_refund_time)))
            min_duration = max(0, min_refund_time-chain_time)
            chain_time = self._chain_time
            if chain_time >= contract.refund_timestamp:
                contract_duration = 0
            else:
                contract_duration = contract.refund_timestamp - chain_time
            if min_duration <= 0:
                if contract_duration != 0:
                    raise tfchain.errors.AtomicSwapContractInvalid(
                        message="contract cannot be refunded yet while it was expected to be possible already",
                        contract=contract)
            elif contract_duration < min_duration:
                if contract_duration == 0:
                    raise tfchain.errors.AtomicSwapContractInvalid(
                        message="contract was expected to be non-refundable for at least {} more, but it can be refunded already since {}".format(
                            duration.toString(min_duration), epoch2HRDateTime(contract.refund_timestamp)),
                        contract=contract)
                elif contract_duration < min_duration:
                    raise tfchain.errors.AtomicSwapContractInvalid(
                        message="contract was expected to be available for redemption for at least {}, but it is only available for {}".format(
                            duration.toString(min_duration), duration.toString(contract_duration)),
                        contract=contract)
        if sender and contract.sender not in self._wallet.addresses:
            raise tfchain.errors.AtomicSwapContractInvalid(
                message="wallet not registered as sender of this contract", contract=contract)
        if receiver and contract.receiver not in self._wallet.addresses:
            raise tfchain.errors.AtomicSwapContractInvalid(
                message="wallet not registered as receiver of this contract", contract=contract)
        return contract
def verify ( self , outputid , amount = None , secret_hash = None , min_refund_time = None , sender = False , receiver = False , contract = None ) : if contract is None : co = None spend_txn = None try : co , _ , spend_txn = self . _wallet . client . coin_output_get ( outputid ) except tfchain . errors . ExplorerNoContent as exc : raise tfchain . errors . AtomicSwapContractNotFound ( outputid = outputid ) from exc if spend_txn is not None : raise tfchain . errors . AtomicSwapContractSpent ( contract = AtomicSwapContract ( coinoutput = co , unspent = False , current_timestamp = self . _chain_time ) , transaction = spend_txn ) contract = AtomicSwapContract ( coinoutput = co , unspent = True , current_timestamp = self . _chain_time ) elif not isinstance ( contract , AtomicSwapContract ) : raise TypeError ( "contract was expected to be an AtomicSwapContract, not to be of type {}" . format ( type ( contract ) ) ) else : if contract . outputid != outputid : raise tfchain . errors . AtomicSwapContractInvalid ( message = "output identifier is expected to be {}, not {}" . format ( str ( outputid ) , str ( contract . outputid ) ) , contract = contract ) if amount is not None : amount = Currency ( value = amount ) if amount != contract . amount : raise tfchain . errors . AtomicSwapContractInvalid ( message = "amount is expected to be {}, not {}" . format ( amount . str ( with_unit = True ) , contract . amount . str ( with_unit = True ) ) , contract = contract ) if secret_hash is not None : secret_hash = AtomicSwapSecretHash ( value = secret_hash ) if secret_hash != contract . secret_hash : raise tfchain . errors . AtomicSwapContractInvalid ( message = "secret_hash is expected to be {}, not {}" . format ( str ( secret_hash ) , str ( contract . secret_hash ) ) , contract = contract ) if min_refund_time is not None : chain_time = self . _chain_time if isinstance ( min_refund_time , str ) : min_refund_time = OutputLock ( value = min_refund_time , current_timestamp = chain_time ) . value elif not isinstance ( min_refund_time , int ) : raise TypeError ( "expected minimum refund time to be an integer or string, not to be of type {}" . format ( type ( min_refund_time ) ) ) min_duration = max ( 0 , min_refund_time - chain_time ) chain_time = self . _chain_time if chain_time >= contract . refund_timestamp : contract_duration = 0 else : contract_duration = contract . refund_timestamp - chain_time if min_duration <= 0 : if contract_duration != 0 : raise tfchain . errors . AtomicSwapContractInvalid ( message = "contract cannot be refunded yet while it was expected to be possible already" , contract = contract ) elif contract_duration < min_duration : if contract_duration == 0 : raise tfchain . errors . AtomicSwapContractInvalid ( message = "contract was expected to be non-refundable for at least {} more, but it can be refunded already since {}" . format ( duration . toString ( min_duration ) , epoch2HRDateTime ( contract . refund_timestamp ) ) , contract = contract ) elif contract_duration < min_duration : raise tfchain . errors . AtomicSwapContractInvalid ( message = "contract was expected to be available for redemption for at least {}, but it is only available for {}" . format ( duration . toString ( min_duration ) , duration . toString ( contract_duration ) ) , contract = contract ) if sender and contract . sender not in self . _wallet . addresses : raise tfchain . errors . AtomicSwapContractInvalid ( message = "wallet not registered as sender of this contract" , contract = contract ) if receiver and contract . receiver not in self . _wallet . addresses : raise tfchain . errors . AtomicSwapContractInvalid ( message = "wallet not registered as receiver of this contract" , contract = contract ) return contract
Verify the status and content of the Atomic Swap Contract linked to the given outputid.
Verify the status and content of the Atomic Swap Contract linked to the given outputid .
"""
        Verify the status and content of the Atomic Swap Contract linked to the given outputid.
        An exception is returned if the contract does not exist, has already been spent
        or is not valid according to this validation

        Returns the verified contract.

        @param outputid: str or Hash that identifies the coin output to whuich this contract is linked
        @param amount: validate amount if defined, int or str that defines the amount of TFT to set, see explanation above
        @param secret_hash: validate secret hash if defined, str or BinaryData
        @param min_refund_time: validate contract's refund time if defined, 0 if expected to be refundable, else the minimun time expected until it becomes refundable
        @param sender: if True it is expected that this wallet is registered as the sender of this contract
        @param receiver: if True it is expected that this wallet is registered as the receiver of this contract
        @param contract: if contract fetched in a previous call already, one can verify it also by directly passing it to this method
        """ # try to fetch the contract # try to fetch the coin output that is expected to contain the secret # check if the contract hasn't been spent already # if a spend transaction exists, # it means the contract was already spend, and can therefore no longer be redeemed # create the unspent contract # verify the outputid is the same # if amount is given verify it # if secret hash is given verify it # normalize secret hash # if min_refund_time is given verify it # if expected to be authorized to be the sender, verify this # if expected to be authorized to be the receiver, verify this # return the contract for further optional consumption, # according to our validations it is valid
self
outputid
str or Hash that identifies the coin output to whuich this contract is linked
str or Hash that identifies the coin output to whuich this contract is linked
amount
validate amount if defined, int or str that defines the amount of TFT to set, see explanation above
validate amount if defined int or str that defines the amount of TFT to set see explanation above
secret_hash
validate secret hash if defined, str or BinaryData
validate secret hash if defined str or BinaryData
min_refund_time
validate contract's refund time if defined, 0 if expected to be refundable, else the minimun time expected until it becomes refundable
validate contract ' s refund time if defined 0 if expected to be refundable else the minimun time expected until it becomes refundable
sender
if True it is expected that this wallet is registered as the sender of this contract
if True it is expected that this wallet is registered as the sender of this contract
receiver
if True it is expected that this wallet is registered as the receiver of this contract
if True it is expected that this wallet is registered as the receiver of this contract
contract
if contract fetched in a previous call already, one can verify it also by directly passing it to this method
if contract fetched in a previous call already one can verify it also by directly passing it to this method