Remove BdkError type alias
This commit is contained in:
parent
535fc70433
commit
2cbb314d0b
42
src/bdk.udl
42
src/bdk.udl
@ -1,10 +1,10 @@
|
|||||||
namespace bdk {
|
namespace bdk {
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
string generate_mnemonic(WordCount word_count);
|
string generate_mnemonic(WordCount word_count);
|
||||||
};
|
};
|
||||||
|
|
||||||
[Error]
|
[Error]
|
||||||
enum BdkError {
|
enum Error {
|
||||||
"InvalidU32Bytes",
|
"InvalidU32Bytes",
|
||||||
"Generic",
|
"Generic",
|
||||||
"MissingCachedScripts",
|
"MissingCachedScripts",
|
||||||
@ -134,16 +134,16 @@ interface BlockchainConfig {
|
|||||||
};
|
};
|
||||||
|
|
||||||
interface Blockchain {
|
interface Blockchain {
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
constructor(BlockchainConfig config);
|
constructor(BlockchainConfig config);
|
||||||
|
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
void broadcast([ByRef] PartiallySignedBitcoinTransaction psbt);
|
void broadcast([ByRef] PartiallySignedBitcoinTransaction psbt);
|
||||||
|
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
u32 get_height();
|
u32 get_height();
|
||||||
|
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
string get_block_hash(u32 height);
|
string get_block_hash(u32 height);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -179,39 +179,39 @@ dictionary AddressAmount {
|
|||||||
};
|
};
|
||||||
|
|
||||||
interface Wallet {
|
interface Wallet {
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
constructor(string descriptor, string? change_descriptor, Network network, DatabaseConfig database_config);
|
constructor(string descriptor, string? change_descriptor, Network network, DatabaseConfig database_config);
|
||||||
|
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
AddressInfo get_address(AddressIndex address_index);
|
AddressInfo get_address(AddressIndex address_index);
|
||||||
|
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
Balance get_balance();
|
Balance get_balance();
|
||||||
|
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
boolean sign([ByRef] PartiallySignedBitcoinTransaction psbt);
|
boolean sign([ByRef] PartiallySignedBitcoinTransaction psbt);
|
||||||
|
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
sequence<TransactionDetails> list_transactions();
|
sequence<TransactionDetails> list_transactions();
|
||||||
|
|
||||||
Network network();
|
Network network();
|
||||||
|
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
void sync([ByRef] Blockchain blockchain, Progress? progress);
|
void sync([ByRef] Blockchain blockchain, Progress? progress);
|
||||||
|
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
sequence<LocalUtxo> list_unspent();
|
sequence<LocalUtxo> list_unspent();
|
||||||
};
|
};
|
||||||
|
|
||||||
interface PartiallySignedBitcoinTransaction {
|
interface PartiallySignedBitcoinTransaction {
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
constructor(string psbt_base64);
|
constructor(string psbt_base64);
|
||||||
|
|
||||||
string serialize();
|
string serialize();
|
||||||
|
|
||||||
string txid();
|
string txid();
|
||||||
|
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
PartiallySignedBitcoinTransaction combine(PartiallySignedBitcoinTransaction other);
|
PartiallySignedBitcoinTransaction combine(PartiallySignedBitcoinTransaction other);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ interface TxBuilder {
|
|||||||
|
|
||||||
TxBuilder set_recipients(sequence<AddressAmount> recipients);
|
TxBuilder set_recipients(sequence<AddressAmount> recipients);
|
||||||
|
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
PartiallySignedBitcoinTransaction finish([ByRef] Wallet wallet);
|
PartiallySignedBitcoinTransaction finish([ByRef] Wallet wallet);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -263,20 +263,20 @@ interface BumpFeeTxBuilder {
|
|||||||
|
|
||||||
BumpFeeTxBuilder enable_rbf_with_sequence(u32 nsequence);
|
BumpFeeTxBuilder enable_rbf_with_sequence(u32 nsequence);
|
||||||
|
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
PartiallySignedBitcoinTransaction finish([ByRef] Wallet wallet);
|
PartiallySignedBitcoinTransaction finish([ByRef] Wallet wallet);
|
||||||
};
|
};
|
||||||
|
|
||||||
interface DerivationPath {
|
interface DerivationPath {
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
constructor(string path);
|
constructor(string path);
|
||||||
};
|
};
|
||||||
|
|
||||||
interface DescriptorSecretKey {
|
interface DescriptorSecretKey {
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
constructor(Network network, string mnemonic, string? password);
|
constructor(Network network, string mnemonic, string? password);
|
||||||
|
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
DescriptorSecretKey derive(DerivationPath path);
|
DescriptorSecretKey derive(DerivationPath path);
|
||||||
|
|
||||||
DescriptorSecretKey extend(DerivationPath path);
|
DescriptorSecretKey extend(DerivationPath path);
|
||||||
@ -289,7 +289,7 @@ interface DescriptorSecretKey {
|
|||||||
};
|
};
|
||||||
|
|
||||||
interface DescriptorPublicKey {
|
interface DescriptorPublicKey {
|
||||||
[Throws=BdkError]
|
[Throws=Error]
|
||||||
DescriptorPublicKey derive(DerivationPath path);
|
DescriptorPublicKey derive(DerivationPath path);
|
||||||
|
|
||||||
DescriptorPublicKey extend(DerivationPath path);
|
DescriptorPublicKey extend(DerivationPath path);
|
||||||
|
32
src/lib.rs
32
src/lib.rs
@ -35,8 +35,6 @@ use std::sync::{Arc, Mutex, MutexGuard};
|
|||||||
|
|
||||||
uniffi_macros::include_scaffolding!("bdk");
|
uniffi_macros::include_scaffolding!("bdk");
|
||||||
|
|
||||||
type BdkError = Error;
|
|
||||||
|
|
||||||
pub struct AddressAmount {
|
pub struct AddressAmount {
|
||||||
pub address: String,
|
pub address: String,
|
||||||
pub amount: u64,
|
pub amount: u64,
|
||||||
@ -177,7 +175,7 @@ struct Blockchain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Blockchain {
|
impl Blockchain {
|
||||||
fn new(blockchain_config: BlockchainConfig) -> Result<Self, BdkError> {
|
fn new(blockchain_config: BlockchainConfig) -> Result<Self, Error> {
|
||||||
let any_blockchain_config = match blockchain_config {
|
let any_blockchain_config = match blockchain_config {
|
||||||
BlockchainConfig::Electrum { config } => {
|
BlockchainConfig::Electrum { config } => {
|
||||||
AnyBlockchainConfig::Electrum(ElectrumBlockchainConfig {
|
AnyBlockchainConfig::Electrum(ElectrumBlockchainConfig {
|
||||||
@ -390,7 +388,7 @@ impl Wallet {
|
|||||||
change_descriptor: Option<String>,
|
change_descriptor: Option<String>,
|
||||||
network: Network,
|
network: Network,
|
||||||
database_config: DatabaseConfig,
|
database_config: DatabaseConfig,
|
||||||
) -> Result<Self, BdkError> {
|
) -> Result<Self, Error> {
|
||||||
let any_database_config = match database_config {
|
let any_database_config = match database_config {
|
||||||
DatabaseConfig::Memory => AnyDatabaseConfig::Memory(()),
|
DatabaseConfig::Memory => AnyDatabaseConfig::Memory(()),
|
||||||
DatabaseConfig::Sled { config } => AnyDatabaseConfig::Sled(config),
|
DatabaseConfig::Sled { config } => AnyDatabaseConfig::Sled(config),
|
||||||
@ -420,7 +418,7 @@ impl Wallet {
|
|||||||
&self,
|
&self,
|
||||||
blockchain: &Blockchain,
|
blockchain: &Blockchain,
|
||||||
progress: Option<Box<dyn Progress>>,
|
progress: Option<Box<dyn Progress>>,
|
||||||
) -> Result<(), BdkError> {
|
) -> Result<(), Error> {
|
||||||
let bdk_sync_opts = BdkSyncOptions {
|
let bdk_sync_opts = BdkSyncOptions {
|
||||||
progress: progress.map(|p| {
|
progress: progress.map(|p| {
|
||||||
Box::new(ProgressHolder { progress: p })
|
Box::new(ProgressHolder { progress: p })
|
||||||
@ -435,7 +433,7 @@ impl Wallet {
|
|||||||
/// Return a derived address using the external descriptor, see AddressIndex for available address index selection
|
/// Return a derived address using the external descriptor, see AddressIndex for available address index selection
|
||||||
/// strategies. If none of the keys in the descriptor are derivable (i.e. the descriptor does not end with a * character)
|
/// strategies. If none of the keys in the descriptor are derivable (i.e. the descriptor does not end with a * character)
|
||||||
/// then the same address will always be returned for any AddressIndex.
|
/// then the same address will always be returned for any AddressIndex.
|
||||||
fn get_address(&self, address_index: AddressIndex) -> Result<AddressInfo, BdkError> {
|
fn get_address(&self, address_index: AddressIndex) -> Result<AddressInfo, Error> {
|
||||||
self.get_wallet()
|
self.get_wallet()
|
||||||
.get_address(address_index.into())
|
.get_address(address_index.into())
|
||||||
.map(AddressInfo::from)
|
.map(AddressInfo::from)
|
||||||
@ -473,10 +471,10 @@ impl Wallet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_script_pubkey(address: &str) -> Result<Script, BdkError> {
|
fn to_script_pubkey(address: &str) -> Result<Script, Error> {
|
||||||
Address::from_str(address)
|
Address::from_str(address)
|
||||||
.map(|x| x.script_pubkey())
|
.map(|x| x.script_pubkey())
|
||||||
.map_err(|e| BdkError::Generic(e.to_string()))
|
.map_err(|e| Error::Generic(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@ -805,7 +803,7 @@ impl BumpFeeTxBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_mnemonic(word_count: WordCount) -> Result<String, BdkError> {
|
fn generate_mnemonic(word_count: WordCount) -> Result<String, Error> {
|
||||||
let mnemonic: GeneratedKey<_, BareCtx> =
|
let mnemonic: GeneratedKey<_, BareCtx> =
|
||||||
Mnemonic::generate((word_count, Language::English)).unwrap();
|
Mnemonic::generate((word_count, Language::English)).unwrap();
|
||||||
Ok(mnemonic.to_string())
|
Ok(mnemonic.to_string())
|
||||||
@ -816,12 +814,12 @@ struct DerivationPath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DerivationPath {
|
impl DerivationPath {
|
||||||
fn new(path: String) -> Result<Self, BdkError> {
|
fn new(path: String) -> Result<Self, Error> {
|
||||||
BdkDerivationPath::from_str(&path)
|
BdkDerivationPath::from_str(&path)
|
||||||
.map(|x| DerivationPath {
|
.map(|x| DerivationPath {
|
||||||
derivation_path_mutex: Mutex::new(x),
|
derivation_path_mutex: Mutex::new(x),
|
||||||
})
|
})
|
||||||
.map_err(|e| BdkError::Generic(e.to_string()))
|
.map_err(|e| Error::Generic(e.to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -830,9 +828,9 @@ struct DescriptorSecretKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DescriptorSecretKey {
|
impl DescriptorSecretKey {
|
||||||
fn new(network: Network, mnemonic: String, password: Option<String>) -> Result<Self, BdkError> {
|
fn new(network: Network, mnemonic: String, password: Option<String>) -> Result<Self, Error> {
|
||||||
let mnemonic = Mnemonic::parse_in(Language::English, mnemonic)
|
let mnemonic = Mnemonic::parse_in(Language::English, mnemonic)
|
||||||
.map_err(|e| BdkError::Generic(e.to_string()))?;
|
.map_err(|e| Error::Generic(e.to_string()))?;
|
||||||
let xkey: ExtendedKey = (mnemonic, password).into_extended_key()?;
|
let xkey: ExtendedKey = (mnemonic, password).into_extended_key()?;
|
||||||
let descriptor_secret_key = BdkDescriptorSecretKey::XPrv(DescriptorXKey {
|
let descriptor_secret_key = BdkDescriptorSecretKey::XPrv(DescriptorXKey {
|
||||||
origin: None,
|
origin: None,
|
||||||
@ -845,7 +843,7 @@ impl DescriptorSecretKey {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn derive(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, BdkError> {
|
fn derive(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, Error> {
|
||||||
let secp = Secp256k1::new();
|
let secp = Secp256k1::new();
|
||||||
let descriptor_secret_key = self.descriptor_secret_key_mutex.lock().unwrap();
|
let descriptor_secret_key = self.descriptor_secret_key_mutex.lock().unwrap();
|
||||||
let path = path.derivation_path_mutex.lock().unwrap().deref().clone();
|
let path = path.derivation_path_mutex.lock().unwrap().deref().clone();
|
||||||
@ -932,7 +930,7 @@ struct DescriptorPublicKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DescriptorPublicKey {
|
impl DescriptorPublicKey {
|
||||||
fn derive(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, BdkError> {
|
fn derive(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, Error> {
|
||||||
let secp = Secp256k1::new();
|
let secp = Secp256k1::new();
|
||||||
let descriptor_public_key = self.descriptor_public_key_mutex.lock().unwrap();
|
let descriptor_public_key = self.descriptor_public_key_mutex.lock().unwrap();
|
||||||
let path = path.derivation_path_mutex.lock().unwrap().deref().clone();
|
let path = path.derivation_path_mutex.lock().unwrap().deref().clone();
|
||||||
@ -1064,7 +1062,7 @@ mod test {
|
|||||||
fn derive_dsk(
|
fn derive_dsk(
|
||||||
key: &DescriptorSecretKey,
|
key: &DescriptorSecretKey,
|
||||||
path: &str,
|
path: &str,
|
||||||
) -> Result<Arc<DescriptorSecretKey>, BdkError> {
|
) -> Result<Arc<DescriptorSecretKey>, Error> {
|
||||||
let path = Arc::new(DerivationPath::new(path.to_string()).unwrap());
|
let path = Arc::new(DerivationPath::new(path.to_string()).unwrap());
|
||||||
key.derive(path)
|
key.derive(path)
|
||||||
}
|
}
|
||||||
@ -1077,7 +1075,7 @@ mod test {
|
|||||||
fn derive_dpk(
|
fn derive_dpk(
|
||||||
key: &DescriptorPublicKey,
|
key: &DescriptorPublicKey,
|
||||||
path: &str,
|
path: &str,
|
||||||
) -> Result<Arc<DescriptorPublicKey>, BdkError> {
|
) -> Result<Arc<DescriptorPublicKey>, Error> {
|
||||||
let path = Arc::new(DerivationPath::new(path.to_string()).unwrap());
|
let path = Arc::new(DerivationPath::new(path.to_string()).unwrap());
|
||||||
key.derive(path)
|
key.derive(path)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user