Use Address type in address field on AddressInfo
This commit is contained in:
parent
2b7c104f11
commit
e7e1a6057e
@ -50,7 +50,8 @@ enum BdkError {
|
|||||||
|
|
||||||
dictionary AddressInfo {
|
dictionary AddressInfo {
|
||||||
u32 index;
|
u32 index;
|
||||||
string address;
|
Address address;
|
||||||
|
KeychainKind keychain;
|
||||||
};
|
};
|
||||||
|
|
||||||
[Enum]
|
[Enum]
|
||||||
@ -452,6 +453,8 @@ interface Address {
|
|||||||
Script script_pubkey();
|
Script script_pubkey();
|
||||||
|
|
||||||
string to_qr_uri();
|
string to_qr_uri();
|
||||||
|
|
||||||
|
string as_string();
|
||||||
};
|
};
|
||||||
|
|
||||||
[Enum]
|
[Enum]
|
||||||
|
@ -47,17 +47,20 @@ pub struct ScriptAmount {
|
|||||||
|
|
||||||
/// A derived address and the index it was found at.
|
/// A derived address and the index it was found at.
|
||||||
pub struct AddressInfo {
|
pub struct AddressInfo {
|
||||||
/// Child index of this address
|
/// Child index of this address.
|
||||||
pub index: u32,
|
pub index: u32,
|
||||||
/// Address
|
/// Address.
|
||||||
pub address: String,
|
pub address: Arc<Address>,
|
||||||
|
/// Type of keychain.
|
||||||
|
pub keychain: KeychainKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<BdkAddressInfo> for AddressInfo {
|
impl From<BdkAddressInfo> for AddressInfo {
|
||||||
fn from(x: bdk::wallet::AddressInfo) -> Self {
|
fn from(x: BdkAddressInfo) -> Self {
|
||||||
AddressInfo {
|
AddressInfo {
|
||||||
index: x.index,
|
index: x.index,
|
||||||
address: x.address.to_string(),
|
address: Arc::new(Address::from(x.address)),
|
||||||
|
keychain: x.keychain,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -347,7 +350,8 @@ impl From<bdk::bitcoin::Transaction> for Transaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A Bitcoin address.
|
/// A Bitcoin address.
|
||||||
struct Address {
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
pub struct Address {
|
||||||
address: BdkAddress,
|
address: BdkAddress,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,6 +390,16 @@ impl Address {
|
|||||||
fn to_qr_uri(&self) -> String {
|
fn to_qr_uri(&self) -> String {
|
||||||
self.address.to_qr_uri()
|
self.address.to_qr_uri()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn as_string(&self) -> String {
|
||||||
|
self.address.to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<BdkAddress> for Address {
|
||||||
|
fn from(address: BdkAddress) -> Self {
|
||||||
|
Address { address }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The method used to produce an address.
|
/// The method used to produce an address.
|
||||||
|
@ -655,7 +655,8 @@ mod test {
|
|||||||
wallet
|
wallet
|
||||||
.get_address(AddressIndex::Peek { index: 2 })
|
.get_address(AddressIndex::Peek { index: 2 })
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.address,
|
.address
|
||||||
|
.as_string(),
|
||||||
"bcrt1q5g0mq6dkmwzvxscqwgc932jhgcxuqqkjv09tkj"
|
"bcrt1q5g0mq6dkmwzvxscqwgc932jhgcxuqqkjv09tkj"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -663,25 +664,38 @@ mod test {
|
|||||||
wallet
|
wallet
|
||||||
.get_address(AddressIndex::Peek { index: 1 })
|
.get_address(AddressIndex::Peek { index: 1 })
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.address,
|
.address
|
||||||
|
.as_string(),
|
||||||
"bcrt1q0xs7dau8af22rspp4klya4f7lhggcnqfun2y3a"
|
"bcrt1q0xs7dau8af22rspp4klya4f7lhggcnqfun2y3a"
|
||||||
);
|
);
|
||||||
|
|
||||||
// new index still 0
|
// new index still 0
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
wallet.get_address(AddressIndex::New).unwrap().address,
|
wallet
|
||||||
|
.get_address(AddressIndex::New)
|
||||||
|
.unwrap()
|
||||||
|
.address
|
||||||
|
.as_string(),
|
||||||
"bcrt1qqjn9gky9mkrm3c28e5e87t5akd3twg6xezp0tv"
|
"bcrt1qqjn9gky9mkrm3c28e5e87t5akd3twg6xezp0tv"
|
||||||
);
|
);
|
||||||
|
|
||||||
// new index now 1
|
// new index now 1
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
wallet.get_address(AddressIndex::New).unwrap().address,
|
wallet
|
||||||
|
.get_address(AddressIndex::New)
|
||||||
|
.unwrap()
|
||||||
|
.address
|
||||||
|
.as_string(),
|
||||||
"bcrt1q0xs7dau8af22rspp4klya4f7lhggcnqfun2y3a"
|
"bcrt1q0xs7dau8af22rspp4klya4f7lhggcnqfun2y3a"
|
||||||
);
|
);
|
||||||
|
|
||||||
// new index now 2
|
// new index now 2
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
wallet.get_address(AddressIndex::New).unwrap().address,
|
wallet
|
||||||
|
.get_address(AddressIndex::New)
|
||||||
|
.unwrap()
|
||||||
|
.address
|
||||||
|
.as_string(),
|
||||||
"bcrt1q5g0mq6dkmwzvxscqwgc932jhgcxuqqkjv09tkj"
|
"bcrt1q5g0mq6dkmwzvxscqwgc932jhgcxuqqkjv09tkj"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -690,7 +704,8 @@ mod test {
|
|||||||
wallet
|
wallet
|
||||||
.get_address(AddressIndex::Peek { index: 1 })
|
.get_address(AddressIndex::Peek { index: 1 })
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.address,
|
.address
|
||||||
|
.as_string(),
|
||||||
"bcrt1q0xs7dau8af22rspp4klya4f7lhggcnqfun2y3a"
|
"bcrt1q0xs7dau8af22rspp4klya4f7lhggcnqfun2y3a"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -699,13 +714,18 @@ mod test {
|
|||||||
wallet
|
wallet
|
||||||
.get_address(AddressIndex::Reset { index: 0 })
|
.get_address(AddressIndex::Reset { index: 0 })
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.address,
|
.address
|
||||||
|
.as_string(),
|
||||||
"bcrt1qqjn9gky9mkrm3c28e5e87t5akd3twg6xezp0tv"
|
"bcrt1qqjn9gky9mkrm3c28e5e87t5akd3twg6xezp0tv"
|
||||||
);
|
);
|
||||||
|
|
||||||
// new index 1 again
|
// new index 1 again
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
wallet.get_address(AddressIndex::New).unwrap().address,
|
wallet
|
||||||
|
.get_address(AddressIndex::New)
|
||||||
|
.unwrap()
|
||||||
|
.address
|
||||||
|
.as_string(),
|
||||||
"bcrt1q0xs7dau8af22rspp4klya4f7lhggcnqfun2y3a"
|
"bcrt1q0xs7dau8af22rspp4klya4f7lhggcnqfun2y3a"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -729,12 +749,20 @@ mod test {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
wallet.get_address(AddressIndex::New).unwrap().address,
|
wallet
|
||||||
|
.get_address(AddressIndex::New)
|
||||||
|
.unwrap()
|
||||||
|
.address
|
||||||
|
.as_string(),
|
||||||
"bcrt1qqjn9gky9mkrm3c28e5e87t5akd3twg6xezp0tv"
|
"bcrt1qqjn9gky9mkrm3c28e5e87t5akd3twg6xezp0tv"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
wallet.get_address(AddressIndex::New).unwrap().address,
|
wallet
|
||||||
|
.get_address(AddressIndex::New)
|
||||||
|
.unwrap()
|
||||||
|
.address
|
||||||
|
.as_string(),
|
||||||
"bcrt1q0xs7dau8af22rspp4klya4f7lhggcnqfun2y3a"
|
"bcrt1q0xs7dau8af22rspp4klya4f7lhggcnqfun2y3a"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -742,7 +770,8 @@ mod test {
|
|||||||
wallet
|
wallet
|
||||||
.get_address(AddressIndex::LastUnused)
|
.get_address(AddressIndex::LastUnused)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.address,
|
.address
|
||||||
|
.as_string(),
|
||||||
"bcrt1q0xs7dau8af22rspp4klya4f7lhggcnqfun2y3a"
|
"bcrt1q0xs7dau8af22rspp4klya4f7lhggcnqfun2y3a"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -750,7 +779,8 @@ mod test {
|
|||||||
wallet
|
wallet
|
||||||
.get_internal_address(AddressIndex::New)
|
.get_internal_address(AddressIndex::New)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.address,
|
.address
|
||||||
|
.as_string(),
|
||||||
"bcrt1qpmz73cyx00r4a5dea469j40ax6d6kqyd67nnpj"
|
"bcrt1qpmz73cyx00r4a5dea469j40ax6d6kqyd67nnpj"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -758,7 +788,8 @@ mod test {
|
|||||||
wallet
|
wallet
|
||||||
.get_internal_address(AddressIndex::New)
|
.get_internal_address(AddressIndex::New)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.address,
|
.address
|
||||||
|
.as_string(),
|
||||||
"bcrt1qaux734vuhykww9632v8cmdnk7z2mw5lsf74v6k"
|
"bcrt1qaux734vuhykww9632v8cmdnk7z2mw5lsf74v6k"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -766,7 +797,8 @@ mod test {
|
|||||||
wallet
|
wallet
|
||||||
.get_internal_address(AddressIndex::LastUnused)
|
.get_internal_address(AddressIndex::LastUnused)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.address,
|
.address
|
||||||
|
.as_string(),
|
||||||
"bcrt1qaux734vuhykww9632v8cmdnk7z2mw5lsf74v6k"
|
"bcrt1qaux734vuhykww9632v8cmdnk7z2mw5lsf74v6k"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user