本文整理汇总了Python中pycoin.tx.Tx.Tx.coinbase_tx方法的典型用法代码示例。如果您正苦于以下问题:Python Tx.coinbase_tx方法的具体用法?Python Tx.coinbase_tx怎么用?Python Tx.coinbase_tx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycoin.tx.Tx.Tx
的用法示例。
在下文中一共展示了Tx.coinbase_tx方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_coinbase_tx
# 需要导入模块: from pycoin.tx.Tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx.Tx import coinbase_tx [as 别名]
def test_coinbase_tx(self):
tx = Tx.coinbase_tx(COINBASE_PUB_KEY_FROM_80971, int(50 * 1e8), COINBASE_BYTES_FROM_80971)
s = io.BytesIO()
tx.stream(s)
tx1 = s.getvalue()
s = io.BytesIO()
block_80971.txs[0].stream(s)
tx2 = s.getvalue()
self.assertEqual(tx1, tx2)
示例2: test_build_spends
# 需要导入模块: from pycoin.tx.Tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx.Tx import coinbase_tx [as 别名]
def test_build_spends(self):
# first, here is the tx database
TX_DB = {}
# 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(exponent * secp256k1_generator, compressed=compressed)
the_coinbase_tx = Tx.coinbase_tx(public_key_sec, int(50 * 1e8), COINBASE_BYTES_FROM_80971)
TX_DB[the_coinbase_tx.hash()] = the_coinbase_tx
# now create a Tx that spends the coinbase
compressed = False
exponent_2 = int("137f3276686959c82b454eea6eefc9ab1b9e45bd4636fb9320262e114e321da1", 16)
bitcoin_address_2 = public_pair_to_bitcoin_address(exponent_2 * secp256k1_generator, compressed=compressed)
self.assertEqual("12WivmEn8AUth6x6U8HuJuXHaJzDw3gHNZ", bitcoin_address_2)
coins_from = [(the_coinbase_tx.hash(), 0, the_coinbase_tx.txs_out[0])]
coins_to = [(int(50 * 1e8), bitcoin_address_2)]
unsigned_coinbase_spend_tx = standard_tx(coins_from, coins_to)
solver = build_hash160_lookup([exponent])
coinbase_spend_tx = unsigned_coinbase_spend_tx.sign(solver)
# now check that it validates
self.assertEqual(coinbase_spend_tx.bad_signature_count(), 0)
TX_DB[coinbase_spend_tx.hash()] = coinbase_spend_tx
# 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(exponent_3 * secp256k1_generator, compressed=compressed)
self.assertEqual("13zzEHPCH2WUZJzANymow3ZrxcZ8iFBrY5", bitcoin_address_3)
coins_from = [(coinbase_spend_tx.hash(), 0, coinbase_spend_tx.txs_out[0])]
unsigned_spend_tx = standard_tx(coins_from, [(int(50 * 1e8), bitcoin_address_3)])
solver.update(build_hash160_lookup([exponent_2]))
spend_tx = unsigned_spend_tx.sign(solver)
# now check that it validates
self.assertEqual(spend_tx.bad_signature_count(), 0)
示例3: test_signature_hash
# 需要导入模块: from pycoin.tx.Tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx.Tx import coinbase_tx [as 别名]
def test_signature_hash(self):
compressed = False
exponent_2 = int("137f3276686959c82b454eea6eefc9ab1b9e45bd4636fb9320262e114e321da1", 16)
bitcoin_address_2 = public_pair_to_bitcoin_address(exponent_2 * secp256k1_generator, compressed=compressed)
exponent = wif_to_secret_exponent("5JMys7YfK72cRVTrbwkq5paxU7vgkMypB55KyXEtN5uSnjV7K8Y")
public_key_sec = public_pair_to_sec(exponent * secp256k1_generator, compressed=compressed)
the_coinbase_tx = Tx.coinbase_tx(public_key_sec, int(50 * 1e8), COINBASE_BYTES_FROM_80971)
coins_from = [(the_coinbase_tx.hash(), 0, the_coinbase_tx.txs_out[0])]
coins_to = [(int(50 * 1e8), bitcoin_address_2)]
unsigned_coinbase_spend_tx = standard_tx(coins_from, coins_to)
tx_out_script_to_check = the_coinbase_tx.txs_out[0].script
idx = 0
actual_hash = unsigned_coinbase_spend_tx.signature_hash(tx_out_script_to_check, idx, hash_type=SIGHASH_ALL)
self.assertEqual(actual_hash, 29819170155392455064899446505816569230970401928540834591675173488544269166940)
示例4: coinbase_tx
# 需要导入模块: from pycoin.tx.Tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx.Tx import coinbase_tx [as 别名]
def coinbase_tx(secret_exponent):
public_pair = ecdsa.public_pair_for_secret_exponent(
ecdsa.secp256k1.generator_secp256k1, secret_exponent)
public_key_sec = public_pair_to_sec(public_pair)
return Tx.coinbase_tx(public_key_sec, 2500000000)
示例5: test_tx_out_bitcoin_address
# 需要导入模块: from pycoin.tx.Tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx.Tx import coinbase_tx [as 别名]
def test_tx_out_bitcoin_address(self):
tx = Tx.coinbase_tx(COINBASE_PUB_KEY_FROM_80971, int(50 * 1e8), COINBASE_BYTES_FROM_80971)
self.assertEqual(tx.txs_out[0].bitcoin_address(), '1DmapcnrJNGeJB13fv9ngRFX1iRvR4zamn')