Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.11.0 beta 1 #64

Merged
merged 6 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
#[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 @@
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 Expand Up @@ -564,7 +546,7 @@
pub fn with_bytes(version: LeafVer, script: Vec<u8>) -> Result<Self, confinement::Error> {
Ok(LeafScript {
version,
script: ScriptBytes::try_from(script)?,

Check warning on line 549 in consensus/src/taproot.rs

View check run for this annotation

Codecov / codecov/patch

consensus/src/taproot.rs#L549

Added line #L549 was not covered by tests
})
}
#[inline]
Expand Down Expand Up @@ -620,9 +602,9 @@

impl TryFrom<Vec<u8>> for TapScript {
type Error = confinement::Error;
fn try_from(script_bytes: Vec<u8>) -> Result<Self, Self::Error> {
ScriptBytes::try_from(script_bytes).map(Self)
}

Check warning on line 607 in consensus/src/taproot.rs

View check run for this annotation

Codecov / codecov/patch

consensus/src/taproot.rs#L605-L607

Added lines #L605 - L607 were not covered by tests
}

impl TapScript {
Expand All @@ -637,9 +619,9 @@
/// Constructs script object assuming the script length is less than 4GB.
/// Panics otherwise.
#[inline]
pub fn from_unsafe(script_bytes: Vec<u8>) -> Self {
Self(ScriptBytes::from_unsafe(script_bytes))
}

Check warning on line 624 in consensus/src/taproot.rs

View check run for this annotation

Codecov / codecov/patch

consensus/src/taproot.rs#L622-L624

Added lines #L622 - L624 were not covered by tests

/// Adds a single opcode to the script.
#[inline]
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
Loading