本文整理汇总了Python中test_framework.util.hex_str_to_bytes函数的典型用法代码示例。如果您正苦于以下问题:Python hex_str_to_bytes函数的具体用法?Python hex_str_to_bytes怎么用?Python hex_str_to_bytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hex_str_to_bytes函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: p2pkh_address_to_script
def p2pkh_address_to_script(self,v):
pubkey = hex_str_to_bytes(v['pubkey'])
p2wpkh = CScript([OP_0, hash160(pubkey)])
p2sh_p2wpkh = CScript([OP_HASH160, hash160(p2wpkh), OP_EQUAL])
p2pk = CScript([pubkey, OP_CHECKSIG])
p2pkh = CScript(hex_str_to_bytes(v['scriptPubKey']))
p2sh_p2pk = CScript([OP_HASH160, hash160(p2pk), OP_EQUAL])
p2sh_p2pkh = CScript([OP_HASH160, hash160(p2pkh), OP_EQUAL])
p2wsh_p2pk = CScript([OP_0, sha256(p2pk)])
p2wsh_p2pkh = CScript([OP_0, sha256(p2pkh)])
p2sh_p2wsh_p2pk = CScript([OP_HASH160, hash160(p2wsh_p2pk), OP_EQUAL])
p2sh_p2wsh_p2pkh = CScript([OP_HASH160, hash160(p2wsh_p2pkh), OP_EQUAL])
return [p2wpkh, p2sh_p2wpkh, p2pk, p2pkh, p2sh_p2pk, p2sh_p2pkh, p2wsh_p2pk, p2wsh_p2pkh, p2sh_p2wsh_p2pk, p2sh_p2wsh_p2pkh]
开发者ID:Flowdalic,项目名称:bitcoin,代码行数:13,代码来源:feature_segwit.py
示例2: assert_tx_format_also_signed
def assert_tx_format_also_signed(self, utxo, segwit):
raw = self.nodes[0].createrawtransaction(
[{"txid": utxo["txid"], "vout": utxo["vout"]}],
[{self.unknown_addr: "49.9"}, {"fee": "0.1"}]
)
unsigned_decoded = self.nodes[0].decoderawtransaction(raw)
assert_equal(len(unsigned_decoded["vin"]), 1)
assert('txinwitness' not in unsigned_decoded["vin"][0])
# Cross-check python serialization
tx = CTransaction()
tx.deserialize(BytesIO(hex_str_to_bytes(raw)))
assert_equal(tx.vin[0].prevout.hash, int("0x"+utxo["txid"], 0))
assert_equal(len(tx.vin), len(unsigned_decoded["vin"]))
assert_equal(len(tx.vout), len(unsigned_decoded["vout"]))
# assert re-encoding
serialized = bytes_to_hex_str(tx.serialize())
assert_equal(serialized, raw)
# Now sign and repeat tests
signed_raw = self.nodes[0].signrawtransactionwithwallet(raw)["hex"]
signed_decoded = self.nodes[0].decoderawtransaction(signed_raw)
assert_equal(len(signed_decoded["vin"]), 1)
assert(("txinwitness" in signed_decoded["vin"][0]) == segwit)
# Cross-check python serialization
tx = CTransaction()
tx.deserialize(BytesIO(hex_str_to_bytes(signed_raw)))
assert_equal(tx.vin[0].prevout.hash, int("0x"+utxo["txid"], 0))
assert_equal(bytes_to_hex_str(tx.vin[0].scriptSig), signed_decoded["vin"][0]["scriptSig"]["hex"])
# test witness
if segwit:
wit_decoded = signed_decoded["vin"][0]["txinwitness"]
for i in range(len(wit_decoded)):
assert_equal(bytes_to_hex_str(tx.wit.vtxinwit[0].scriptWitness.stack[i]), wit_decoded[i])
# assert re-encoding
serialized = bytes_to_hex_str(tx.serialize())
assert_equal(serialized, signed_raw)
txid = self.nodes[0].sendrawtransaction(serialized)
nodetx = self.nodes[0].getrawtransaction(txid, 1)
assert_equal(nodetx["txid"], tx.rehash())
# cross-check wtxid report from node
wtxid = bytes_to_hex_str(ser_uint256(tx.calc_sha256(True))[::-1])
assert_equal(nodetx["wtxid"], wtxid)
assert_equal(nodetx["hash"], wtxid)
# witness hash stuff
assert_equal(nodetx["withash"], tx.calc_witness_hash())
return (txid, wtxid)
开发者ID:ElementsProject,项目名称:elements,代码行数:51,代码来源:feature_txwitness.py
示例3: buildDummySegwitNameUpdate
def buildDummySegwitNameUpdate (self, name, value, addr):
"""
Builds a transaction that updates the given name to the given value and
address. We assume that the name is at a native segwit script. The witness
of the transaction will be set to two dummy stack elements so that the
program itself is "well-formed" even if it won't execute successfully.
"""
data = self.node.name_show (name)
u = self.findUnspent (Decimal ('0.01'))
ins = [data, u]
outs = {addr: Decimal ('0.01')}
txHex = self.node.createrawtransaction (ins, outs)
nameOp = {"op": "name_update", "name": name, "value": value}
txHex = self.node.namerawtransaction (txHex, 0, nameOp)['hex']
txHex = self.node.signrawtransactionwithwallet (txHex)['hex']
tx = CTransaction ()
tx.deserialize (io.BytesIO (hex_str_to_bytes (txHex)))
tx.wit = CTxWitness ()
tx.wit.vtxinwit.append (CTxInWitness ())
tx.wit.vtxinwit[0].scriptWitness = CScriptWitness ()
tx.wit.vtxinwit[0].scriptWitness.stack = [b"dummy"] * 2
txHex = tx.serialize ().hex ()
return txHex
开发者ID:domob1812,项目名称:namecore,代码行数:27,代码来源:name_segwit.py
示例4: sign_transaction
def sign_transaction(node, unsignedtx):
rawtx = ToHex(unsignedtx)
signresult = node.signrawtransactionwithwallet(rawtx)
tx = CTransaction()
f = BytesIO(hex_str_to_bytes(signresult['hex']))
tx.deserialize(f)
return tx
开发者ID:MentalCollatz,项目名称:DigiByteProject,代码行数:7,代码来源:feature_csv_activation.py
示例5: create_transaction
def create_transaction(node, txid, to_address, amount):
inputs = [{"txid": txid, "vout": 0}]
outputs = {to_address: amount}
rawtx = node.createrawtransaction(inputs, outputs)
tx = CTransaction()
f = BytesIO(hex_str_to_bytes(rawtx))
tx.deserialize(f)
return tx
开发者ID:994920256,项目名称:bitcoin,代码行数:8,代码来源:feature_csv_activation.py
示例6: setScriptSigOps
def setScriptSigOps (self, txHex, ind, scriptSigOps):
"""
Update the given hex transaction by setting the scriptSig for the
input with the given index.
"""
tx = CTransaction ()
tx.deserialize (io.BytesIO (hex_str_to_bytes (txHex)))
tx.vin[ind].scriptSig = CScript (scriptSigOps)
return tx.serialize ().hex ()
开发者ID:domob1812,项目名称:namecore,代码行数:11,代码来源:name_multisig.py
示例7: addAuxpow
def addAuxpow (self, block, blkHash, ok):
"""
Fills in the auxpow for the given block message. It is either
chosen to be valid (ok = True) or invalid (ok = False).
"""
target = b"%064x" % uint256_from_compact (block.nBits)
auxpowHex = computeAuxpow (blkHash, target, ok)
block.auxpow = CAuxPow ()
block.auxpow.deserialize (BytesIO (hex_str_to_bytes (auxpowHex)))
return block
开发者ID:domob1812,项目名称:namecore,代码行数:12,代码来源:auxpow_invalidpow.py
示例8: make_utxo
def make_utxo(node, amount, confirmed=True, scriptPubKey=CScript([1])):
"""Create a txout with a given amount and scriptPubKey
Mines coins as needed.
confirmed - txouts created will be confirmed in the blockchain;
unconfirmed otherwise.
"""
fee = 1*COIN
while node.getbalance()['bitcoin'] < satoshi_round((amount + fee)/COIN):
node.generate(100)
new_addr = node.getnewaddress()
unblinded_addr = node.validateaddress(new_addr)["unconfidential"]
txidstr = node.sendtoaddress(new_addr, satoshi_round((amount+fee)/COIN))
tx1 = node.getrawtransaction(txidstr, 1)
txid = int(txidstr, 16)
i = None
for i, txout in enumerate(tx1['vout']):
if txout['scriptPubKey']['type'] == "fee":
continue # skip fee outputs
if txout['scriptPubKey']['addresses'] == [unblinded_addr]:
break
assert i is not None
tx2 = CTransaction()
tx2.vin = [CTxIn(COutPoint(txid, i))]
tx1raw = CTransaction()
tx1raw.deserialize(BytesIO(hex_str_to_bytes(node.getrawtransaction(txidstr))))
feeout = CTxOut(CTxOutValue(tx1raw.vout[i].nValue.getAmount() - amount))
tx2.vout = [CTxOut(amount, scriptPubKey), feeout]
tx2.rehash()
signed_tx = node.signrawtransactionwithwallet(txToHex(tx2))
txid = node.sendrawtransaction(signed_tx['hex'], True)
# If requested, ensure txouts are confirmed.
if confirmed:
mempool_size = len(node.getrawmempool())
while mempool_size > 0:
node.generate(1)
new_size = len(node.getrawmempool())
# Error out if we have something stuck in the mempool, as this
# would likely be a bug.
assert(new_size < mempool_size)
mempool_size = new_size
return COutPoint(int(txid, 16), 0)
开发者ID:ElementsProject,项目名称:elements,代码行数:50,代码来源:feature_rbf.py
示例9: create_and_mine_tx_from_txids
def create_and_mine_tx_from_txids(self, txids, success = True):
tx = CTransaction()
for i in txids:
txtmp = CTransaction()
txraw = self.nodes[0].getrawtransaction(i)
f = BytesIO(hex_str_to_bytes(txraw))
txtmp.deserialize(f)
for j in range(len(txtmp.vout)):
tx.vin.append(CTxIn(COutPoint(int('0x'+i,0), j)))
tx.vout.append(CTxOut(0, CScript()))
tx.rehash()
signresults = self.nodes[0].signrawtransactionwithwallet(bytes_to_hex_str(tx.serialize_without_witness()))['hex']
self.nodes[0].sendrawtransaction(signresults, True)
self.nodes[0].generate(1)
sync_blocks(self.nodes)
开发者ID:Flowdalic,项目名称:bitcoin,代码行数:15,代码来源:feature_segwit.py
示例10: submit_block_with_tx
def submit_block_with_tx(node, tx):
ctx = CTransaction()
ctx.deserialize(io.BytesIO(hex_str_to_bytes(tx)))
tip = node.getbestblockhash()
height = node.getblockcount() + 1
block_time = node.getblockheader(tip)["mediantime"] + 1
block = create_block(int(tip, 16), create_coinbase(height), block_time)
block.vtx.append(ctx)
block.rehash()
block.hashMerkleRoot = block.calc_merkle_root()
add_witness_commitment(block)
block.solve()
node.submitblock(block.serialize(True).hex())
return block
开发者ID:dgenr8,项目名称:bitcoin,代码行数:15,代码来源:wallet_bumpfee.py
示例11: cltv_validate
def cltv_validate(node, tx, height):
'''Modify the signature in vin 0 of the tx to pass CLTV
Prepends <height> CLTV DROP in the scriptSig, and sets
the locktime to height'''
tx.vin[0].nSequence = 0
tx.nLockTime = height
# Need to re-sign, since nSequence and nLockTime changed
signed_result = node.signrawtransactionwithwallet(ToHex(tx))
new_tx = CTransaction()
new_tx.deserialize(BytesIO(hex_str_to_bytes(signed_result['hex'])))
new_tx.vin[0].scriptSig = CScript([CScriptNum(height), OP_CHECKLOCKTIMEVERIFY, OP_DROP] +
list(CScript(new_tx.vin[0].scriptSig)))
return new_tx
开发者ID:fujicoin,项目名称:fujicoin,代码行数:15,代码来源:feature_cltv.py
示例12: get_key
def get_key(node):
"""Generate a fresh key on node
Returns a named tuple of privkey, pubkey and all address and scripts."""
addr = node.getnewaddress()
pubkey = node.getaddressinfo(addr)['pubkey']
pkh = hash160(hex_str_to_bytes(pubkey))
return Key(privkey=node.dumpprivkey(addr),
pubkey=pubkey,
p2pkh_script=CScript([OP_DUP, OP_HASH160, pkh, OP_EQUALVERIFY, OP_CHECKSIG]).hex(),
p2pkh_addr=key_to_p2pkh(pubkey),
p2wpkh_script=CScript([OP_0, pkh]).hex(),
p2wpkh_addr=key_to_p2wpkh(pubkey),
p2sh_p2wpkh_script=CScript([OP_HASH160, hash160(CScript([OP_0, pkh])), OP_EQUAL]).hex(),
p2sh_p2wpkh_redeem_script=CScript([OP_0, pkh]).hex(),
p2sh_p2wpkh_addr=key_to_p2sh_p2wpkh(pubkey))
开发者ID:JeremyRubin,项目名称:bitcoin,代码行数:16,代码来源:wallet_util.py
示例13: get_key
def get_key(self):
"""Generate a fresh key on node0
Returns a named tuple of privkey, pubkey and all address and scripts."""
addr = self.nodes[0].getnewaddress()
pubkey = self.nodes[0].getaddressinfo(addr)['pubkey']
pkh = hash160(hex_str_to_bytes(pubkey))
return Key(self.nodes[0].dumpprivkey(addr),
pubkey,
CScript([OP_DUP, OP_HASH160, pkh, OP_EQUALVERIFY, OP_CHECKSIG]).hex(), # p2pkh
key_to_p2pkh(pubkey), # p2pkh addr
CScript([OP_0, pkh]).hex(), # p2wpkh
key_to_p2wpkh(pubkey), # p2wpkh addr
CScript([OP_HASH160, hash160(CScript([OP_0, pkh])), OP_EQUAL]).hex(), # p2sh-p2wpkh
CScript([OP_0, pkh]).hex(), # p2sh-p2wpkh redeem script
key_to_p2sh_p2wpkh(pubkey)) # p2sh-p2wpkh addr
开发者ID:bigpot,项目名称:bitcoin,代码行数:16,代码来源:wallet_importmulti.py
示例14: run_test
def run_test (self):
node = self.nodes[0]
p2pStore = node.add_p2p_connection (P2PDataStore ())
p2pGetter = node.add_p2p_connection (P2PBlockGetter ())
self.log.info ("Adding a block with non-zero hash in the auxpow...")
blk, blkHash = self.createBlock ()
blk.auxpow.hashBlock = 12345678
blkHex = blk.serialize ().hex ()
assert_equal (node.submitblock (blkHex), None)
assert_equal (node.getbestblockhash (), blkHash)
self.log.info ("Retrieving block through RPC...")
gotHex = node.getblock (blkHash, 0)
assert gotHex != blkHex
gotBlk = CBlock ()
gotBlk.deserialize (BytesIO (hex_str_to_bytes (gotHex)))
assert_equal (gotBlk.auxpow.hashBlock, 0)
self.log.info ("Retrieving block through P2P...")
gotBlk = p2pGetter.getBlock (blkHash)
assert_equal (gotBlk.auxpow.hashBlock, 0)
self.log.info ("Sending zero-hash auxpow through RPC...")
blk, blkHash = self.createBlock ()
blk.auxpow.hashBlock = 0
assert_equal (node.submitblock (blk.serialize ().hex ()), None)
assert_equal (node.getbestblockhash (), blkHash)
self.log.info ("Sending zero-hash auxpow through P2P...")
blk, blkHash = self.createBlock ()
blk.auxpow.hashBlock = 0
p2pStore.send_blocks_and_test ([blk], node, success=True)
assert_equal (node.getbestblockhash (), blkHash)
self.log.info ("Sending non-zero nIndex auxpow through RPC...")
blk, blkHash = self.createBlock ()
blk.auxpow.nIndex = 42
assert_equal (node.submitblock (blk.serialize ().hex ()), None)
assert_equal (node.getbestblockhash (), blkHash)
self.log.info ("Sending non-zero nIndex auxpow through P2P...")
blk, blkHash = self.createBlock ()
blk.auxpow.nIndex = 42
p2pStore.send_blocks_and_test ([blk], node, success=True)
assert_equal (node.getbestblockhash (), blkHash)
开发者ID:domob1812,项目名称:namecore,代码行数:46,代码来源:auxpow_zerohash.py
示例15: get_multisig
def get_multisig(self):
"""Generate a fresh multisig on node0
Returns a named tuple of privkeys, pubkeys and all address and scripts."""
addrs = []
pubkeys = []
for _ in range(3):
addr = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
addrs.append(addr['address'])
pubkeys.append(addr['pubkey'])
script_code = CScript([OP_2] + [hex_str_to_bytes(pubkey) for pubkey in pubkeys] + [OP_3, OP_CHECKMULTISIG])
witness_script = CScript([OP_0, sha256(script_code)])
return Multisig([self.nodes[0].dumpprivkey(addr) for addr in addrs],
pubkeys,
CScript([OP_HASH160, hash160(script_code), OP_EQUAL]).hex(), # p2sh
script_to_p2sh(script_code), # p2sh addr
script_code.hex(), # redeem script
witness_script.hex(), # p2wsh
script_to_p2wsh(script_code), # p2wsh addr
CScript([OP_HASH160, witness_script, OP_EQUAL]).hex(), # p2sh-p2wsh
script_to_p2sh_p2wsh(script_code)) # p2sh-p2wsh addr
开发者ID:bigpot,项目名称:bitcoin,代码行数:21,代码来源:wallet_importmulti.py
示例16: get_multisig
def get_multisig(node):
"""Generate a fresh 2-of-3 multisig on node
Returns a named tuple of privkeys, pubkeys and all address and scripts."""
addrs = []
pubkeys = []
for _ in range(3):
addr = node.getaddressinfo(node.getnewaddress())
addrs.append(addr['address'])
pubkeys.append(addr['pubkey'])
script_code = CScript([OP_2] + [hex_str_to_bytes(pubkey) for pubkey in pubkeys] + [OP_3, OP_CHECKMULTISIG])
witness_script = CScript([OP_0, sha256(script_code)])
return Multisig(privkeys=[node.dumpprivkey(addr) for addr in addrs],
pubkeys=pubkeys,
p2sh_script=CScript([OP_HASH160, hash160(script_code), OP_EQUAL]).hex(),
p2sh_addr=script_to_p2sh(script_code),
redeem_script=script_code.hex(),
p2wsh_script=witness_script.hex(),
p2wsh_addr=script_to_p2wsh(script_code),
p2sh_p2wsh_script=CScript([OP_HASH160, witness_script, OP_EQUAL]).hex(),
p2sh_p2wsh_addr=script_to_p2sh_p2wsh(script_code))
开发者ID:JeremyRubin,项目名称:bitcoin,代码行数:21,代码来源:wallet_util.py
示例17: tryUpdateInBlock
def tryUpdateInBlock (self, name, value, addr, withWitness):
"""
Tries to update the given name with a dummy witness directly in a block
(to bypass any checks done on the mempool).
"""
txHex = self.buildDummySegwitNameUpdate (name, value, addr)
tx = CTransaction ()
tx.deserialize (io.BytesIO (hex_str_to_bytes (txHex)))
tip = self.node.getbestblockhash ()
height = self.node.getblockcount () + 1
nTime = self.node.getblockheader (tip)["mediantime"] + 1
block = create_block (int (tip, 16), create_coinbase (height), nTime,
version=4)
block.vtx.append (tx)
add_witness_commitment (block, 0)
block.solve ()
blkHex = block.serialize (withWitness).hex ()
return self.node.submitblock (blkHex)
开发者ID:domob1812,项目名称:namecore,代码行数:22,代码来源:name_segwit.py
示例18: witness_script_test
def witness_script_test(self):
# Now test signing transaction to P2SH-P2WSH addresses without wallet
# Create a new P2SH-P2WSH 1-of-1 multisig address:
embedded_address = self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress())
embedded_privkey = self.nodes[1].dumpprivkey(embedded_address["address"])
p2sh_p2wsh_address = self.nodes[1].addmultisigaddress(1, [embedded_address["pubkey"]], "", "p2sh-segwit")
# send transaction to P2SH-P2WSH 1-of-1 multisig address
self.nodes[0].generate(101)
self.nodes[0].sendtoaddress(p2sh_p2wsh_address["address"], 49.999)
self.nodes[0].generate(1)
self.sync_all()
# Find the UTXO for the transaction node[1] should have received, check witnessScript matches
unspent_output = self.nodes[1].listunspent(0, 999999, [p2sh_p2wsh_address["address"]])[0]
assert_equal(unspent_output["witnessScript"], p2sh_p2wsh_address["redeemScript"])
p2sh_redeemScript = CScript([OP_0, sha256(hex_str_to_bytes(p2sh_p2wsh_address["redeemScript"]))])
assert_equal(unspent_output["redeemScript"], p2sh_redeemScript.hex())
# Now create and sign a transaction spending that output on node[0], which doesn't know the scripts or keys
spending_tx = self.nodes[0].createrawtransaction([unspent_output], {self.nodes[1].getnewaddress(): Decimal("49.998")})
spending_tx_signed = self.nodes[0].signrawtransactionwithkey(spending_tx, [embedded_privkey], [unspent_output])
# Check the signing completed successfully
assert 'complete' in spending_tx_signed
assert_equal(spending_tx_signed['complete'], True)
开发者ID:ajtowns,项目名称:bitcoin,代码行数:22,代码来源:rpc_signrawtransaction.py
示例19: sign_stake_tx
def sign_stake_tx(self, block, stake_in_value, fZPoS=False):
''' signs a coinstake transaction
:param block: (CBlock) block with stake to sign
stake_in_value: (int) staked amount
fZPoS: (bool) zerocoin stake
:return: stake_tx_signed: (CTransaction) signed tx
'''
self.block_sig_key = CECKey()
if fZPoS:
self.log.info("Signing zPoS stake...")
# Create raw zerocoin stake TX (signed)
raw_stake = self.node.createrawzerocoinstake(block.prevoutStake)
stake_tx_signed_raw_hex = raw_stake["hex"]
# Get stake TX private key to sign the block with
stake_pkey = raw_stake["private-key"]
self.block_sig_key.set_compressed(True)
self.block_sig_key.set_secretbytes(bytes.fromhex(stake_pkey))
else:
# Create a new private key and get the corresponding public key
self.block_sig_key.set_secretbytes(hash256(pack('<I', 0xffff)))
pubkey = self.block_sig_key.get_pubkey()
# Create the raw stake TX (unsigned)
scriptPubKey = CScript([pubkey, OP_CHECKSIG])
outNValue = int(stake_in_value + 2*COIN)
stake_tx_unsigned = CTransaction()
stake_tx_unsigned.nTime = block.nTime
stake_tx_unsigned.vin.append(CTxIn(block.prevoutStake))
stake_tx_unsigned.vin[0].nSequence = 0xffffffff
stake_tx_unsigned.vout.append(CTxOut())
stake_tx_unsigned.vout.append(CTxOut(outNValue, scriptPubKey))
# Sign the stake TX
stake_tx_signed_raw_hex = self.node.signrawtransaction(bytes_to_hex_str(stake_tx_unsigned.serialize()))['hex']
# Deserialize the signed raw tx into a CTransaction object and return it
stake_tx_signed = CTransaction()
stake_tx_signed.deserialize(BytesIO(hex_str_to_bytes(stake_tx_signed_raw_hex)))
return stake_tx_signed
开发者ID:benzmuircroft,项目名称:REWIRE.io,代码行数:39,代码来源:base_test.py
示例20: test_transaction_serialization
def test_transaction_serialization(self):
legacy_addr = self.nodes[0].getnewaddress("", "legacy")
p2sh_addr = self.nodes[0].getnewaddress("", "p2sh-segwit")
bech32_addr = self.nodes[0].getnewaddress("", "bech32")
self.unknown_addr = self.nodes[1].getnewaddress()
# directly seed types of utxos required
self.nodes[0].generatetoaddress(1, legacy_addr)
self.nodes[0].generatetoaddress(1, p2sh_addr)
self.nodes[0].generatetoaddress(1, bech32_addr)
self.nodes[0].generatetoaddress(101, self.unknown_addr)
# grab utxos filtering by age
legacy_utxo = self.nodes[0].listunspent(104, 104)[0]
p2sh_utxo = self.nodes[0].listunspent(103, 103)[0]
bech32_utxo = self.nodes[0].listunspent(102, 102)[0]
submitted_txids = []
self.log.info("Testing legacy UTXO")
submitted_txids.append(self.assert_tx_format_also_signed(legacy_utxo, segwit=False))
self.log.info("Testing p2sh UTXO")
submitted_txids.append(self.assert_tx_format_also_signed(p2sh_utxo, segwit=True))
self.log.info("Testing bech32 UTXO")
submitted_txids.append(self.assert_tx_format_also_signed(bech32_utxo, segwit=True))
blockhash = self.nodes[0].generate(1)[0]
hexblock = self.nodes[0].getblock(blockhash, 0)
block_details = self.nodes[0].getblock(blockhash, 2)
block = CBlock()
block.deserialize(BytesIO(hex_str_to_bytes(hexblock)))
assert(len(block.vtx) == len(submitted_txids) + 1)
assert_equal(len(block_details["tx"]), len(block.vtx))
for tx1, tx2 in zip(block.vtx[1:], block_details["tx"][1:]):
# no tuple wildcard, just re-used tx2 on first one
assert((tx1.rehash(), tx2["wtxid"]) in submitted_txids)
assert((tx2["txid"], tx2["hash"]) in submitted_txids)
assert((tx2["txid"], tx2["wtxid"]) in submitted_txids)
block.rehash()
assert_equal(block.hash, self.nodes[0].getbestblockhash())
开发者ID:ElementsProject,项目名称:elements,代码行数:39,代码来源:feature_txwitness.py
注:本文中的test_framework.util.hex_str_to_bytes函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论