def __init__(self, scriptpubkey, block_height: int, reward, wtx_merkle_root): inputs = [] inputs.append(Input("0" * 64, int("f" * 8, 16), "%016x" % block_height)) outputs = [ Output(int(reward * 10**8), scriptpubkey), Output(0, "6a%02x%s" % (len(wtx_merkle_root) * 2, wtx_merkle_root)) ] super().__init__(inputs, outputs, 0)
def from_dict(dict): inputs = [ Input(input['txid'], input['vout'], input['scriptsig']) for input in dict['inputs'] ] outputs = [ Output(output['value'], output['scriptpubkey']) for output in dict['outputs'] ] return Transaction(inputs, outputs, dict['locktime'])
def deserialize_sw_transaction(stx: str): cur = 0 version = int(reverse_bytes(stx[cur:cur + 8]), 16) cur += 8 cur += 4 inputs_count = int(stx[cur:cur + 2], 16) cur += 2 inputs = [] for i in range(inputs_count): txid = reverse_bytes(stx[cur:cur + 64]) cur += 64 vout = int(reverse_bytes(stx[cur:cur + 8]), 16) cur += 8 len = int(stx[cur:cur + 2], 16) cur += 2 scriptsig = stx[cur:cur + len * 2] cur += len * 2 cur += 8 # skipping sequence inputs.append(Input(txid, vout, scriptsig)) outputs_count = int(stx[cur:cur + 2], 16) cur += 2 outputs = [] for i in range(outputs_count): value = int(reverse_bytes(stx[cur:cur + 16]), 16) cur += 16 len = int(stx[cur:cur + 2], 16) cur += 2 scriptpubkey = stx[cur:cur + len * 2] cur += len * 2 outputs.append(Output(value, scriptpubkey)) witness_count = int(stx[cur:cur + 2], 16) cur += 2 witness = [] for i in range(witness_count): len = int(stx[cur:cur + 2], 16) cur += 2 wit = stx[cur:cur + len * 2] cur += len * 2 witness.append(wit) locktime = int(reverse_bytes(stx[cur:cur + 8]), 16) return Transaction(inputs, outputs, locktime, version=version, witness=witness)
def test_wtxid_for_nonsw_transaction(self): inputs = [ Input( "fc9e4f9c334d55c1dc535bd691a1c159b0f7314c54745522257a905e18a56779", 1, "47304402206a2eb16b7b92051d0fa38c133e67684ed064effada1d7f925c842da401d4f22702201f196b10e6e4b4a9fff948e5c5d71ec5da53e90529c8dbd122bff2b1d21dc8a90121039b7bcd0824b9a9164f7ba098408e63e5b7e3cf90835cceb19868f54f8961a825" ) ] outputs = [ Output(2207563, "76a914db4d1141d0048b1ed15839d0b7a4c488cd368b0e88ac") ] tx = Transaction(inputs, outputs, locktime=0) self.assertEqual(tx.txid, tx.wtxid)
def from_dict(dict): version = dict['version'] inputs = [ Input(input['txid'], input['vout'], input['scriptsig']) for input in dict['inputs'] ] outputs = [ Output(output['value'], output['scriptpubkey']) for output in dict['outputs'] ] witness = [wint for wint in dict['witness']] return Transaction(inputs, outputs, dict['locktime'], version=version, witness=witness)
def test_raw_transaction_creation(self): inputs = [ Input( "fc9e4f9c334d55c1dc535bd691a1c159b0f7314c54745522257a905e18a56779", 1, "47304402206a2eb16b7b92051d0fa38c133e67684ed064effada1d7f925c842da401d4f22702201f196b10e6e4b4a9fff948e5c5d71ec5da53e90529c8dbd122bff2b1d21dc8a90121039b7bcd0824b9a9164f7ba098408e63e5b7e3cf90835cceb19868f54f8961a825" ) ] outputs = [ Output(2207563, "76a914db4d1141d0048b1ed15839d0b7a4c488cd368b0e88ac") ] tx = Transaction(inputs, outputs, locktime=0) raw_tx = "01000000017967a5185e907a25225574544c31f7b059c1a191d65b53dcc1554d339c4f9efc010000006a47304402206a2eb16b7b92051d0fa38c133e67684ed064effada1d7f925c842da401d4f22702201f196b10e6e4b4a9fff948e5c5d71ec5da53e90529c8dbd122bff2b1d21dc8a90121039b7bcd0824b9a9164f7ba098408e63e5b7e3cf90835cceb19868f54f8961a825ffffffff014baf2100000000001976a914db4d1141d0048b1ed15839d0b7a4c488cd368b0e88ac00000000" self.assertEqual(raw_tx, Serializer.serialize_transaction(tx))
def __init__(self, scriptpubkey, block_height: int): inputs = [] inputs.append(Input("0" * 64, int("f" * 8, 16), "%016x" % block_height)) outputs = [Output(5000000000, scriptpubkey)] super().__init__(inputs, outputs, 0)