Skip to content

Commit bc8d6a3

Browse files
committed
Merge #1178: LocalChain with hardwired genesis block
f1b112e docs(bitcoind_rpc): update docs for `Emitter::new` (志宇) 9a250ba chore: make clippy happy (志宇) 79b84be feat(bdk): changeset's `Append` impl checks that network is consistent (志宇) 06a956a feat!: change `load_from_persistence` to return an option (志宇) c3265e2 test(bdk): add tests for wallet constructor methods (志宇) 96f1d94 test(file_store): add construction method tests (志宇) 1886dc4 chore(examples): use `Wallet::new_or_load` method where appropriate (志宇) 24994a3 feat(file_store)!: have separate methods for creating and opening Store (志宇) d294e2e feat(wallet)!: add `new_or_load` methods (志宇) 7c6cbc4 chore(file_store): rm empty test file (志宇) 6cf3963 feat(bdk)!: have separate methods for creating and loading `Wallet` (志宇) 7d5f31f feat(chain, file_store): add `is_empty` method to `PersistBackend` trait (志宇) 5998a22 feat!: `LocalChain` with hardwired genesis checkpoint (志宇) Pull request description: closes #1079 closes #1107 ### Description Many methods of `TxGraph` require a `chain_tip: BlockId` input to use against a `ChainOracle` implementation. This is used to ask the `ChainOracle` implementation whether a certain block exists in the chain identified by the `chain_tip`. This guarantees that the `TxGraph` methods will return a consistent history of transactions. However, the `ChainOracle` trait's `get_chain_tip` method returns an option of `BlockId`. It becomes unclear what to do when `get_chain_tip` returns `None`. This PR changes the `ChainOracle::get_chain_tip` method to always return a `BlockId` (no `Option`). `LocalChain` now hardwires the genesis block in order to implement `ChainOracle`. `bdk::Wallet` and `bdk_file_store::Store` are changed to have separate constructor methods for initializing a fresh instance and recovering a previous instance from persistence. ### Notes to the reviewers ### Changelog notice - Changed `ChainOracle::get_chain_tip` method to return a `BlockId` instead of an `Option` of a `BlockId`. - Refactored `LocalChain` so that the genesis `BlockId` is hardwired. This way, the `ChainOracle::get_chain_tip` implementation can always return a tip. - Add `is_empty` method to `PersistBackend`. This returns true when there is no data in the persistence. - Changed `Wallet::new` to initialize a fresh wallet only. - Added `Wallet::load` to restore an instance of a wallet. - Replaced `Store::new` with separate methods to create/open the database file. ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### New Features: * [x] I've added tests for the new feature * [x] I've added docs for the new feature Top commit has no ACKs. Tree-SHA512: 31b75fb53cc451f1fce7e409f1112c43973db7e8b5b31640e01e5b52089683b60320565427d6ea0478ff4c8680dbdb9272fdab08aef69d30f257da52e731e1a3
2 parents d6a0cf0 + f1b112e commit bc8d6a3

File tree

27 files changed

+1090
-574
lines changed

27 files changed

+1090
-574
lines changed

crates/bdk/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ dev-getrandom-wasm = ["getrandom/js"]
4747
lazy_static = "1.4"
4848
env_logger = "0.7"
4949
assert_matches = "1.5.0"
50+
tempfile = "3"
51+
bdk_file_store = { path = "../file_store" }
5052

5153
[package.metadata.docs.rs]
5254
all-features = true

crates/bdk/src/wallet/coin_selection.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ mod test {
836836
let drain_script = ScriptBuf::default();
837837
let target_amount = 250_000 + FEE_AMOUNT;
838838

839-
let result = LargestFirstCoinSelection::default()
839+
let result = LargestFirstCoinSelection
840840
.coin_select(
841841
utxos,
842842
vec![],
@@ -857,7 +857,7 @@ mod test {
857857
let drain_script = ScriptBuf::default();
858858
let target_amount = 20_000 + FEE_AMOUNT;
859859

860-
let result = LargestFirstCoinSelection::default()
860+
let result = LargestFirstCoinSelection
861861
.coin_select(
862862
utxos,
863863
vec![],
@@ -878,7 +878,7 @@ mod test {
878878
let drain_script = ScriptBuf::default();
879879
let target_amount = 20_000 + FEE_AMOUNT;
880880

881-
let result = LargestFirstCoinSelection::default()
881+
let result = LargestFirstCoinSelection
882882
.coin_select(
883883
vec![],
884884
utxos,
@@ -900,7 +900,7 @@ mod test {
900900
let drain_script = ScriptBuf::default();
901901
let target_amount = 500_000 + FEE_AMOUNT;
902902

903-
LargestFirstCoinSelection::default()
903+
LargestFirstCoinSelection
904904
.coin_select(
905905
vec![],
906906
utxos,
@@ -918,7 +918,7 @@ mod test {
918918
let drain_script = ScriptBuf::default();
919919
let target_amount = 250_000 + FEE_AMOUNT;
920920

921-
LargestFirstCoinSelection::default()
921+
LargestFirstCoinSelection
922922
.coin_select(
923923
vec![],
924924
utxos,
@@ -935,7 +935,7 @@ mod test {
935935
let drain_script = ScriptBuf::default();
936936
let target_amount = 180_000 + FEE_AMOUNT;
937937

938-
let result = OldestFirstCoinSelection::default()
938+
let result = OldestFirstCoinSelection
939939
.coin_select(
940940
vec![],
941941
utxos,
@@ -956,7 +956,7 @@ mod test {
956956
let drain_script = ScriptBuf::default();
957957
let target_amount = 20_000 + FEE_AMOUNT;
958958

959-
let result = OldestFirstCoinSelection::default()
959+
let result = OldestFirstCoinSelection
960960
.coin_select(
961961
utxos,
962962
vec![],
@@ -977,7 +977,7 @@ mod test {
977977
let drain_script = ScriptBuf::default();
978978
let target_amount = 20_000 + FEE_AMOUNT;
979979

980-
let result = OldestFirstCoinSelection::default()
980+
let result = OldestFirstCoinSelection
981981
.coin_select(
982982
vec![],
983983
utxos,
@@ -999,7 +999,7 @@ mod test {
999999
let drain_script = ScriptBuf::default();
10001000
let target_amount = 600_000 + FEE_AMOUNT;
10011001

1002-
OldestFirstCoinSelection::default()
1002+
OldestFirstCoinSelection
10031003
.coin_select(
10041004
vec![],
10051005
utxos,
@@ -1018,7 +1018,7 @@ mod test {
10181018
let target_amount: u64 = utxos.iter().map(|wu| wu.utxo.txout().value).sum::<u64>() - 50;
10191019
let drain_script = ScriptBuf::default();
10201020

1021-
OldestFirstCoinSelection::default()
1021+
OldestFirstCoinSelection
10221022
.coin_select(
10231023
vec![],
10241024
utxos,

0 commit comments

Comments
 (0)