Skip to content

Commit

Permalink
Merge pull request #64 from BP-WG/v0.11
Browse files Browse the repository at this point in the history
Release v0.11.0 beta 1
  • Loading branch information
dr-orlovsky authored Nov 2, 2023
2 parents e8273b7 + d022312 commit aa0e7f7
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 256 deletions.
25 changes: 14 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 5 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ default-members = [
]

[workspace.package]
version = "0.10.11"
version = "0.11.0-beta.1"
authors = ["Dr Maxim Orlovsky <[email protected]>"]
homepage = "https://github.com/BP-WG"
repository = "https://github.com/BP-WG/bp-core"
Expand All @@ -27,10 +27,10 @@ strict_encoding = "2.6.1"
strict_types = "1.6.3"
commit_verify = "0.11.0-beta.1"
single_use_seals = "0.11.0-beta.1"
bp-consensus = { version = "0.10.11", path = "consensus" }
bp-dbc = { version = "0.10.11", path = "./dbc" }
bp-seals = { version = "0.10.11", path = "./seals" }
secp256k1 = { version = "0.27.0", features = ["global-context"] }
bp-consensus = { version = "0.11.0-beta.1", path = "consensus" }
bp-dbc = { version = "0.11.0-beta.1", path = "./dbc" }
bp-seals = { version = "0.11.0-beta.1", path = "./seals" }
secp256k1 = { version = "0.28.0", features = ["global-context"] }
serde_crate = { package = "serde", version = "1", features = ["derive"] }

[package]
Expand Down Expand Up @@ -81,7 +81,3 @@ stl = ["strict_types", "strict_types/base64", "bp-consensus/stl", "commit_verify

[package.metadata.docs.rs]
features = [ "all" ]

[patch.crates-io]
commit_verify = { git = "https://github.com/LNP-BP/client_side_validation", branch = "v0.11" }
single_use_seals = { git = "https://github.com/LNP-BP/client_side_validation", branch = "v0.11" }
2 changes: 1 addition & 1 deletion consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub use timelocks::{
pub use tx::{
Outpoint, OutpointParseError, Sats, Tx, TxIn, TxOut, TxParseError, TxVer, Txid, Vout,
};
pub use util::{Chain, ChainParseError, NonStandardValue};
pub use util::NonStandardValue;
pub use weights::{VBytes, Weight, WeightUnits};

pub const LIB_NAME_BITCOIN: &str = "Bitcoin";
5 changes: 2 additions & 3 deletions consensus/src/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use strict_types::{CompileError, LibBuilder, TypeLib};

use crate::timelocks::TimeLockInterval;
use crate::{
Bip340Sig, BlockHeader, ByteStr, Chain, CompressedPk, ControlBlock, FutureLeafVer, InternalPk,
Bip340Sig, BlockHeader, ByteStr, CompressedPk, ControlBlock, FutureLeafVer, InternalPk,
LeafScript, LegacyPk, LegacySig, LockHeight, LockTimestamp, OpCode, OutputPk, PubkeyHash,
RedeemScript, ScriptHash, TapCode, TapLeafHash, TapNodeHash, TapScript, Tx, UncompressedPk,
VBytes, VarInt, WPubkeyHash, WScriptHash, WeightUnits, WitnessProgram, WitnessScript,
Expand All @@ -37,7 +37,7 @@ pub const LIB_ID_BITCOIN: &str =
pub const LIB_ID_BP_TX: &str =
"urn:ubideco:stl:HX2UBak8vPsTokug1DGMDvTpzns3xUdwZ7QJdyt4qBA9#speed-atlanta-trilogy";
pub const LIB_ID_BP_CONSENSUS: &str =
"urn:ubideco:stl:8nFxDqDPmHD15hQf1npGQbDfpRX4Y9hXoo7VfarMJX11#urgent-viva-ninja";
"urn:ubideco:stl:DQtzB8Kcfm7XeuhWf8sv3n31c5V2qK6VS1Zbye76haUQ#erosion-quiet-kinetic";

#[deprecated(since = "0.10.8", note = "use _bp_tx_stl instead")]
fn _bitcoin_stl() -> Result<TypeLib, CompileError> { _bp_tx_stl() }
Expand Down Expand Up @@ -83,7 +83,6 @@ fn _bp_consensus_stl() -> Result<TypeLib, CompileError> {
.transpile::<Tx>()
.transpile::<VarInt>()
.transpile::<ByteStr>()
.transpile::<Chain>()
.transpile::<WeightUnits>()
.transpile::<VBytes>()
.compile()
Expand Down
20 changes: 1 addition & 19 deletions consensus/src/taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl FromStr for XOnlyPk {
#[derive(Wrapper, WrapperMut, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From)]
#[wrapper(Deref, LowerHex, Display, FromStr)]
#[wrapper_mut(DerefMut)]
#[derive(StrictType, StrictDumb)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_BITCOIN)]
#[cfg_attr(
feature = "serde",
Expand Down Expand Up @@ -205,24 +205,6 @@ impl From<InternalPk> for [u8; 32] {
fn from(pk: InternalPk) -> [u8; 32] { pk.to_byte_array() }
}

// TODO: Remove custom implementation in v0.11
impl StrictEncode for InternalPk {
fn strict_encode<W: TypedWrite>(&self, writer: W) -> io::Result<W> {
let bytes = Bytes32::from(self.0.serialize());
writer.write_newtype::<Self>(&bytes)
}
}

impl StrictDecode for InternalPk {
fn strict_decode(reader: &mut impl TypedRead) -> Result<Self, DecodeError> {
reader.read_tuple(|r| {
let bytes: Bytes32 = r.read_field()?;
let pk = XOnlyPk::from_byte_array(bytes.to_byte_array())?;
Ok(InternalPk(pk))
})
}
}

/// Output taproot key - an [`InternalPk`] tweaked with merkle root of the
/// script tree - or its own hash. Used only inside addresses and raw taproot
/// descriptors.
Expand Down
86 changes: 0 additions & 86 deletions consensus/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
// limitations under the License.

use std::fmt::{Debug, Display};
use std::str::FromStr;

use crate::LIB_NAME_BITCOIN;

/// the provided value {value} for {matter} is non-standard; while it is
/// accepted by the bitcoin consensus rules, the software prohibits from using
Expand All @@ -37,86 +34,3 @@ pub struct NonStandardValue<T: Debug + Display> {
impl<T: Debug + Display> NonStandardValue<T> {
pub const fn with(value: T, matter: &'static str) -> Self { NonStandardValue { value, matter } }
}

#[derive(Clone, Eq, PartialEq, Debug, Display, Error)]
#[display("invalid blockchain name '{0}'")]
pub struct ChainParseError(String);

#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Display, Default)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_BITCOIN, tags = repr, into_u8, try_from_u8)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict)]
#[repr(u8)]
// TODO: v0.11 make non_exhaustive
pub enum Chain {
#[default]
#[display("mainnet")]
Bitcoin = 0x00,

#[display("testnet")]
Testnet3 = 0x83,

#[display("regtest")]
Regtest = 0x80,

#[display("signet")]
Signet = 0x84,
}

impl Chain {
#[inline]
pub fn is_test_chain(self) -> bool {
match self {
Chain::Bitcoin => false,
Chain::Testnet3 | Chain::Regtest | Chain::Signet => true,
}
}
}

impl FromStr for Chain {
type Err = ChainParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let chain = s.to_lowercase();
Ok(match chain.as_str() {
"mainnet" | "bitcoin" => Chain::Bitcoin,
"testnet" | "testnet3" => Chain::Testnet3,
"regtest" => Chain::Regtest,
"signet" => Chain::Signet,
_ => return Err(ChainParseError(chain)),
})
}
}

#[cfg(feature = "serde")]
mod _serde {
use serde::de::Error;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

use super::*;

impl Serialize for Chain {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer {
if serializer.is_human_readable() {
self.to_string().serialize(serializer)
} else {
(*self as u8).serialize(serializer)
}
}
}

impl<'de> Deserialize<'de> for Chain {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de> {
if deserializer.is_human_readable() {
let s = String::deserialize(deserializer)?;
Chain::from_str(&s).map_err(D::Error::custom)
} else {
let v = u8::deserialize(deserializer)?;
Chain::try_from(v).map_err(D::Error::custom)
}
}
}
}
2 changes: 1 addition & 1 deletion src/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use strict_types::{CompileError, LibBuilder, TypeLib};
/// Strict types id for the library providing data types from [`dbc`] and
/// [`seals`] crates.
pub const LIB_ID_BPCORE: &str =
"urn:ubideco:stl:8RW9jc3Za592QYvum2jiPDtXjpjVdBzT8J2nurNmKX2o#change-mango-survive";
"urn:ubideco:stl:E4xYrMV4cHgYhTPzrjG3DxzAyLEMnbvnsrBsGhQP4anV#quest-harlem-mirror";

fn _bp_core_stl() -> Result<TypeLib, CompileError> {
LibBuilder::new(libname!(LIB_NAME_BPCORE), tiny_bset! {
Expand Down
Loading

0 comments on commit aa0e7f7

Please sign in to comment.