|
1 | 1 | use crate::error::{
|
2 |
| - AddressParseError, ExtractTxError, FeeRateError, FromScriptError, PsbtError, PsbtParseError, |
3 |
| - TransactionError, |
| 2 | + AddressParseError, ExtractTxError, FeeRateError, FromScriptError, HashParseError, PsbtError, |
| 3 | + PsbtParseError, TransactionError, |
4 | 4 | };
|
5 | 5 | use crate::error::{ParseAmountError, PsbtFinalizeError};
|
6 |
| -use crate::{impl_from_core_type, impl_into_core_type}; |
| 6 | +use crate::{impl_from_core_type, impl_hash_like, impl_into_core_type}; |
7 | 7 |
|
8 | 8 | use bdk_wallet::bitcoin::address::NetworkChecked;
|
9 | 9 | use bdk_wallet::bitcoin::address::NetworkUnchecked;
|
10 | 10 | use bdk_wallet::bitcoin::address::{Address as BdkAddress, AddressData as BdkAddressData};
|
11 | 11 | use bdk_wallet::bitcoin::blockdata::block::Header as BdkHeader;
|
| 12 | +use bdk_wallet::bitcoin::consensus::encode::deserialize; |
12 | 13 | use bdk_wallet::bitcoin::consensus::encode::serialize;
|
13 | 14 | use bdk_wallet::bitcoin::consensus::Decodable;
|
| 15 | +use bdk_wallet::bitcoin::hashes::sha256::Hash as BitcoinSha256Hash; |
| 16 | +use bdk_wallet::bitcoin::hashes::sha256d::Hash as BitcoinDoubleSha256Hash; |
14 | 17 | use bdk_wallet::bitcoin::io::Cursor;
|
15 | 18 | use bdk_wallet::bitcoin::secp256k1::Secp256k1;
|
16 | 19 | use bdk_wallet::bitcoin::Amount as BdkAmount;
|
| 20 | +use bdk_wallet::bitcoin::BlockHash as BitcoinBlockHash; |
17 | 21 | use bdk_wallet::bitcoin::FeeRate as BdkFeeRate;
|
18 | 22 | use bdk_wallet::bitcoin::Network;
|
| 23 | +use bdk_wallet::bitcoin::OutPoint as BdkOutPoint; |
19 | 24 | use bdk_wallet::bitcoin::Psbt as BdkPsbt;
|
20 | 25 | use bdk_wallet::bitcoin::ScriptBuf as BdkScriptBuf;
|
21 | 26 | use bdk_wallet::bitcoin::Transaction as BdkTransaction;
|
22 | 27 | use bdk_wallet::bitcoin::TxIn as BdkTxIn;
|
23 | 28 | use bdk_wallet::bitcoin::TxOut as BdkTxOut;
|
24 |
| -use bdk_wallet::bitcoin::{OutPoint as BdkOutPoint, Txid}; |
| 29 | +use bdk_wallet::bitcoin::Txid as BitcoinTxid; |
| 30 | +use bdk_wallet::bitcoin::Wtxid as BitcoinWtxid; |
25 | 31 | use bdk_wallet::miniscript::psbt::PsbtExt;
|
26 | 32 | use bdk_wallet::serde_json;
|
27 | 33 |
|
@@ -51,7 +57,7 @@ impl From<&BdkOutPoint> for OutPoint {
|
51 | 57 | impl From<OutPoint> for BdkOutPoint {
|
52 | 58 | fn from(outpoint: OutPoint) -> Self {
|
53 | 59 | BdkOutPoint {
|
54 |
| - txid: Txid::from_str(&outpoint.txid).unwrap(), |
| 60 | + txid: BitcoinTxid::from_str(&outpoint.txid).unwrap(), |
55 | 61 | vout: outpoint.vout,
|
56 | 62 | }
|
57 | 63 | }
|
@@ -575,6 +581,42 @@ impl From<&BdkTxOut> for TxOut {
|
575 | 581 | }
|
576 | 582 | }
|
577 | 583 |
|
| 584 | +/// A bitcoin Block hash |
| 585 | +#[derive(Debug, PartialEq, Eq, std::hash::Hash, uniffi::Object)] |
| 586 | +#[uniffi::export(Display, Eq, Hash)] |
| 587 | +pub struct BlockHash(pub(crate) BitcoinBlockHash); |
| 588 | + |
| 589 | +impl_hash_like!(BlockHash, BitcoinBlockHash); |
| 590 | + |
| 591 | +/// A bitcoin transaction identifier |
| 592 | +#[derive(Debug, PartialEq, Eq, std::hash::Hash, uniffi::Object)] |
| 593 | +#[uniffi::export(Display, Eq, Hash)] |
| 594 | +pub struct Txid(pub(crate) BitcoinTxid); |
| 595 | + |
| 596 | +impl_hash_like!(Txid, BitcoinTxid); |
| 597 | + |
| 598 | +/// A bitcoin transaction identifier, including witness data. |
| 599 | +/// For transactions with no SegWit inputs, the `txid` will be equivalent to `wtxid`. |
| 600 | +#[derive(Debug, PartialEq, Eq, std::hash::Hash, uniffi::Object)] |
| 601 | +#[uniffi::export(Display, Eq, Hash)] |
| 602 | +pub struct Wtxid(pub(crate) BitcoinWtxid); |
| 603 | + |
| 604 | +impl_hash_like!(Wtxid, BitcoinWtxid); |
| 605 | + |
| 606 | +/// A collision-proof unique identifier for a descriptor. |
| 607 | +#[derive(Debug, PartialEq, Eq, std::hash::Hash, uniffi::Object)] |
| 608 | +#[uniffi::export(Display, Eq, Hash)] |
| 609 | +pub struct DescriptorId(pub(crate) BitcoinSha256Hash); |
| 610 | + |
| 611 | +impl_hash_like!(DescriptorId, BitcoinSha256Hash); |
| 612 | + |
| 613 | +/// The merkle root of the merkle tree corresponding to a block's transactions. |
| 614 | +#[derive(Debug, PartialEq, Eq, std::hash::Hash, uniffi::Object)] |
| 615 | +#[uniffi::export(Display, Eq, Hash)] |
| 616 | +pub struct TxMerkleNode(pub(crate) BitcoinDoubleSha256Hash); |
| 617 | + |
| 618 | +impl_hash_like!(TxMerkleNode, BitcoinDoubleSha256Hash); |
| 619 | + |
578 | 620 | #[cfg(test)]
|
579 | 621 | mod tests {
|
580 | 622 | use crate::bitcoin::Address;
|
|
0 commit comments