Merge pull request #67 from nuttycom/fix_zip0244_field_names

Rename scriptCode -> scriptPubKey & add zip244 test vectors.
This commit is contained in:
str4d 2022-01-13 02:45:08 +00:00 committed by GitHub
commit 69dd363272
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 20 deletions

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,7 @@
txid: [u8; 32],
auth_digest: [u8; 32],
amounts: [i64; 2],
script_codes: [Vec<u8>; 2],
script_pubkeys: [Vec<u8>; 2],
transparent_input: Option<u32>,
sighash_shielded: [u8; 32],
sighash_all: Option<[u8; 32]>,
@ -29,7 +29,7 @@
amounts: [
1800841178198868,
],
script_codes: [
script_pubkeys: [
vec![
0x65, 0x00, 0x51
],
@ -65,7 +65,7 @@
],
amounts: [
],
script_codes: [
script_pubkeys: [
],
transparent_input: None,
sighash_shielded: [
@ -90,7 +90,7 @@
],
amounts: [
],
script_codes: [
script_pubkeys: [
],
transparent_input: None,
sighash_shielded: [
@ -115,7 +115,7 @@
],
amounts: [
],
script_codes: [
script_pubkeys: [
],
transparent_input: None,
sighash_shielded: [
@ -143,7 +143,7 @@
447389782351145,
620151782842275,
],
script_codes: [
script_pubkeys: [
vec![
0xac, 0x00, 0x00
],
@ -191,7 +191,7 @@
1561051182746413,
1535468271734483,
],
script_codes: [
script_pubkeys: [
vec![
0x65, 0x6a, 0x51, 0x6a, 0xac, 0x51, 0x6a, 0x65, 0x52
],
@ -234,7 +234,7 @@
],
amounts: [
],
script_codes: [
script_pubkeys: [
],
transparent_input: None,
sighash_shielded: [
@ -262,7 +262,7 @@
1685382316228727,
1715663111103469,
],
script_codes: [
script_pubkeys: [
vec![
0x65, 0x6a
],
@ -307,7 +307,7 @@
316847576141144,
1780844721475339,
],
script_codes: [
script_pubkeys: [
vec![
0x00, 0x65, 0x51, 0xac, 0x65, 0x63, 0x00, 0x53
],
@ -351,7 +351,7 @@
1399781968202734,
1999413718097392,
],
script_codes: [
script_pubkeys: [
vec![
0x00, 0x53, 0x00
],

File diff suppressed because one or more lines are too long

View File

@ -223,7 +223,7 @@ def auth_digest(tx):
class TransparentInput(object):
def __init__(self, nIn, rand):
self.nIn = nIn
self.scriptCode = Script(rand)
self.scriptPubKey = Script(rand)
self.amount = rand.u64() % (MAX_MONEY + 1)
def signature_digest(tx, t_inputs, nHashType, txin):
@ -246,7 +246,7 @@ def transparent_sig_digest(tx, t_inputs, nHashType, txin):
digest.update(hash_type(tx, nHashType, txin))
digest.update(prevouts_sig_digest(tx, nHashType))
digest.update(amounts_sig_digest(t_inputs, nHashType))
digest.update(script_codes_sig_digest(t_inputs, nHashType))
digest.update(scriptpubkeys_sig_digest(t_inputs, nHashType))
digest.update(sequence_sig_digest(tx, nHashType))
digest.update(outputs_sig_digest(tx, nHashType, txin))
digest.update(txin_sig_digest(tx, txin))
@ -287,12 +287,12 @@ def amounts_sig_digest(t_inputs, nHashType):
else:
return blake2b(digest_size=32, person=b'ZTxTrAmountsHash').digest()
def script_codes_sig_digest(t_inputs, nHashType):
def scriptpubkeys_sig_digest(t_inputs, nHashType):
# If the SIGHASH_ANYONECANPAY flag is not set:
if not (nHashType & SIGHASH_ANYONECANPAY):
digest = blake2b(digest_size=32, person=b'ZTxTrScriptsHash')
for x in t_inputs:
digest.update(bytes(x.scriptCode))
digest.update(bytes(x.scriptPubKey))
return digest.digest()
else:
return blake2b(digest_size=32, person=b'ZTxTrScriptsHash').digest()
@ -325,7 +325,7 @@ def txin_sig_digest(tx, txin):
if txin is not None:
digest.update(bytes(tx.vin[txin.nIn].prevout))
digest.update(struct.pack('<Q', txin.amount))
digest.update(bytes(txin.scriptCode))
digest.update(bytes(txin.scriptPubKey))
digest.update(struct.pack('<I', tx.vin[txin.nIn].nSequence))
return digest.digest()
@ -382,7 +382,7 @@ def main():
'txid': txid,
'auth_digest': auth,
'amounts': [x.amount for x in t_inputs],
'script_codes': [x.scriptCode.raw() for x in t_inputs],
'script_pubkeys': [x.scriptPubKey.raw() for x in t_inputs],
'transparent_input': None if txin is None else txin.nIn,
'sighash_shielded': sighash_shielded,
'sighash_all': other_sighashes.get(SIGHASH_ALL),
@ -401,7 +401,7 @@ def main():
('txid', '[u8; 32]'),
('auth_digest', '[u8; 32]'),
('amounts', '[i64; %d]' % len(t_inputs)),
('script_codes', {
('script_pubkeys', {
'rust_type': '[Vec<u8>; %d]' % len(t_inputs),
'bitcoin_flavoured': False,
}),