How to use the transaction.Payment function in transaction

To help you get started, we’ve selected a few transaction examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github notsag-dev / scroogecoin / test_goofy.py View on Github external
def test_process_payment_without_signature(self):
        """ Put coins in the Goofy's wallet, and transfer them
            to the same wallet without signing
        """
        goofy = Goofy()
        coin = Goofycoin(value=2, wallet_id=goofy.wallet.id)
        created_coins = goofy.create_coins([coin]).transaction.created_coins
        payment = Payment(created_coins=[coin], consumed_coins=created_coins)
        payment_result = goofy.process_payment(payment, [])
        self.assertEqual(payment_result, None)
github notsag-dev / scroogecoin / test_goofy.py View on Github external
def test_process_payment_with_signature(self):
        """ Put coins in the Goofy's wallet, and transfer them
            to the same wallet
        """
        goofy = Goofy()
        coin = Goofycoin(value=2, wallet_id=goofy.wallet.id)
        created_coins = goofy.create_coins([coin]).transaction.created_coins
        payment = Payment(created_coins=[coin], consumed_coins=created_coins)
        signature = goofy.wallet.sign(encoded_hash_object(payment))
        payment_result = goofy.process_payment(
            payment, [(goofy.wallet.verifying_key, signature)]
        )
        self.assertFalse(payment_result == None)
github notsag-dev / scroogecoin / wallet.py View on Github external
def devide_coin(self, coin, value, scrooge):
        """ Devide a coin in two new coins. The paramenter
            'value' is the value of one of the new coins
            and the value of the other is the rest.
            The original coin is consumed and cannot be used
            again.
        """
        if value > coin.value:
            return
        created_coins = []
        created_coins.append(Scroogecoin(value, self.id))
        created_coins.append(Scroogecoin(coin.value - value, self.id))
        payment = Payment(created_coins=created_coins, consumed_coins=[coin])
        signature = self.sign(encoded_hash_object(payment))
        new_block = scrooge.process_payment(
            payment, [(self.verifying_key, signature)]
        )
        return new_block.transaction.created_coins
github pagseguromaster / plugpag / 1.x / demos / Windows / Python / PlugPagDemo / plugpag.py View on Github external
print("\n\n*** Pressione Ctrl+C para finalizar a aplicacao ***")

    try:
        while (True):
            # Read menu option
            option = readOption()

            # Handle selected option
            returnValue = None
            transactionResult = TransactionResult()

            print('')

            if option == 1:
                # Payment option
                returnValue = transaction.Payment(pp, ENCODING).execute(transactionResult)
            elif option == 2:
                # Cancel transaction
                returnValue = transaction.CancelPayment(pp).execute(transactionResult)
            elif option == 3:
                # Query last transaction
                returnValue = transaction.QueryLastTransaction(pp).execute(transactionResult)

            if returnValue is not None:
                printResult(returnValue, transactionResult)
    except KeyboardInterrupt:
        print("\n\nFIM\n..........")
github notsag-dev / scroogecoin / blockchain.py View on Github external
def check_coin(self, coin):
        """ Check if the coin was created and was not consumed """
        creation_id = coin.id.transaction_id

        # Check created
        if coin not in self.blocks[creation_id].transaction.created_coins:
            print('WARNING: Coin creation not found')
            return False

        # Check not consumed
        for ind in range(creation_id + 1, len(self.blocks)):
            transaction = self.blocks[ind].transaction
            if isinstance(transaction, Payment) and coin in transaction.consumed_coins:
                print('WARNING: Double spent attempt detected')
                return False

        return True
github notsag-dev / scroogecoin / wallet.py View on Github external
consumed_coins.append(coin)
                    consumed_amount = coin.value
                    amount -= coin.value
                else:
                    new_coins = self.devide_coin(coin, amount, scrooge)
                    consumed_ind = self.index_coin_value(new_coins, amount)
                    consumed_coins.append(new_coins[consumed_ind])
                    consumed_amount = amount
                    my_coins.append(new_coins[consumed_ind + 1])
                    amount = 0
                created_coins.append(
                    Scroogecoin(value=consumed_amount, wallet_id=wallet_id)
                )
                if amount == 0:
                    break
        return Payment(created_coins, consumed_coins)