Skip to content

Commit

Permalink
fix: utxo pubkey find and commitment missing output
Browse files Browse the repository at this point in the history
  • Loading branch information
hensg committed Feb 8, 2024
1 parent e1570ce commit f8dae95
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 133 deletions.
6 changes: 4 additions & 2 deletions solution/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions solution/rust/balance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ fn get_p2wpkh_program(pubkey: &[u8]) -> Vec<u8> {
// https://github.com/bitcoin/bitcoin/blob/master/doc/bitcoin-conf.md#configuration-file-path
// Examples: bcli("getblockcount")
// bcli("getblockhash 100")
fn bcli(cmd: &str) -> Result<Vec<u8>, BalanceError> {
pub fn bcli(cmd: &str) -> Result<Vec<u8>, BalanceError> {
let args = cmd.split(' ').collect::<Vec<&str>>();

let result = Command::new("bitcoin-cli")
Expand Down Expand Up @@ -310,15 +310,15 @@ pub fn recover_wallet_state(
let child_key = get_child_key_at_path(deserialized_key, derivation_path);
// Compute 2000 private keys from the child key path
let private_keys = get_keys_at_child_key_path(child_key, 2000);
let mut public_keys = HashSet::new();
let mut witness_programs = HashSet::new();
let mut public_keys = vec![];
let mut witness_programs = vec![];

for key in private_keys.iter() {
let public_key = derive_public_key_from_private(&key.key);
public_keys.insert(public_key.clone());
public_keys.push(public_key.clone());

let witness_program = get_p2wpkh_program(&public_key);
witness_programs.insert(witness_program);
witness_programs.push(witness_program);
}
let mut outgoing_txs: Vec<Vec<u8>> = vec![];
let mut my_vouts_by_txid: HashMap<String, Vec<u32>> = HashMap::new();
Expand Down Expand Up @@ -529,9 +529,9 @@ pub fn recover_wallet_state(
// Return Wallet State
Ok(WalletState {
utxos,
public_keys: public_keys.into_iter().collect(),
public_keys: public_keys,
private_keys: private_keys.into_iter().map(|k| k.key.to_vec()).collect(),
witness_programs: witness_programs.into_iter().collect(),
witness_programs: witness_programs,
})
}

Expand Down
2 changes: 2 additions & 0 deletions solution/rust/spend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
balance = {path = "../balance"}
bitcoin = "0.31.1"
hex = "0.4.3"
libsecp256k1 = "0.7.1"
serde_json = "1.0.113"
sha2 = "0.10.8"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
Loading

0 comments on commit f8dae95

Please sign in to comment.