Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-replay-protection.py
Show First 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
private_key.set_secretbytes(b"replayprotection") | private_key.set_secretbytes(b"replayprotection") | ||||
public_key = private_key.get_pubkey() | public_key = private_key.get_pubkey() | ||||
# This is a little handier to use than the version in blocktools.py | # This is a little handier to use than the version in blocktools.py | ||||
def create_fund_and_spend_tx(spend, forkvalue=0): | def create_fund_and_spend_tx(spend, forkvalue=0): | ||||
# Fund transaction | # Fund transaction | ||||
script = CScript([public_key, OP_CHECKSIG]) | script = CScript([public_key, OP_CHECKSIG]) | ||||
txfund = create_transaction( | txfund = create_transaction( | ||||
spend.tx, spend.n, b'', 50 * COIN, script) | spend.tx, spend.n, b'', 50 * COIN - 1000, script) | ||||
txfund.rehash() | txfund.rehash() | ||||
# Spend transaction | # Spend transaction | ||||
txspend = CTransaction() | txspend = CTransaction() | ||||
txspend.vout.append(CTxOut(50 * COIN - 1000, CScript([OP_TRUE]))) | txspend.vout.append(CTxOut(50 * COIN - 2000, CScript([OP_TRUE]))) | ||||
txspend.vin.append(CTxIn(COutPoint(txfund.sha256, 0), b'')) | txspend.vin.append(CTxIn(COutPoint(txfund.sha256, 0), b'')) | ||||
# Sign the transaction | # Sign the transaction | ||||
sighashtype = (forkvalue << 8) | SIGHASH_ALL | SIGHASH_FORKID | sighashtype = (forkvalue << 8) | SIGHASH_ALL | SIGHASH_FORKID | ||||
sighash = SignatureHashForkId( | sighash = SignatureHashForkId( | ||||
script, txspend, 0, sighashtype, 50 * COIN) | script, txspend, 0, sighashtype, 50 * COIN - 1000) | ||||
sig = private_key.sign(sighash) + \ | sig = private_key.sign(sighash) + \ | ||||
bytes(bytearray([SIGHASH_ALL | SIGHASH_FORKID])) | bytes(bytearray([SIGHASH_ALL | SIGHASH_FORKID])) | ||||
txspend.vin[0].scriptSig = CScript([sig]) | txspend.vin[0].scriptSig = CScript([sig]) | ||||
txspend.rehash() | txspend.rehash() | ||||
return [txfund, txspend] | return [txfund, txspend] | ||||
def send_transaction_to_mempool(tx): | def send_transaction_to_mempool(tx): | ||||
▲ Show 20 Lines • Show All 141 Lines • Show Last 20 Lines |