Beispiel #1
0
    def test_build_spends(self):
        # create a coinbase Tx where we know the public & private key

        exponent = wif_to_secret_exponent(
            "5JMys7YfK72cRVTrbwkq5paxU7vgkMypB55KyXEtN5uSnjV7K8Y")
        compressed = False

        public_key_sec = public_pair_to_sec(
            ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1,
                                                  exponent),
            compressed=compressed)

        the_coinbase_tx = Tx.coinbase_tx(public_key_sec, int(50 * 1e8),
                                         COINBASE_BYTES_FROM_80971)

        # now create a Tx that spends the coinbase

        compressed = False

        exponent_2 = int(
            "137f3276686959c82b454eea6eefc9ab1b9e45bd4636fb9320262e114e321da1",
            16)
        bitcoin_address_2 = public_pair_to_bitcoin_address(
            ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1,
                                                  exponent_2),
            compressed=compressed)

        self.assertEqual("12WivmEn8AUth6x6U8HuJuXHaJzDw3gHNZ",
                         bitcoin_address_2)

        TX_DB = dict((tx.hash(), tx) for tx in [the_coinbase_tx])

        coins_from = [(the_coinbase_tx.hash(), 0)]
        coins_to = [(int(50 * 1e8), bitcoin_address_2)]
        coinbase_spend_tx = Tx.standard_tx(coins_from, coins_to, TX_DB,
                                           [exponent])
        coinbase_spend_tx.validate(TX_DB)

        ## now try to respend from priv_key_2 to priv_key_3

        compressed = True

        exponent_3 = int(
            "f8d39b8ecd0e1b6fee5a340519f239097569d7a403a50bb14fb2f04eff8db0ff",
            16)
        bitcoin_address_3 = public_pair_to_bitcoin_address(
            ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1,
                                                  exponent_3),
            compressed=compressed)

        self.assertEqual("13zzEHPCH2WUZJzANymow3ZrxcZ8iFBrY5",
                         bitcoin_address_3)

        TX_DB = dict((tx.hash(), tx) for tx in [coinbase_spend_tx])

        spend_tx = Tx.standard_tx([(coinbase_spend_tx.hash(), 0)],
                                  [(int(50 * 1e8), bitcoin_address_3)], TX_DB,
                                  [exponent_2])

        spend_tx.validate(TX_DB)
Beispiel #2
0
 def test_standard_tx_out(self):
     coin_value = 10
     recipient_bc_address = '1BcJRKjiwYQ3f37FQSpTYM7AfnXurMjezu'
     tx_out = Tx.standard_tx(
         [], [(coin_value, recipient_bc_address)]).txs_out[0]
     s = str(tx_out)
     self.assertEqual(
         'TxOut<1E-7 "OP_DUP OP_HASH160 745e5b81fd30ca1e90311b012badabaa4411ae1a OP_EQUALVERIFY OP_CHECKSIG">',
         s)
    def test_build_spends(self):
        # create a coinbase Tx where we know the public & private key

        exponent = wif_to_secret_exponent("5JMys7YfK72cRVTrbwkq5paxU7vgkMypB55KyXEtN5uSnjV7K8Y")
        compressed = False

        public_key_sec = public_pair_to_sec(ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1, exponent), compressed=compressed)

        the_coinbase_tx = Tx.coinbase_tx(public_key_sec, int(50 * 1e8), COINBASE_BYTES_FROM_80971)

        # now create a Tx that spends the coinbase

        compressed = False

        exponent_2 = int("137f3276686959c82b454eea6eefc9ab1b9e45bd4636fb9320262e114e321da1", 16)
        bitcoin_address_2 = public_pair_to_bitcoin_address(
                ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1, exponent_2),
                compressed=compressed)

        self.assertEqual("12WivmEn8AUth6x6U8HuJuXHaJzDw3gHNZ", bitcoin_address_2)

        TX_DB = dict((tx.hash(), tx) for tx in [the_coinbase_tx])

        coins_from = [(the_coinbase_tx.hash(), 0)]
        coins_to = [(int(50 * 1e8), bitcoin_address_2)]
        coinbase_spend_tx = Tx.standard_tx(coins_from, coins_to, TX_DB, [exponent])
        coinbase_spend_tx.validate(TX_DB)

        ## now try to respend from priv_key_2 to priv_key_3

        compressed = True

        exponent_3 = int("f8d39b8ecd0e1b6fee5a340519f239097569d7a403a50bb14fb2f04eff8db0ff", 16)
        bitcoin_address_3 = public_pair_to_bitcoin_address(
                ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1, exponent_3),
                compressed=compressed)

        self.assertEqual("13zzEHPCH2WUZJzANymow3ZrxcZ8iFBrY5", bitcoin_address_3)

        TX_DB = dict((tx.hash(), tx) for tx in [coinbase_spend_tx])

        spend_tx = Tx.standard_tx([(coinbase_spend_tx.hash(), 0)], [(int(50 * 1e8), bitcoin_address_3)], TX_DB, [exponent_2])

        spend_tx.validate(TX_DB)
 def test_standard_tx_out(self):
     coin_value = 10
     recipient_bc_address = '1BcJRKjiwYQ3f37FQSpTYM7AfnXurMjezu'
     tx_out = Tx.standard_tx([], [(coin_value, recipient_bc_address)]).txs_out[0]
     s = str(tx_out)
     self.assertEqual('TxOut<1E-7 "OP_DUP OP_HASH160 745e5b81fd30ca1e90311b012badabaa4411ae1a OP_EQUALVERIFY OP_CHECKSIG">', s)