Avoid the need to specify a `rust_fmt` function for Options.

This does not change test vectors.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
Daira Hopwood 2022-02-12 20:46:02 +00:00
parent 54f168a30b
commit 1c10ad5f4a
5 changed files with 38 additions and 102 deletions

View File

@ -132,6 +132,8 @@ def tv_option_int_rust(name, value, pad):
def tv_part_rust(name, value, config, indent=3):
if 'rust_fmt' in config:
value = config['rust_fmt'](value)
elif config['rust_type'].startswith('Option<') and not (value is None or isinstance(value, Some)):
value = Some(value)
pad = ' ' * indent
if config['rust_type'] == 'Option<Vec<u8>>':

View File

@ -118,31 +118,15 @@ def main():
args,
'unified_address',
(
('p2pkh_bytes', {
'rust_type': 'Option<[u8; 20]>',
'rust_fmt': lambda x: None if x is None else Some(x),
}),
('p2sh_bytes', {
'rust_type': 'Option<[u8; 20]>',
'rust_fmt': lambda x: None if x is None else Some(x),
}),
('sapling_raw_addr', {
'rust_type': 'Option<[u8; 43]>',
'rust_fmt': lambda x: None if x is None else Some(x),
}),
('orchard_raw_addr', {
'rust_type': 'Option<[u8; 43]>',
'rust_fmt': lambda x: None if x is None else Some(x),
}),
('unknown_typecode', 'u32'),
('unknown_bytes', {
'rust_type': 'Option<Vec<u8>>',
'rust_fmt': lambda x: None if x is None else Some(x),
'bitcoin_flavoured': False,
}),
('unified_addr', {'rust_type': 'Vec<u8>', 'bitcoin_flavoured': False}),
('root_seed', {'rust_type': 'Vec<u8>', 'bitcoin_flavoured': False}),
('account', 'u32'),
('p2pkh_bytes', 'Option<[u8; 20]>'),
('p2sh_bytes', 'Option<[u8; 20]>'),
('sapling_raw_addr', 'Option<[u8; 43]>'),
('orchard_raw_addr', 'Option<[u8; 43]>'),
('unknown_typecode', 'u32'),
('unknown_bytes', {'rust_type': 'Option<Vec<u8>>', 'bitcoin_flavoured': False}),
('unified_addr', {'rust_type': 'Vec<u8>', 'bitcoin_flavoured': False}),
('root_seed', {'rust_type': 'Vec<u8>', 'bitcoin_flavoured': False}),
('account', 'u32'),
('diversifier_index', 'u32'),
),
test_vectors,

View File

@ -119,27 +119,14 @@ def main():
args,
'unified_full_viewing_keys',
(
('t_key_bytes', {
'rust_type': 'Option<[u8; 65]>',
'rust_fmt': lambda x: None if x is None else Some(x),
}),
('sapling_fvk_bytes', {
'rust_type': 'Option<[u8; 128]>',
'rust_fmt': lambda x: None if x is None else Some(x),
}),
('orchard_fvk_bytes', {
'rust_type': 'Option<[u8; 96]>',
'rust_fmt': lambda x: None if x is None else Some(x),
}),
('t_key_bytes', 'Option<[u8; 65]>'),
('sapling_fvk_bytes', 'Option<[u8; 128]>'),
('orchard_fvk_bytes', 'Option<[u8; 96]>'),
('unknown_fvk_typecode', 'u32'),
('unknown_fvk_bytes', {
'rust_type': 'Option<Vec<u8>>',
'rust_fmt': lambda x: None if x is None else Some(x),
'bitcoin_flavoured': False,
}),
('unified_fvk', {'rust_type': 'Vec<u8>', 'bitcoin_flavoured': False}),
('root_seed', {'rust_type': 'Vec<u8>', 'bitcoin_flavoured': False}),
('account', 'u32'),
('unknown_fvk_bytes', {'rust_type': 'Option<Vec<u8>>', 'bitcoin_flavoured': False}),
('unified_fvk', {'rust_type': 'Vec<u8>', 'bitcoin_flavoured': False}),
('root_seed', {'rust_type': 'Vec<u8>', 'bitcoin_flavoured': False}),
('account', 'u32'),
),
test_vectors,
)

View File

@ -115,27 +115,14 @@ def main():
args,
'unified_incoming_viewing_keys',
(
('t_key_bytes', {
'rust_type': 'Option<[u8; 65]>',
'rust_fmt': lambda x: None if x is None else Some(x),
}),
('sapling_ivk_bytes', {
'rust_type': 'Option<[u8; 64]>',
'rust_fmt': lambda x: None if x is None else Some(x),
}),
('orchard_ivk_bytes', {
'rust_type': 'Option<[u8; 64]>',
'rust_fmt': lambda x: None if x is None else Some(x),
}),
('t_key_bytes', 'Option<[u8; 65]>'),
('sapling_ivk_bytes', 'Option<[u8; 64]>'),
('orchard_ivk_bytes', 'Option<[u8; 64]>'),
('unknown_ivk_typecode', 'u32'),
('unknown_ivk_bytes', {
'rust_type': 'Option<Vec<u8>>',
'rust_fmt': lambda x: None if x is None else Some(x),
'bitcoin_flavoured': False,
}),
('unified_ivk', {'rust_type': 'Vec<u8>', 'bitcoin_flavoured': False}),
('root_seed', {'rust_type': 'Vec<u8>', 'bitcoin_flavoured': False}),
('account', 'u32'),
('unknown_ivk_bytes', {'rust_type': 'Option<Vec<u8>>', 'bitcoin_flavoured': False}),
('unified_ivk', {'rust_type': 'Vec<u8>', 'bitcoin_flavoured': False}),
('root_seed', {'rust_type': 'Vec<u8>', 'bitcoin_flavoured': False}),
('account', 'u32'),
),
test_vectors,
)

View File

@ -406,43 +406,19 @@ def main():
args,
'zip_0244',
(
('tx', {'rust_type': 'Vec<u8>', 'bitcoin_flavoured': False}),
('txid', '[u8; 32]'),
('auth_digest', '[u8; 32]'),
('amounts', {'rust_type': 'Vec<i64>'}),
('script_pubkeys', {
'rust_type': 'Vec<Vec<u8>>',
'bitcoin_flavoured': False,
}),
('transparent_input', {
'rust_type': 'Option<u32>',
'rust_fmt': lambda x: None if x is None else Some(x),
}),
('sighash_shielded', '[u8; 32]'),
('sighash_all', {
'rust_type': 'Option<[u8; 32]>',
'rust_fmt': lambda x: None if x is None else Some(x),
}),
('sighash_none', {
'rust_type': 'Option<[u8; 32]>',
'rust_fmt': lambda x: None if x is None else Some(x),
}),
('sighash_single', {
'rust_type': 'Option<[u8; 32]>',
'rust_fmt': lambda x: None if x is None else Some(x),
}),
('sighash_all_anyone', {
'rust_type': 'Option<[u8; 32]>',
'rust_fmt': lambda x: None if x is None else Some(x),
}),
('sighash_none_anyone', {
'rust_type': 'Option<[u8; 32]>',
'rust_fmt': lambda x: None if x is None else Some(x),
}),
('sighash_single_anyone', {
'rust_type': 'Option<[u8; 32]>',
'rust_fmt': lambda x: None if x is None else Some(x),
}),
('tx', {'rust_type': 'Vec<u8>', 'bitcoin_flavoured': False}),
('txid', '[u8; 32]'),
('auth_digest', '[u8; 32]'),
('amounts', 'Vec<i64>'),
('script_pubkeys', {'rust_type': 'Vec<Vec<u8>>', 'bitcoin_flavoured': False}),
('transparent_input', 'Option<u32>'),
('sighash_shielded', '[u8; 32]'),
('sighash_all', 'Option<[u8; 32]>'),
('sighash_none', 'Option<[u8; 32]>'),
('sighash_single', 'Option<[u8; 32]>'),
('sighash_all_anyone', 'Option<[u8; 32]>'),
('sighash_none_anyone', 'Option<[u8; 32]>'),
('sighash_single_anyone', 'Option<[u8; 32]>'),
),
test_vectors,
)