Upgrade bdk to 0.14.0
This commit is contained in:
parent
5240cd895e
commit
72f90f1d63
@ -10,7 +10,7 @@ crate-type = ["staticlib", "cdylib"]
|
|||||||
name = "bdkffi"
|
name = "bdkffi"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bdk = { version = "0.13", features = ["all-keys", "use-esplora-ureq"] }
|
bdk = { version = "0.14", features = ["all-keys", "use-esplora-ureq"] }
|
||||||
uniffi_macros = "0.14.1"
|
uniffi_macros = "0.14.1"
|
||||||
uniffi = "0.16.0"
|
uniffi = "0.16.0"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
namespace bdk {
|
namespace bdk {
|
||||||
[Throws=BdkError]
|
[Throws=BdkError]
|
||||||
ExtendedKeyInfo generate_extended_key(Network network, MnemonicType mnemonic_type, string? password);
|
ExtendedKeyInfo generate_extended_key(Network network, WordCount word_count, string? password);
|
||||||
[Throws=BdkError]
|
[Throws=BdkError]
|
||||||
ExtendedKeyInfo restore_extended_key(Network network, string mnemonic, string? password);
|
ExtendedKeyInfo restore_extended_key(Network network, string mnemonic, string? password);
|
||||||
};
|
};
|
||||||
@ -73,7 +73,7 @@ dictionary TransactionDetails {
|
|||||||
string txid;
|
string txid;
|
||||||
};
|
};
|
||||||
|
|
||||||
dictionary Confirmation {
|
dictionary BlockTime {
|
||||||
u32 height;
|
u32 height;
|
||||||
u64 timestamp;
|
u64 timestamp;
|
||||||
};
|
};
|
||||||
@ -81,7 +81,7 @@ dictionary Confirmation {
|
|||||||
[Enum]
|
[Enum]
|
||||||
interface Transaction {
|
interface Transaction {
|
||||||
Unconfirmed(TransactionDetails details);
|
Unconfirmed(TransactionDetails details);
|
||||||
Confirmed(TransactionDetails details, Confirmation confirmation);
|
Confirmed(TransactionDetails details, BlockTime confirmation);
|
||||||
};
|
};
|
||||||
|
|
||||||
interface OfflineWallet {
|
interface OfflineWallet {
|
||||||
@ -158,7 +158,7 @@ dictionary ExtendedKeyInfo {
|
|||||||
string fingerprint;
|
string fingerprint;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum MnemonicType {
|
enum WordCount {
|
||||||
"Words12",
|
"Words12",
|
||||||
"Words15",
|
"Words15",
|
||||||
"Words18",
|
"Words18",
|
||||||
|
26
src/lib.rs
26
src/lib.rs
@ -8,11 +8,11 @@ use bdk::blockchain::{
|
|||||||
};
|
};
|
||||||
use bdk::database::any::{AnyDatabase, SledDbConfiguration};
|
use bdk::database::any::{AnyDatabase, SledDbConfiguration};
|
||||||
use bdk::database::{AnyDatabaseConfig, ConfigurableDatabase};
|
use bdk::database::{AnyDatabaseConfig, ConfigurableDatabase};
|
||||||
use bdk::keys::bip39::{Language, Mnemonic, MnemonicType};
|
use bdk::keys::bip39::{Language, Mnemonic, WordCount};
|
||||||
use bdk::keys::{DerivableKey, ExtendedKey, GeneratableKey, GeneratedKey};
|
use bdk::keys::{DerivableKey, ExtendedKey, GeneratableKey, GeneratedKey};
|
||||||
use bdk::miniscript::BareCtx;
|
use bdk::miniscript::BareCtx;
|
||||||
use bdk::wallet::AddressIndex;
|
use bdk::wallet::AddressIndex;
|
||||||
use bdk::{ConfirmationTime, Error, FeeRate, SignOptions, Wallet};
|
use bdk::{BlockTime, Error, FeeRate, SignOptions, Wallet};
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::{Mutex, MutexGuard};
|
use std::sync::{Mutex, MutexGuard};
|
||||||
@ -69,8 +69,6 @@ pub struct TransactionDetails {
|
|||||||
pub txid: String,
|
pub txid: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
type Confirmation = ConfirmationTime;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum Transaction {
|
pub enum Transaction {
|
||||||
Unconfirmed {
|
Unconfirmed {
|
||||||
@ -78,7 +76,7 @@ pub enum Transaction {
|
|||||||
},
|
},
|
||||||
Confirmed {
|
Confirmed {
|
||||||
details: TransactionDetails,
|
details: TransactionDetails,
|
||||||
confirmation: Confirmation,
|
confirmation: BlockTime,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,9 +94,9 @@ impl From<&bdk::TransactionDetails> for TransactionDetails {
|
|||||||
impl From<&bdk::TransactionDetails> for Transaction {
|
impl From<&bdk::TransactionDetails> for Transaction {
|
||||||
fn from(x: &bdk::TransactionDetails) -> Transaction {
|
fn from(x: &bdk::TransactionDetails) -> Transaction {
|
||||||
match x.confirmation_time.clone() {
|
match x.confirmation_time.clone() {
|
||||||
Some(confirmation) => Transaction::Confirmed {
|
Some(block_time) => Transaction::Confirmed {
|
||||||
details: TransactionDetails::from(x),
|
details: TransactionDetails::from(x),
|
||||||
confirmation,
|
confirmation: block_time,
|
||||||
},
|
},
|
||||||
None => Transaction::Unconfirmed {
|
None => Transaction::Unconfirmed {
|
||||||
details: TransactionDetails::from(x),
|
details: TransactionDetails::from(x),
|
||||||
@ -128,7 +126,7 @@ trait OfflineWalletOperations<B>: WalletHolder<B> {
|
|||||||
self.get_wallet().get_balance()
|
self.get_wallet().get_balance()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sign<'a>(&self, psbt: &'a PartiallySignedBitcoinTransaction) -> Result<(), Error> {
|
fn sign(&self, psbt: &PartiallySignedBitcoinTransaction) -> Result<(), Error> {
|
||||||
let mut psbt = psbt.internal.lock().unwrap();
|
let mut psbt = psbt.internal.lock().unwrap();
|
||||||
let finalized = self.get_wallet().sign(&mut psbt, SignOptions::default())?;
|
let finalized = self.get_wallet().sign(&mut psbt, SignOptions::default())?;
|
||||||
match finalized {
|
match finalized {
|
||||||
@ -278,12 +276,12 @@ impl OnlineWallet {
|
|||||||
.sync(BdkProgressHolder { progress_update }, max_address_param)
|
.sync(BdkProgressHolder { progress_update }, max_address_param)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn broadcast<'a>(
|
fn broadcast(
|
||||||
&self,
|
&self,
|
||||||
psbt: &'a PartiallySignedBitcoinTransaction,
|
psbt: &PartiallySignedBitcoinTransaction,
|
||||||
) -> Result<Transaction, Error> {
|
) -> Result<Transaction, Error> {
|
||||||
let tx = psbt.internal.lock().unwrap().clone().extract_tx();
|
let tx = psbt.internal.lock().unwrap().clone().extract_tx();
|
||||||
self.get_wallet().broadcast(tx)?;
|
self.get_wallet().broadcast(&tx)?;
|
||||||
Ok(Transaction::from(&psbt.details))
|
Ok(Transaction::from(&psbt.details))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -304,11 +302,11 @@ pub struct ExtendedKeyInfo {
|
|||||||
|
|
||||||
fn generate_extended_key(
|
fn generate_extended_key(
|
||||||
network: Network,
|
network: Network,
|
||||||
mnemonic_type: MnemonicType,
|
word_count: WordCount,
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
) -> Result<ExtendedKeyInfo, Error> {
|
) -> Result<ExtendedKeyInfo, Error> {
|
||||||
let mnemonic: GeneratedKey<_, BareCtx> =
|
let mnemonic: GeneratedKey<_, BareCtx> =
|
||||||
Mnemonic::generate((mnemonic_type, Language::English)).unwrap();
|
Mnemonic::generate((word_count, Language::English)).unwrap();
|
||||||
let mnemonic = mnemonic.into_key();
|
let mnemonic = mnemonic.into_key();
|
||||||
let xkey: ExtendedKey = (mnemonic.clone(), password).into_extended_key()?;
|
let xkey: ExtendedKey = (mnemonic.clone(), password).into_extended_key()?;
|
||||||
let xprv = xkey.into_xprv(network).unwrap();
|
let xprv = xkey.into_xprv(network).unwrap();
|
||||||
@ -325,7 +323,7 @@ fn restore_extended_key(
|
|||||||
mnemonic: String,
|
mnemonic: String,
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
) -> Result<ExtendedKeyInfo, Error> {
|
) -> Result<ExtendedKeyInfo, Error> {
|
||||||
let mnemonic = Mnemonic::from_phrase(mnemonic.as_ref(), Language::English).unwrap();
|
let mnemonic = Mnemonic::parse_in(Language::English, mnemonic).unwrap();
|
||||||
let xkey: ExtendedKey = (mnemonic.clone(), password).into_extended_key()?;
|
let xkey: ExtendedKey = (mnemonic.clone(), password).into_extended_key()?;
|
||||||
let xprv = xkey.into_xprv(network).unwrap();
|
let xprv = xkey.into_xprv(network).unwrap();
|
||||||
let fingerprint = xprv.fingerprint(&Secp256k1::new());
|
let fingerprint = xprv.fingerprint(&Secp256k1::new());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user