Skip to content

Commit

Permalink
Add address index to return type of get_last_unused_address
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Apr 8, 2022
1 parent a12e5ed commit d73affd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ enum BdkError {
"Rusqlite",
};

dictionary AddressInformation {
u32 index;
string address;
};

enum Network {
"Bitcoin",
"Testnet",
Expand Down Expand Up @@ -120,7 +125,7 @@ interface Wallet {
[Throws=BdkError]
constructor(string descriptor, string? change_descriptor, Network network, DatabaseConfig database_config, BlockchainConfig blockchain_config);
string get_new_address();
string get_last_unused_address();
AddressInformation get_last_unused_address();
[Throws=BdkError]
u64 get_balance();
[Throws=BdkError]
Expand Down
26 changes: 21 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use bdk::keys::bip39::{Language, Mnemonic, WordCount};
use bdk::keys::{DerivableKey, ExtendedKey, GeneratableKey, GeneratedKey};
use bdk::miniscript::BareCtx;
use bdk::wallet::AddressIndex;
use bdk::wallet::AddressInfo;
use bdk::{BlockTime, Error, FeeRate, SignOptions, Wallet as BdkWallet};
use std::convert::TryFrom;
use std::str::FromStr;
Expand All @@ -22,6 +23,11 @@ uniffi_macros::include_scaffolding!("bdk");

type BdkError = Error;

pub struct AddressInformation {
pub index: u32,
pub address: String,
}

pub enum DatabaseConfig {
Memory,
Sled { config: SledDbConfiguration },
Expand Down Expand Up @@ -201,12 +207,22 @@ impl Wallet {
.to_string()
}

fn get_last_unused_address(&self) -> String {
self.get_wallet()
// fn get_last_unused_address(&self) -> String {
// self.get_wallet()
// .get_address(AddressIndex::LastUnused)
// .unwrap()
// .address
// .to_string()
// }

fn get_last_unused_address(&self) -> AddressInformation {
let address_info = self.get_wallet()
.get_address(AddressIndex::LastUnused)
.unwrap()
.address
.to_string()
.unwrap();
return AddressInformation {
index: address_info.index,
address: address_info.address.to_string()
}
}

fn get_balance(&self) -> Result<u64, Error> {
Expand Down

0 comments on commit d73affd

Please sign in to comment.