Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rust/Bitcoin/Utxo] Great Migration towards tw_bitcoin and tw_utxo #3382

Merged
merged 371 commits into from
Sep 19, 2023
Merged
Changes from 1 commit
Commits
Show all changes
371 commits
Select commit Hold shift + click to select a range
7a466b4
add signing logic to modules/signer
lamafab Aug 15, 2023
1e73554
remove unused imports
lamafab Aug 15, 2023
fc1de72
unify BitcoinV2 and Utxo locktime
lamafab Aug 15, 2023
d15e1ad
add fee calculation to utxo_proto
lamafab Aug 15, 2023
f887715
add convenience function for lock_time conversion
lamafab Aug 15, 2023
e0e1e98
add weight projection for pre_images
lamafab Aug 15, 2023
878fe0f
add mechanism for fee calculation, input selection and change output …
lamafab Aug 15, 2023
5dc44c6
remove previously attempted fee/selectio mechanism from tw_bitcoin
lamafab Aug 15, 2023
b989146
add input_selector to protobuf structes, handle logic
lamafab Aug 16, 2023
25b182e
use protobuf structures directly for sighash_input_p2pkh_output_p2pkh
lamafab Aug 16, 2023
587f1b7
use protobuf types directly for segwit tests
lamafab Aug 16, 2023
07d2586
deprecate builder types
lamafab Aug 16, 2023
dd1f32f
add tests for input selection
lamafab Aug 16, 2023
d2507f6
expand error types in tw_utxo
lamafab Aug 16, 2023
86ecd13
init Error type for BitcoinV2
lamafab Aug 16, 2023
6ca3d77
wrap over *_impl functions
lamafab Aug 16, 2023
21c711d
handle additional unwraps
lamafab Aug 16, 2023
d5acb30
add custom From<T> handlers for certain error types
lamafab Aug 16, 2023
c6c07fd
more error handling
lamafab Aug 16, 2023
aad1f53
update error value on wpubkey_hash
lamafab Aug 16, 2023
409ab2e
wrap tw_build_p2pkh_script FFI function over OutputBuilder
lamafab Aug 16, 2023
b8c24e3
update comments in protobuf
lamafab Aug 17, 2023
294c316
expose 'one_prevout' only to taproot
lamafab Aug 17, 2023
496ab5c
remove control_block field from Brc20Inscription
lamafab Aug 17, 2023
f83cc76
correctly pass on sighash type for signature construction
lamafab Aug 17, 2023
864d4d7
add comments
lamafab Aug 17, 2023
facca43
add additional comments
lamafab Aug 17, 2023
e4725cb
add test for tw_build_p2pkh_script
lamafab Aug 17, 2023
93ed0d7
add tests for tw_build_p2wpkh_script and tw_build_p2tr_key_path_script
lamafab Aug 17, 2023
34c5ad0
test ffi_tw_build_brc20_transfer_inscription
lamafab Aug 17, 2023
6ab0f11
boilerplate for ffi_tw_bitcoin_build_nft_inscription
lamafab Aug 17, 2023
901e54d
add P2PKH address handler
lamafab Aug 17, 2023
830c18d
complete mechanism for deriving transaction type from the address itself
lamafab Aug 17, 2023
bc5ea64
expand legacy taproot_build_and_sign_transaction
lamafab Aug 17, 2023
51ac185
add outputs
lamafab Aug 17, 2023
8ddda26
add extra comments
lamafab Aug 17, 2023
771a2b1
correctly set change_output
lamafab Aug 17, 2023
5451021
add note on unhandled legacy fields
lamafab Aug 17, 2023
53e973d
start with processing the singing output for legacy struct
lamafab Aug 17, 2023
f347697
add taproot_payload to TransactionOutput
lamafab Aug 17, 2023
f3eed41
update comment
lamafab Aug 17, 2023
444e67c
move FFI functions to legacy module
lamafab Aug 17, 2023
887a15d
move transaction types into transactions module
lamafab Aug 17, 2023
0c0a6af
deprecate additional, unused functions
lamafab Aug 17, 2023
a2e30a5
move TaprootScript and TaprootProgram to transactions module
lamafab Aug 17, 2023
42383df
rename Ticker to Brc20Ticker
lamafab Aug 17, 2023
e1a567c
track tests for main coin entry
lamafab Aug 17, 2023
5f3713f
get rid of a bunch of todos
lamafab Aug 17, 2023
ce725b2
handle more TODOs
lamafab Aug 17, 2023
2643084
add sequence field to input
lamafab Aug 17, 2023
04abc9b
add comments
lamafab Aug 17, 2023
f07664b
add signing method and leaf hash as parameter
lamafab Aug 17, 2023
1e6ebc5
expand custom ScriptWitness message
lamafab Aug 17, 2023
237fb54
update formatting
lamafab Aug 17, 2023
a2a3ce7
add change output test
lamafab Aug 21, 2023
fbad597
add test no_change_output
lamafab Aug 21, 2023
348f632
add test multiple_inputs_and_outputs
lamafab Aug 21, 2023
d40c95b
change tests/common module structure
lamafab Aug 21, 2023
a99b444
explicitly check returned outputs from preimage_hashes
lamafab Aug 21, 2023
17325e2
combine input_selector_all with change output
lamafab Aug 21, 2023
8a62316
add change output creation to input_selector_select_ascending
lamafab Aug 21, 2023
75d80f7
add input_selector_one_input_cannot_cover_fees test
lamafab Aug 21, 2023
3d1e327
remove change_output module, redundant
lamafab Aug 21, 2023
c46efb2
add test input_selector_empty_script_bufs
lamafab Aug 21, 2023
6020291
move change output scriptPubkey check at the start of function
lamafab Aug 21, 2023
f90436a
add test for p2pkh weight projection
lamafab Aug 22, 2023
9c0d96e
add p2wpkh_fee_projection
lamafab Aug 22, 2023
8805b9a
add test p2tr_key_path_fee_projection
lamafab Aug 22, 2023
3f5c735
add brc20_inscribe_fee_projection test
lamafab Aug 22, 2023
824d3ac
rename *_projection to *_estimate
lamafab Aug 22, 2023
e870866
update fee estimate in utxo tests
lamafab Aug 22, 2023
0deb30c
get rid of warnings
lamafab Aug 22, 2023
cdf8f5f
add OrdinalInscription to protobuf and implement builder pattern
lamafab Aug 22, 2023
9e28ad7
implement claiming mechanism for Ordinal inscriptions
lamafab Aug 22, 2023
52bcd80
add builder for Ordinal nft outputs, add coin_entry_sign_ordinal_nft_…
lamafab Aug 22, 2023
01ff78f
separate coin-entry tests into individual modules
lamafab Aug 22, 2023
6c7331e
restructure how inputs/outputs are included
lamafab Aug 22, 2023
5215232
expand input builder for P2SH
lamafab Aug 22, 2023
f8ff46e
use redeem script instead of script hash in P2SH builder
lamafab Aug 22, 2023
61cca7d
add output builder for P2SH
lamafab Aug 22, 2023
2100e0f
extend input builder for P2WSH
lamafab Aug 22, 2023
91cdd06
implement claiming mechanism for P2WSH
lamafab Aug 22, 2023
d26ab5e
implement output builder for P2WSH
lamafab Aug 22, 2023
de3f516
update numbering of Sighash types
lamafab Aug 23, 2023
605241e
add explicit enable_zero_sequence field
lamafab Aug 23, 2023
a4cb559
update tw_bitcoin to enable_zero_sequence adjustment
lamafab Aug 23, 2023
17e67d1
add test for zero sequence usage
lamafab Aug 23, 2023
1394457
rename enable_zero_sequence to sequence_enable_zero
lamafab Aug 23, 2023
fc1a8f8
create a separate function for deriving transaction type from address
lamafab Aug 23, 2023
b19c646
add tests for automatically deriving transaction type from address
lamafab Aug 23, 2023
9260880
add test send_to_p2tr_key_path_address
lamafab Aug 23, 2023
e757643
remove unused imports
lamafab Aug 23, 2023
c693613
make it explicit that p2tr_tweaked is dangerous
lamafab Aug 23, 2023
c74289d
rename script_pubkey to custom_script_pubkey in builder, convert from…
lamafab Aug 23, 2023
caaf3cb
extend Proto to LegacyProto conversion
lamafab Aug 23, 2023
803023a
expand input_from_legacy_utxo, correctly derive builders from provide…
lamafab Aug 23, 2023
aaaf06b
pass individual private keys and redeem script to input_from_legacy_utxo
lamafab Aug 23, 2023
e91f4c2
add error handling to legacy tw_taproot_build_and_sign_transaction
lamafab Aug 23, 2023
3957441
complete tw_bitcoin_build_nft_inscription implementation
lamafab Aug 23, 2023
d102a01
cleanup leftover from rebase
lamafab Aug 24, 2023
3e0f95d
use fixed signature in coin_entry_sign_brc20_commit_reveal_transfer
lamafab Aug 24, 2023
32efa6d
used fixed RNG for coin_entry_sign_ordinal_nft_commit_reveal_transfer…
lamafab Aug 24, 2023
9d88b17
complete legacy test ffi_tw_bitcoin_build_nft_inscription
lamafab Aug 24, 2023
cd88743
add utxo related errors to BitconV2.proto
lamafab Aug 24, 2023
f125088
convert errors between tw_utxo and tw_bitcoin, handle returns
lamafab Aug 24, 2023
6b7fba1
explicitly prefix utxo related errors with *_utxo_*
lamafab Aug 24, 2023
1bd42dc
add txid field to Utxo output
lamafab Aug 24, 2023
be0fc46
correctly return txid
lamafab Aug 24, 2023
6ead03f
test returned transaction ID in BRC20 tests
lamafab Aug 24, 2023
742701b
explicitly test transaction id in Ordinal nft tests
lamafab Aug 24, 2023
3c947c4
remove some TODO comments
lamafab Aug 24, 2023
3ef184e
rename amount to value in utxo
lamafab Aug 24, 2023
08ec9bc
rename amount to value in tw_bitcoin
lamafab Aug 24, 2023
ca8a85b
rename sat_vb to fee_per_vb
lamafab Aug 24, 2023
a3d6a1d
remove two items from note comment
lamafab Aug 24, 2023
aad6c59
continue with legacy taproot_build_and_sign test
lamafab Aug 25, 2023
1e609e1
return explicit error in tw_taproot_build_and_sign_transaction
lamafab Aug 25, 2023
9e8e578
create custom error variant for invalid change_output
lamafab Aug 25, 2023
ad2c3bc
set the correct sequence
lamafab Aug 25, 2023
3d98cad
add FFI signing tests for P2WPKH and P2TR
lamafab Aug 25, 2023
3caae15
test FFI legacy P2TR key-path spend
lamafab Aug 25, 2023
0b77e15
small cleanup
lamafab Aug 25, 2023
aaeaacf
test claming P2TR complex script via FFI
lamafab Aug 25, 2023
6c88f67
remove unnecessariy inputs from FFI signing tests
lamafab Aug 25, 2023
67215fd
fix warnings
lamafab Aug 25, 2023
0995ef5
add extra error handling and comments
lamafab Aug 28, 2023
14b88a5
add a SelectInOrder variant to InputSelector
lamafab Aug 28, 2023
9140bff
add automatic input selection to legacy building, but do not order
lamafab Aug 28, 2023
8b42ff0
fix field numbering in Utxo.proto and BitcoinV2.proto
lamafab Aug 28, 2023
142f86c
reintroduce tw_bitcoin_calculate_transaction_fee
lamafab Aug 28, 2023
6ea7225
fix all C++ issues; correctly set sequence and un-reverse Txid return
lamafab Aug 28, 2023
64c4ba2
remove txid reversal check in tests
lamafab Aug 28, 2023
22bc090
remove address function, remove unused Recipient methods
lamafab Aug 28, 2023
a392554
remove some unwraps
lamafab Aug 28, 2023
7b0e683
clear all uwnraps
lamafab Aug 28, 2023
84b6c23
implement parse_address
lamafab Aug 28, 2023
7ad852a
implement derive_address
lamafab Aug 28, 2023
2e2c853
add test input_selector_select_ascending
lamafab Aug 28, 2023
e05579e
add comments to entry
lamafab Aug 28, 2023
332aaaa
add comments to fields in BitcoinV2.proto
lamafab Aug 28, 2023
2557d2e
update comments
lamafab Aug 28, 2023
d6ba406
add comments to fields in Utxo.proto
lamafab Aug 28, 2023
5b2292c
trigger CI
lamafab Aug 28, 2023
3ea2d6a
remove unnecessary to_vec
lamafab Aug 28, 2023
2288beb
revert changes to Podfile.lock
lamafab Aug 28, 2023
73f91ae
bump wallet-core-kotlin version
lamafab Aug 28, 2023
8fa0783
use iter() directly
lamafab Aug 28, 2023
447d516
formatting
lamafab Aug 28, 2023
b625196
derive P2SH transaction types from address
lamafab Aug 28, 2023
97ae310
dervice both P2WPKH and P2WSH transaction types from address
lamafab Aug 28, 2023
31320cf
fix typo
lamafab Aug 28, 2023
4fab3f8
add comments to InputSelector variants
lamafab Aug 28, 2023
ad050a9
remove unused imports from proto file
lamafab Aug 28, 2023
2b1ff47
add prefix to certain BitcoinV2 proto types
lamafab Aug 28, 2023
f516471
formatting
lamafab Aug 28, 2023
9db3403
fix typo, remove unused import
lamafab Aug 29, 2023
ab1657d
remove unused BRC20 mint and deploy types
lamafab Aug 29, 2023
fbda3f5
remove deprecated utils module
lamafab Aug 29, 2023
2561766
simplify BRC20 payload structure
lamafab Aug 29, 2023
72676b4
make certain modules private
lamafab Aug 29, 2023
e81dba8
deprecate Recipient type and module
lamafab Aug 29, 2023
e8fece8
move protobuf aliases to lib.rs, update imports
lamafab Aug 29, 2023
81051cc
update comments
lamafab Aug 29, 2023
bcd7022
move tests/ outside src/
lamafab Aug 29, 2023
bddc727
add explicit, separate test for P2PKH
lamafab Aug 29, 2023
2a12418
attempt at claiming P2SH input
lamafab Aug 29, 2023
4aa52ea
add comments
lamafab Aug 30, 2023
5b7a4ff
rename custom to custom_script
lamafab Aug 30, 2023
844e0c2
add ticker tests to brc20.rs
lamafab Aug 30, 2023
8ffe130
add dangerous_use_fixed_schnorr_rng to SigningInput for testing
lamafab Aug 30, 2023
3764f3c
test non-deterministic transactions in legacy module
lamafab Aug 30, 2023
cb6292e
add comments to legacy_build_sign
lamafab Aug 30, 2023
a0bfea4
cleanup dbg and println statements
lamafab Aug 30, 2023
4ef9327
allow dead_code in tests/common/mod.rs
lamafab Aug 30, 2023
2a3dfe6
update coverage.stats, set P2SH to todo
lamafab Aug 30, 2023
0b1ff48
Merge branch 'tw-utxo-update-tests' into integrate-tw-utxo-restruct
lamafab Aug 30, 2023
52d58bb
bump field numbers
lamafab Aug 30, 2023
4a5acce
rename p2sh_script_sig to script_sig
lamafab Aug 30, 2023
76dd48b
add comment to script_sig in Utxo.proto
lamafab Aug 30, 2023
b505a13
attempt at completing P2SH test
lamafab Aug 30, 2023
febd493
add TWBitcoinV2 header to include
lamafab Aug 30, 2023
3c6866b
add bitcoin related FFI entries to wallet_core_rs, add cpp source cal…
lamafab Aug 30, 2023
4731a38
cleanup debug and println statements
lamafab Aug 30, 2023
b46f69d
Merge branch 'integrate-tw-utxo-restruct-cleanups' into integrate-tw-…
lamafab Aug 30, 2023
6103975
adjust coverage.stats
lamafab Aug 30, 2023
c24d337
add docs to TWBitcoinV2 functions in header
lamafab Aug 31, 2023
538c2bf
add C++ test for TWBitcoinV2Sign
lamafab Aug 31, 2023
3ec8a80
deprecate BitcoinV2 FFI functions, not needed
lamafab Aug 31, 2023
a4e648b
use constants in tests
lamafab Aug 31, 2023
4971bbe
add tests for derving scriptPubkey from P2SH and P2WSH addresses
lamafab Aug 31, 2023
ddb4354
add comment
lamafab Aug 31, 2023
f91367e
add tests for P2TR script-path input/output buildres
lamafab Aug 31, 2023
435f204
track p2tr_script_path file
lamafab Aug 31, 2023
8873cc0
rename public_key to internal_key in OutputTaprootScriptPath
lamafab Aug 31, 2023
2ef4d94
extend tw_any_coin tests with Bitcoin variant
lamafab Aug 31, 2023
9311bf9
remove unneeded derives for TaprootScript and TaprootProgram
lamafab Aug 31, 2023
cb88a82
add individual private_key entry to Input
lamafab Aug 31, 2023
cc9aa11
correctly sign P2SH inputs (finallygit add -u)
lamafab Sep 4, 2023
4e303ea
correctly sign P2WSH inputs
lamafab Sep 4, 2023
d6e3cd0
update some error variants
lamafab Sep 4, 2023
78dbb33
cleanup input builder a little
lamafab Sep 4, 2023
c1ddfd9
rename output to signed
lamafab Sep 4, 2023
a036456
remove deprecated script_sig from tw_utxo tests
lamafab Sep 4, 2023
75c7ea6
track p2wsh
lamafab Sep 4, 2023
dd21ee9
make sequence field optional
lamafab Sep 4, 2023
152befa
remove option/default fields from tests
lamafab Sep 4, 2023
d753c88
update comments in protobuf
lamafab Sep 4, 2023
2efdbc6
revert Cargo.lock changes
lamafab Sep 6, 2023
18f538b
update test_any_address_normalize_eth for Bitcoin
lamafab Sep 6, 2023
33700a9
make use of signing_output_error!
lamafab Sep 6, 2023
ece533f
remove json_signer and plan_builder
lamafab Sep 6, 2023
d8e4442
use iterator for utxo input/output conversion
lamafab Sep 6, 2023
480b4ae
remove useless comment from legacy/scripts.rs
lamafab Sep 6, 2023
32b2992
move signing mechanism out of BitcoinEntry to Signer types
lamafab Sep 6, 2023
4477306
init BitcoinPlanBuilder
lamafab Sep 6, 2023
a2a109a
add ComposePlan and TransactionPlan to protobuf structures
lamafab Sep 6, 2023
d392c82
add plan_brc20 to BitcoinPlanBuilder
lamafab Sep 6, 2023
7907a88
add clone_proto_input function
lamafab Sep 6, 2023
e621085
add clone_proto_input
lamafab Sep 6, 2023
5d62d72
add txid field to PreSigningOutput
lamafab Sep 6, 2023
30b591b
fix txid rev
lamafab Sep 6, 2023
1101d92
move hard-clone functions to utils module
lamafab Sep 6, 2023
a2eafa1
make use of aliases
lamafab Sep 6, 2023
adb2966
format aliases
lamafab Sep 6, 2023
11ba2f1
add comments to plan_brc20
lamafab Sep 6, 2023
7cfa943
init plan_builder test
lamafab Sep 6, 2023
45b2852
add brc20 inscription to plan builder
lamafab Sep 6, 2023
2acd5f2
correctly select Txids
lamafab Sep 7, 2023
cd55f4f
correctly return change output
lamafab Sep 7, 2023
56330c5
expand transaction_plan_compose_brc20
lamafab Sep 7, 2023
5d90af2
expand transaction_plan_compose_brc20 test
lamafab Sep 7, 2023
46a0fb0
check tagged output
lamafab Sep 7, 2023
ce75d4b
check input of reveal transaction
lamafab Sep 7, 2023
80cea0a
check addtional basics
lamafab Sep 7, 2023
9483f46
cleanup
lamafab Sep 7, 2023
a7856f7
sign transaction plan, check txid
lamafab Sep 7, 2023
421c449
set private_key field to ComposeTransaction, add comments
lamafab Sep 7, 2023
42c2977
set fee_per_vb to zero for fixed commit/reveal transaction
lamafab Sep 7, 2023
740ab8d
Merge branch 'tw-bitcoin-plan-builder' into integrate-tw-utxo-restruct
lamafab Sep 7, 2023
8a1669f
fix formatting
lamafab Sep 7, 2023
ce5f63a
bump wallet-core-kotlin
lamafab Sep 7, 2023
df0117c
improve private key handling in legacy builders
lamafab Sep 8, 2023
b673bf2
return error if Ordinal chunk size is too large
lamafab Sep 8, 2023
09b642a
move legacy FFIs to wallet-core-rs
lamafab Sep 8, 2023
6301452
prefix FFI functions with tw_bitcoin_legacy_*
lamafab Sep 8, 2023
74ddf83
track wallet-core-rs bitcoin module
lamafab Sep 8, 2023
3542f08
formatting
lamafab Sep 8, 2023
4c84a49
return errors instead of unwrapping in plan_builder
lamafab Sep 19, 2023
6fa15fc
start handling todos in utils.rs
lamafab Sep 19, 2023
776f266
complete handling todos in utils.rs
lamafab Sep 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add convenience function for lock_time conversion
lamafab committed Aug 24, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit f887715153eeece5239c57ab4cc8c5ffca4b07b2
88 changes: 32 additions & 56 deletions rust/tw_utxo/src/compiler.rs
Original file line number Diff line number Diff line change
@@ -179,35 +179,9 @@ impl Compiler<StandardBitcoinContext> {
fn compile_impl(
proto: Proto::PreSerialization<'_>,
) -> Result<Proto::SerializedTransaction<'static>> {
let version = proto.version;

// Retreive the lock time. If none is provided, the default lock time is
// used (immediately spendable).
let lock_time = if let Some(lock_time) = proto.lock_time {
match lock_time.variant {
ProtoLockTimeVariant::blocks(block) => LockTime::Blocks(
Height::from_consensus(block)
.map_err(|_| Error::from(Proto::Error::Error_invalid_lock_time))?,
),
ProtoLockTimeVariant::seconds(secs) => LockTime::Seconds(
Time::from_consensus(secs)
.map_err(|_| Error::from(Proto::Error::Error_invalid_lock_time))?,
),
ProtoLockTimeVariant::None => LockTime::Blocks(
Height::from_consensus(0)
.map_err(|_| Error::from(Proto::Error::Error_invalid_lock_time))?,
),
}
} else {
LockTime::Blocks(
Height::from_consensus(0)
.map_err(|_| Error::from(Proto::Error::Error_invalid_lock_time))?,
)
};

let mut tx = Transaction {
version,
lock_time,
version: proto.version,
lock_time: lock_time_from_proto(&proto.lock_time)?,
input: vec![],
output: vec![],
};
@@ -256,35 +230,9 @@ impl Compiler<StandardBitcoinContext> {
}

fn convert_proto_to_tx<'a>(proto: &'a Proto::SigningInput<'a>) -> Result<Transaction> {
let version = proto.version;

// Retreive the lock time. If none is provided, the default lock time is
// used (immediately spendable).
let lock_time = if let Some(ref lock_time) = proto.lock_time {
match lock_time.variant {
ProtoLockTimeVariant::blocks(block) => LockTime::Blocks(
Height::from_consensus(block)
.map_err(|_| Error::from(Proto::Error::Error_invalid_lock_time))?,
),
ProtoLockTimeVariant::seconds(secs) => LockTime::Seconds(
Time::from_consensus(secs)
.map_err(|_| Error::from(Proto::Error::Error_invalid_lock_time))?,
),
ProtoLockTimeVariant::None => LockTime::Blocks(
Height::from_consensus(0)
.map_err(|_| Error::from(Proto::Error::Error_invalid_lock_time))?,
),
}
} else {
LockTime::Blocks(
Height::from_consensus(0)
.map_err(|_| Error::from(Proto::Error::Error_invalid_lock_time))?,
)
};

let mut tx = Transaction {
version,
lock_time,
version: proto.version,
lock_time: lock_time_from_proto(&proto.lock_time)?,
input: vec![],
output: vec![],
};
@@ -312,3 +260,31 @@ fn convert_proto_to_tx<'a>(proto: &'a Proto::SigningInput<'a>) -> Result<Transac

Ok(tx)
}

// Convenience function to retreive the lock time. If none is provided, the
// default lock time is used (immediately spendable).
fn lock_time_from_proto(proto: &Option<Proto::LockTime>) -> Result<LockTime> {
let lock_time = if let Some(lock_time) = proto {
match lock_time.variant {
ProtoLockTimeVariant::blocks(block) => LockTime::Blocks(
Height::from_consensus(block)
.map_err(|_| Error::from(Proto::Error::Error_invalid_lock_time))?,
),
ProtoLockTimeVariant::seconds(secs) => LockTime::Seconds(
Time::from_consensus(secs)
.map_err(|_| Error::from(Proto::Error::Error_invalid_lock_time))?,
),
ProtoLockTimeVariant::None => LockTime::Blocks(
Height::from_consensus(0)
.map_err(|_| Error::from(Proto::Error::Error_invalid_lock_time))?,
),
}
} else {
LockTime::Blocks(
Height::from_consensus(0)
.map_err(|_| Error::from(Proto::Error::Error_invalid_lock_time))?,
)
};

Ok(lock_time)
}