-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update rust-bitcoin, rust-elements and rust-electrum-client
- Introduced new BEScript, BETxid and BEBlockHash enums to encapsulate rust-elements's new data types. - The new data types will BREAK the existing RawCache database, which will be automatically re-populated from the Electrum server. Care has been taken to retain compatibility with the RawStore database (containing the user's settings and tx labels). - Added support for Signet.
- Loading branch information
Showing
23 changed files
with
572 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use bitcoin::hashes::hex::ToHex; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq, Serialize, Deserialize)] | ||
pub enum BEBlockHash { | ||
Bitcoin(bitcoin::BlockHash), | ||
Elements(elements::BlockHash), | ||
} | ||
|
||
impl BEBlockHash { | ||
pub fn to_hex(&self) -> String { | ||
match self { | ||
Self::Bitcoin(blockhash) => blockhash.to_hex(), | ||
Self::Elements(blockhash) => blockhash.to_hex(), | ||
} | ||
} | ||
} | ||
|
||
impl ToString for BEBlockHash { | ||
fn to_string(&self) -> String { | ||
match self { | ||
Self::Bitcoin(blockhash) => blockhash.to_string(), | ||
Self::Elements(blockhash) => blockhash.to_string(), | ||
} | ||
} | ||
} | ||
|
||
// We must have a default for Store, so we use bitcoin::BlockHash which | ||
// will be replaced with the proper type after the first sync. | ||
impl Default for BEBlockHash { | ||
fn default() -> Self { | ||
Self::Bitcoin(Default::default()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
use bitcoin::hashes::hex::ToHex; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] | ||
pub enum BEScript { | ||
Bitcoin(bitcoin::Script), | ||
Elements(elements::Script), | ||
} | ||
|
||
impl BEScript { | ||
pub fn to_hex(&self) -> String { | ||
match self { | ||
Self::Bitcoin(script) => script.to_hex(), | ||
Self::Elements(script) => script.to_hex(), | ||
} | ||
} | ||
|
||
pub fn is_empty(&self) -> bool { | ||
match self { | ||
Self::Bitcoin(script) => script.is_empty(), | ||
Self::Elements(script) => script.is_empty(), | ||
} | ||
} | ||
pub fn ref_bitcoin(&self) -> Option<&bitcoin::Script> { | ||
match self { | ||
Self::Bitcoin(script) => Some(script), | ||
Self::Elements(_) => None, | ||
} | ||
} | ||
pub fn ref_elements(&self) -> Option<&elements::Script> { | ||
match self { | ||
Self::Bitcoin(_) => None, | ||
Self::Elements(script) => Some(script), | ||
} | ||
} | ||
} | ||
|
||
pub trait BEScriptConvert { | ||
fn into_bitcoin(self) -> bitcoin::Script; | ||
fn into_elements(self) -> elements::Script; | ||
fn into_be(self) -> BEScript; | ||
} | ||
|
||
impl BEScriptConvert for BEScript { | ||
fn into_bitcoin(self) -> bitcoin::Script { | ||
match self { | ||
Self::Bitcoin(script) => script, | ||
Self::Elements(script) => script.into_bitcoin(), | ||
} | ||
} | ||
fn into_elements(self) -> elements::Script { | ||
match self { | ||
Self::Bitcoin(script) => script.into_elements(), | ||
Self::Elements(script) => script, | ||
} | ||
} | ||
fn into_be(self) -> Self { | ||
self | ||
} | ||
} | ||
|
||
impl BEScriptConvert for bitcoin::Script { | ||
fn into_bitcoin(self) -> bitcoin::Script { | ||
self | ||
} | ||
fn into_elements(self) -> elements::Script { | ||
elements::Script::from(self.into_bytes()) | ||
} | ||
fn into_be(self) -> BEScript { | ||
self.into() | ||
} | ||
} | ||
|
||
impl BEScriptConvert for elements::Script { | ||
fn into_bitcoin(self) -> bitcoin::Script { | ||
bitcoin::Script::from(self.into_bytes()) | ||
} | ||
fn into_elements(self) -> elements::Script { | ||
self | ||
} | ||
fn into_be(self) -> BEScript { | ||
self.into() | ||
} | ||
} | ||
|
||
impl BEScriptConvert for &elements::Script { | ||
fn into_bitcoin(self) -> bitcoin::Script { | ||
self.clone().into_bitcoin() | ||
} | ||
fn into_elements(self) -> elements::Script { | ||
self.clone().into_elements() | ||
} | ||
fn into_be(self) -> BEScript { | ||
self.clone().into() | ||
} | ||
} | ||
|
||
impl BEScriptConvert for &bitcoin::Script { | ||
fn into_bitcoin(self) -> bitcoin::Script { | ||
self.clone().into_bitcoin() | ||
} | ||
fn into_elements(self) -> elements::Script { | ||
self.clone().into_elements() | ||
} | ||
fn into_be(self) -> BEScript { | ||
self.clone().into() | ||
} | ||
} | ||
|
||
impl ToString for BEScript { | ||
fn to_string(&self) -> String { | ||
match self { | ||
BEScript::Bitcoin(script) => script.to_string(), | ||
BEScript::Elements(script) => script.to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl From<bitcoin::Script> for BEScript { | ||
fn from(script: bitcoin::Script) -> BEScript { | ||
BEScript::Bitcoin(script) | ||
} | ||
} | ||
|
||
impl From<elements::Script> for BEScript { | ||
fn from(script: elements::Script) -> BEScript { | ||
BEScript::Elements(script) | ||
} | ||
} | ||
impl From<&bitcoin::Script> for BEScript { | ||
fn from(script: &bitcoin::Script) -> BEScript { | ||
script.clone().into() | ||
} | ||
} | ||
|
||
impl From<&elements::Script> for BEScript { | ||
fn from(script: &elements::Script) -> BEScript { | ||
script.clone().into() | ||
} | ||
} |
Oops, something went wrong.