Exemplo n.º 1
0
 def atomic_swap(
     self,
     sender_address: str,
     recipient_address: str,
     value: float,
     solvable_utxo: list,
     secret_hash: str = None,
 ) -> BitcoinAtomicSwapTransaction:
     transaction = BitcoinAtomicSwapTransaction(self, sender_address,
                                                recipient_address, value,
                                                solvable_utxo, secret_hash)
     transaction.create_unsigned_transaction()
     return transaction
Exemplo n.º 2
0
def test_swap_contract(alice_wallet, bob_wallet):
    transaction = BitcoinAtomicSwapTransaction(BitcoinTestNet(),
                                               alice_wallet.address,
                                               bob_wallet.address,
                                               0.5,
                                               solvable_utxo=[])
    transaction.set_locktime(number_of_hours=48)
    transaction.generate_hash()
    transaction.build_atomic_swap_contract()
    assert transaction.contract.is_valid()
Exemplo n.º 3
0
 def atomic_swap(
     self,
     sender_address: str,
     recipient_address: str,
     value: float,
     solvable_utxo: list = None,
     secret_hash: str = None,
 ) -> BitcoinAtomicSwapTransaction:
     if not solvable_utxo:
         solvable_utxo = self.get_utxo(sender_address, value)
         if not solvable_utxo:
             logger.error(f'Cannot get UTXO for address {sender_address}')
             return
     transaction = BitcoinAtomicSwapTransaction(self, sender_address,
                                                recipient_address, value,
                                                solvable_utxo, secret_hash)
     transaction.create_unsigned_transaction()
     return transaction
Exemplo n.º 4
0
    def atomic_swap(
        self,
        sender_address: str,
        recipient_address: str,
        value: float,
        solvable_utxo: list = None,
        secret_hash: str = None,
    ) -> Optional[BitcoinAtomicSwapTransaction]:
        '''
        Creates atomic swap unsigned transaction object.

        Args:
            sender_address (str): wallet address of the sender
            recipient_address (str): wallet address of the recipient
            value (float): amount to swap
            solvable_utxo (list): optional list of UTXO objects. If None then it will try to find UTXO automatically
                by using the `get_utxo` method.
            secret_hash (str): optional secret hash to be used in transaction. If None then the new hash
                will be generated.

        Returns:
            BitcoinAtomicSwapTransaction, None: unsigned Atomic Swap transaction object or None if something went wrong

        Example:
            >>> from clove.network import BitcoinTestNet
            >>> network = BitcoinTestNet()
            >>> network.atomic_swap('msJ2ucZ2NDhpVzsiNE5mGUFzqFDggjBVTM', 'mmJtKA92Mxqfi3XdyGReza69GjhkwAcBN1', 2.4)
            <clove.network.bitcoin.transaction.BitcoinAtomicSwapTransaction at 0x7f989439d630>
        '''
        if not solvable_utxo:
            solvable_utxo = self.get_utxo(sender_address, value)
            if not solvable_utxo:
                logger.error(f'Cannot get UTXO for address {sender_address}')
                return
        transaction = BitcoinAtomicSwapTransaction(self, sender_address,
                                                   recipient_address, value,
                                                   solvable_utxo, secret_hash)
        transaction.create_unsigned_transaction()
        return transaction
Exemplo n.º 5
0
def test_swap_transaction_with_invalid_recipient_and_sender_addresses():
    with raises(ValueError,
                match='Given recipient and sender addresses are invalid.'):
        BitcoinAtomicSwapTransaction(BitcoinTestNet(), 'invalid_address',
                                     'address_123', 0.01, [])
Exemplo n.º 6
0
def test_swap_transaction_with_invalid_sender_address(bob_wallet):
    with raises(ValueError, match='Given sender address is invalid.'):
        BitcoinAtomicSwapTransaction(BitcoinTestNet(), 'invalid_address',
                                     bob_wallet.address, 0.01, [])