Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
exterpate outdated strict encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jul 28, 2023
1 parent bee761c commit 70aadcd
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 418 deletions.
378 changes: 119 additions & 259 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion bitcoin_blockchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ crate-type = ["lib", "staticlib"]

[dependencies]
amplify = "3.14.2"
strict_encoding = "0.9.0"
serde_crate = { package = "serde", version = "1", features = ["derive"], optional = true }
chrono = "0.4.23"

Expand Down
2 changes: 0 additions & 2 deletions bitcoin_blockchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#[macro_use]
extern crate amplify;
#[macro_use]
extern crate strict_encoding;
#[cfg(feature = "serde")]
#[macro_use]
extern crate serde_crate as serde;
Expand Down
97 changes: 23 additions & 74 deletions bitcoin_blockchain/src/locks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub const LOCKTIME_THRESHOLD: u32 = 500000000;
/// Time lock interval describing both relative (OP_CHECKSEQUENCEVERIFY) and
/// absolute (OP_CHECKTIMELOCKVERIFY) timelocks.
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
#[derive(StrictEncode, StrictDecode)]
pub enum TimeLockInterval {
/// Describes number of blocks for the timelock
#[display("height({0})")]
Expand Down Expand Up @@ -93,7 +92,6 @@ impl std::error::Error for ParseError {

/// Value for `nSeq` field of a transaction output
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, From)]
#[derive(StrictEncode, StrictDecode)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand All @@ -102,16 +100,12 @@ impl std::error::Error for ParseError {
pub struct SeqNo(#[from] u32);

impl From<SeqNo> for u32 {
fn from(seqno: SeqNo) -> Self {
seqno.into_consensus()
}
fn from(seqno: SeqNo) -> Self { seqno.into_consensus() }
}

impl Default for SeqNo {
#[inline]
fn default() -> Self {
SeqNo(SEQ_NO_MAX_VALUE)
}
fn default() -> Self { SeqNo(SEQ_NO_MAX_VALUE) }
}

impl PartialOrd for SeqNo {
Expand Down Expand Up @@ -142,23 +136,17 @@ impl SeqNo {

/// Creates `nSeq` in replace-by-fee mode with the specified order number.
#[inline]
pub fn from_rbf(order: u16) -> SeqNo {
SeqNo(order as u32 | SEQ_NO_CSV_DISABLE_MASK)
}
pub fn from_rbf(order: u16) -> SeqNo { SeqNo(order as u32 | SEQ_NO_CSV_DISABLE_MASK) }

/// Creates `nSeq` in replace-by-fee mode with value 0xFFFFFFFD.
///
/// This value is the value supported by the BitBox software.
#[inline]
pub fn rbf() -> SeqNo {
SeqNo(SEQ_NO_SUBMAX_VALUE - 1)
}
pub fn rbf() -> SeqNo { SeqNo(SEQ_NO_SUBMAX_VALUE - 1) }

/// Creates relative time lock measured in number of blocks (implies RBF).
#[inline]
pub fn from_height(blocks: u16) -> SeqNo {
SeqNo(blocks as u32)
}
pub fn from_height(blocks: u16) -> SeqNo { SeqNo(blocks as u32) }

/// Creates relative time lock measured in number of 512-second intervals
/// (implies RBF).
Expand All @@ -169,9 +157,7 @@ impl SeqNo {

/// Creates time lock basing on bitcoin consensus 32-bit value.
#[inline]
pub fn from_consensus(consensus: u32) -> SeqNo {
SeqNo(consensus)
}
pub fn from_consensus(consensus: u32) -> SeqNo { SeqNo(consensus) }

/// Classifies type of `nSeq` value (see [`SeqNoClass`]).
#[inline]
Expand All @@ -187,23 +173,17 @@ impl SeqNo {
/// Checks if `nSeq` value opts-in for replace-by-fee (also always true for
/// relative time locks).
#[inline]
pub fn is_rbf(self) -> bool {
self.0 < SEQ_NO_SUBMAX_VALUE
}
pub fn is_rbf(self) -> bool { self.0 < SEQ_NO_SUBMAX_VALUE }

/// Checks if `nSeq` value opts-in for relative time locks (also always
/// imply RBG opt-in).
#[inline]
pub fn is_timelock(self) -> bool {
self.0 & SEQ_NO_CSV_DISABLE_MASK > 1
}
pub fn is_timelock(self) -> bool { self.0 & SEQ_NO_CSV_DISABLE_MASK > 1 }

/// Gets full u32 representation of `nSeq` value as it is serialized in
/// bitcoin transaction.
#[inline]
pub fn into_consensus(self) -> u32 {
self.0
}
pub fn into_consensus(self) -> u32 { self.0 }

/// Gets structured relative time lock information from the `nSeq` value.
/// See [`TimeLockInterval`].
Expand Down Expand Up @@ -291,7 +271,6 @@ pub struct InvalidTimelock;
/// UNIX timestamp which is always either 0 or a greater than or equal to
/// 500000000.
#[derive(Copy, Clone, PartialOrd, Ord, Eq, PartialEq, Hash, Debug, Default)]
#[derive(StrictEncode, StrictDecode)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand All @@ -300,9 +279,7 @@ pub struct InvalidTimelock;
pub struct LockTimestamp(u32);

impl From<LockTimestamp> for u32 {
fn from(lock_timestamp: LockTimestamp) -> Self {
lock_timestamp.into_consensus()
}
fn from(lock_timestamp: LockTimestamp) -> Self { lock_timestamp.into_consensus() }
}

impl TryFrom<u32> for LockTimestamp {
Expand All @@ -327,9 +304,7 @@ impl TryFrom<LockTime> for LockTimestamp {
impl LockTimestamp {
/// Create zero time lock
#[inline]
pub fn anytime() -> Self {
Self(0)
}
pub fn anytime() -> Self { Self(0) }

/// Creates absolute time lock valid since the current timestamp.
pub fn since_now() -> Self {
Expand All @@ -354,15 +329,11 @@ impl LockTimestamp {
/// Converts into full u32 representation of `nSeq` value as it is
/// serialized in bitcoin transaction.
#[inline]
pub fn into_consensus(self) -> u32 {
self.0
}
pub fn into_consensus(self) -> u32 { self.0 }

/// Converts into [`LockTime`] representation.
#[inline]
pub fn into_locktime(self) -> LockTime {
self.into()
}
pub fn into_locktime(self) -> LockTime { self.into() }
}

impl Display for LockTimestamp {
Expand Down Expand Up @@ -392,7 +363,6 @@ impl FromStr for LockTimestamp {
/// Value for a transaction `nTimeLock` field which is guaranteed to represent a
/// block height number which is always less than 500000000.
#[derive(Copy, Clone, PartialOrd, Ord, Eq, PartialEq, Hash, Debug, Default)]
#[derive(StrictEncode, StrictDecode)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand All @@ -401,9 +371,7 @@ impl FromStr for LockTimestamp {
pub struct LockHeight(u32);

impl From<LockHeight> for u32 {
fn from(lock_height: LockHeight) -> Self {
lock_height.into_consensus()
}
fn from(lock_height: LockHeight) -> Self { lock_height.into_consensus() }
}

impl TryFrom<u32> for LockHeight {
Expand All @@ -428,9 +396,7 @@ impl TryFrom<LockTime> for LockHeight {
impl LockHeight {
/// Create zero time lock
#[inline]
pub fn anytime() -> Self {
Self(0)
}
pub fn anytime() -> Self { Self(0) }

/// Creates absolute time lock with the given block height.
///
Expand All @@ -448,15 +414,11 @@ impl LockHeight {
/// Converts into full u32 representation of `nSeq` value as it is
/// serialized in bitcoin transaction.
#[inline]
pub fn into_consensus(self) -> u32 {
self.0
}
pub fn into_consensus(self) -> u32 { self.0 }

/// Converts into [`LockTime`] representation.
#[inline]
pub fn into_locktime(self) -> LockTime {
self.into()
}
pub fn into_locktime(self) -> LockTime { self.into() }
}

impl Display for LockHeight {
Expand Down Expand Up @@ -487,7 +449,6 @@ impl FromStr for LockHeight {
/// (>=500000000) or a block height (<500000000). See alse [`LockTimestamp`] and
/// [`LockHeight`] types.
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, From, Default)]
#[derive(StrictEncode, StrictDecode)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand All @@ -511,17 +472,13 @@ impl PartialOrd for LockTime {
}

impl From<LockTime> for u32 {
fn from(lock_time: LockTime) -> Self {
lock_time.into_consensus()
}
fn from(lock_time: LockTime) -> Self { lock_time.into_consensus() }
}

impl LockTime {
/// Create zero time lock
#[inline]
pub fn anytime() -> Self {
Self(0)
}
pub fn anytime() -> Self { Self(0) }

/// Creates absolute time lock valid since the current timestamp.
pub fn since_now() -> Self {
Expand Down Expand Up @@ -556,30 +513,22 @@ impl LockTime {
}

/// Constructs timelock from a bitcoin consensus 32-bit timelock value.
pub fn from_consensus(value: u32) -> Self {
Self(value)
}
pub fn from_consensus(value: u32) -> Self { Self(value) }

/// Checks if the absolute timelock provided by the `nLockTime` value
/// specifies height-based lock
#[inline]
pub fn is_height_based(self) -> bool {
self.0 < LOCKTIME_THRESHOLD
}
pub fn is_height_based(self) -> bool { self.0 < LOCKTIME_THRESHOLD }

/// Checks if the absolute timelock provided by the `nLockTime` value
/// specifies time-based lock
#[inline]
pub fn is_time_based(self) -> bool {
!self.is_height_based()
}
pub fn is_time_based(self) -> bool { !self.is_height_based() }

/// Converts into full u32 representation of `nSeq` value as it is
/// serialized in bitcoin transaction.
#[inline]
pub fn into_consensus(self) -> u32 {
self.0
}
pub fn into_consensus(self) -> u32 { self.0 }
}

impl Display for LockTime {
Expand Down
3 changes: 0 additions & 3 deletions bitcoin_scripts/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ impl SegWitInfo {
/// See also [`bitcoin::Address`] as a non-copy alternative supporting
/// future witness program versions
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From)]
#[derive(StrictEncode, StrictDecode)]
pub struct AddressCompat {
/// Address payload (see [`AddressPayload`]).
pub payload: AddressPayload,
Expand Down Expand Up @@ -129,7 +128,6 @@ impl FromStr for AddressCompat {
#[derive(
Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display, From
)]
#[derive(StrictEncode, StrictDecode)]
pub enum AddressPayload {
/// P2PKH payload.
#[from]
Expand Down Expand Up @@ -463,7 +461,6 @@ impl FromStr for AddressFormat {

/// Bitcoin network used by the address
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
#[derive(StrictEncode, StrictDecode)]
pub enum AddressNetwork {
/// Bitcoin mainnet
#[display("mainnet")]
Expand Down
2 changes: 0 additions & 2 deletions bitcoin_scripts/src/hlc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use serde_with::{As, DisplayFromStr};
#[derive(
Wrapper, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Display, From
)]
#[derive(StrictEncode, StrictDecode)]
#[display(LowerHex)]
#[wrapper(FromStr, LowerHex, UpperHex)]
pub struct HashLock(#[cfg_attr(feature = "serde", serde(with = "As::<DisplayFromStr>"))] Slice32);
Expand Down Expand Up @@ -70,7 +69,6 @@ impl Borrow<[u8]> for HashLock {
#[derive(
Wrapper, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Display, From
)]
#[derive(StrictEncode, StrictDecode)]
#[display(LowerHex)]
#[wrapper(FromStr, LowerHex, UpperHex)]
pub struct HashPreimage(
Expand Down
2 changes: 0 additions & 2 deletions bitcoin_scripts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@
#[macro_use]
extern crate amplify;
#[macro_use]
extern crate strict_encoding;
#[cfg(feature = "serde")]
#[macro_use]
extern crate serde_crate as serde;
Expand Down
Loading

0 comments on commit 70aadcd

Please sign in to comment.