Skip to content

Commit

Permalink
Merge pull request #105 from RGB-WG/hybrid
Browse files Browse the repository at this point in the history
Update to RGB Core v0.11 beta 1
  • Loading branch information
dr-orlovsky authored Nov 9, 2023
2 parents e512508 + 40d635b commit c224669
Show file tree
Hide file tree
Showing 74 changed files with 2,027 additions and 4,195 deletions.
270 changes: 114 additions & 156 deletions Cargo.lock

Large diffs are not rendered by default.

53 changes: 31 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[workspace]
members = [
"std",
".",
"stl"
]
default-members = [
"std",
"."
".",
]
resolver = "2"

[workspace.package]
version = "0.11.0-beta.1"
authors = ["Dr Maxim Orlovsky <orlovsky@lnp-bp.org>"]
homepage = "https://github.com/RGB-WG"
repository = "https://github.com/RGB-WG/rgb-wallet"
Expand All @@ -21,14 +22,15 @@ amplify = "4.5.0"
baid58 = "0.4.4"
strict_encoding = "2.6.1"
strict_types = "1.6.3"
commit_verify = { version = "0.10.6", features = ["stl"] }
bp-core = { version = "0.10.11", features = ["stl"] }
rgb-core = { version = "0.10.8", features = ["stl"] }
commit_verify = { version = "0.11.0-beta.1", features = ["stl"] }
bp-core = { version = "0.11.0-beta.1", features = ["stl"] }
rgb-core = { version = "0.11.0-beta.1", features = ["stl"] }
serde_crate = { package = "serde", version = "1", features = ["derive"] }

[package]
name = "rgb-wallet"
version = "0.10.9"
description = "RGB wallet library for smart contracts on Bitcoin & Lightning network"
name = "rgb-std"
version = { workspace = true }
description = "RGB standard library for working with smart contracts on Bitcoin & Lightning"
keywords = ["bitcoin", "lightning", "rgb", "smart-contracts", "lnp-bp"]
categories = ["cryptography::cryptocurrencies"]
authors = { workspace = true }
Expand All @@ -38,33 +40,37 @@ edition = { workspace = true }
license = { workspace = true }
rust-version = { workspace = true }
readme = "README.md"
exclude = [".github", "std"]

[lib]
name = "rgbwallet"
name = "rgbstd"
crate-type = ["cdylib", "rlib"] # We need this for WASM

[dependencies]
amplify = { workspace = true }
baid58 = { workspace = true }
commit_verify = { workspace = true }
strict_encoding = { workspace = true }
# descriptor-wallet = "0.10.0-alpha.1"
strict_types = { workspace = true }
commit_verify = { workspace = true }
bp-core = { workspace = true }
rgb-core = { workspace = true }
rgb-std = { version = "0.10.8", path = "std" }
fluent-uri = "0.1.4"
baid58 = { workspace = true }
base85 = "=2.0.0"
chrono = "0.4.31"
indexmap = "2.0.2"
# TODO: This dependencies should be replaced with psbt package
bitcoin = "0.30.1"
chrono = "0.4.24"
percent-encoding = "2.2.0"
serde_crate = { workspace = true, optional = true }

[features]
default = []
all = ["fs", "serde"]
serde = ["rgb-std/serde", "rgb-core/serde"]
fs = ["rgb-std/fs"]
serde = [
"serde_crate",
"amplify/serde",
"strict_encoding/serde",
"strict_types/serde",
"commit_verify/serde",
"bp-core/serde",
"rgb-core/serde",
]
fs = []

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2"
Expand All @@ -76,3 +82,6 @@ wasm-bindgen-test = "0.3"

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

[patch.crates-io]
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "v0.11" }
6 changes: 3 additions & 3 deletions scripts/typelib.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

cargo run --bin rgb-stl -- --sty
cargo run --bin rgb-stl -- --stl
cargo run --bin rgb-stl -- --sta
cargo run -p rgb-stl --bin rgb-stl -- --sty
cargo run -p rgb-stl --bin rgb-stl -- --stl
cargo run -p rgb-stl --bin rgb-stl -- --sta
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,23 @@
// limitations under the License.

use amplify::confinement::SmallVec;
use commit_verify::Conceal;
use rgb::{
Assign, AssignAttach, AssignData, AssignFungible, AssignRights, ExposedSeal, ExposedState,
TypedAssigns,
SealDefinition, TypedAssigns,
};

pub trait TypedAssignsExt<Seal: ExposedSeal> {
fn reveal_seal(&mut self, seal: Seal);
fn reveal_seal(&mut self, seal: SealDefinition<Seal>);

fn filter_revealed_seals(&self) -> Vec<Seal>;
fn filter_revealed_seals(&self) -> Vec<SealDefinition<Seal>>;
}

impl<Seal: ExposedSeal> TypedAssignsExt<Seal> for TypedAssigns<Seal> {
fn reveal_seal(&mut self, seal: Seal) {
fn reveal_seal(&mut self, seal: SealDefinition<Seal>) {
fn reveal<State: ExposedState, Seal: ExposedSeal>(
vec: &mut SmallVec<Assign<State, Seal>>,
revealed: Seal,
revealed: SealDefinition<Seal>,
) {
for assign in vec.iter_mut() {
match assign {
Expand Down Expand Up @@ -64,7 +65,7 @@ impl<Seal: ExposedSeal> TypedAssignsExt<Seal> for TypedAssigns<Seal> {
}
}

fn filter_revealed_seals(&self) -> Vec<Seal> {
fn filter_revealed_seals(&self) -> Vec<SealDefinition<Seal>> {
match self {
TypedAssigns::Declarative(s) => {
s.iter().filter_map(AssignRights::revealed_seal).collect()
Expand Down
6 changes: 3 additions & 3 deletions std/src/accessors/bundle.rs → src/accessors/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use rgb::{GraphSeal, OpId, Operation, Transition, TransitionBundle};
use rgb::{GraphSeal, OpId, Operation, SealDefinition, Transition, TransitionBundle};

use crate::accessors::TypedAssignsExt;

Expand All @@ -32,7 +32,7 @@ pub enum RevealError {

pub trait BundleExt {
/// Ensures that the seal is revealed inside the bundle.
fn reveal_seal(&mut self, seal: GraphSeal);
fn reveal_seal(&mut self, seal: SealDefinition<GraphSeal>);

/// Ensures that the transition is revealed inside the bundle.
///
Expand All @@ -44,7 +44,7 @@ pub trait BundleExt {
}

impl BundleExt for TransitionBundle {
fn reveal_seal(&mut self, seal: GraphSeal) {
fn reveal_seal(&mut self, seal: SealDefinition<GraphSeal>) {
for (_, item) in self.keyed_values_mut() {
if let Some(transition) = &mut item.transition {
for (_, assign) in transition.assignments.keyed_values_mut() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub trait MergeReveal: Sized {

impl MergeReveal for Anchor<mpc::MerkleBlock> {
fn merge_reveal(self, other: Self) -> Result<Self, MergeRevealError> {
self.merge_reveal(other).map_err(MergeRevealError::from)
Anchor::merge_reveal(self, other).map_err(MergeRevealError::from)
}
}

Expand Down
File renamed without changes.
166 changes: 86 additions & 80 deletions std/src/containers/bindle.rs → src/containers/bindle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@
use std::collections::BTreeMap;
use std::fmt::{Debug, Display};
use std::io::{self, Read};
use std::ops::Deref;
use std::str::FromStr;

#[cfg(feature = "fs")]
pub use _fs::*;
use amplify::confinement;
use amplify::confinement::{Confined, TinyVec, U24};
use amplify::confinement::{self, Confined, TinyVec, U24};
use baid58::Baid58ParseError;
use rgb::{BundleId, ContractId, Schema, SchemaId, SchemaRoot};
use rgb::{BundleId, ContractId, Schema, SchemaId, SchemaRoot, SubSchema};
use strict_encoding::{
StrictDecode, StrictDeserialize, StrictDumb, StrictEncode, StrictSerialize, StrictType,
StrictDecode, StrictDeserialize, StrictDumb, StrictEncode, StrictReader, StrictSerialize,
StrictType,
};

use crate::containers::transfer::TransferId;
Expand Down Expand Up @@ -277,67 +276,93 @@ impl<C: BindleContent> Display for Bindle<C> {
}
}

impl<C: BindleContent> Bindle<C> {
pub fn load(mut data: impl Read) -> Result<Self, LoadError> {
let mut rgb = [0u8; 3];
let mut magic = [0u8; 4];
data.read_exact(&mut rgb)?;
data.read_exact(&mut magic)?;
if rgb != *b"RGB" || magic != C::MAGIC {
return Err(LoadError::InvalidMagic);
}
let mut reader = StrictReader::with(usize::MAX, data);
let me = Self::strict_decode(&mut reader)?;
Ok(me)
}
}

#[derive(Clone, Debug, From)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase", tag = "type")
)]
pub enum UniversalBindle {
#[from]
#[cfg_attr(feature = "serde", serde(rename = "interface"))]
Iface(Bindle<Iface>),

#[from]
Schema(Bindle<SubSchema>),

#[from]
#[cfg_attr(feature = "serde", serde(rename = "implementation"))]
Impl(Bindle<IfaceImpl>),

#[from]
Contract(Bindle<Contract>),

#[from]
Transfer(Bindle<Transfer>),
}

impl UniversalBindle {
pub fn load(mut data: impl Read) -> Result<Self, LoadError> {
let mut rgb = [0u8; 3];
let mut magic = [0u8; 4];
data.read_exact(&mut rgb)?;
data.read_exact(&mut magic)?;
if rgb != *b"RGB" {
return Err(LoadError::InvalidMagic);
}
let mut reader = StrictReader::with(usize::MAX, data);
Ok(match magic {
x if x == Iface::MAGIC => Bindle::<Iface>::strict_decode(&mut reader)?.into(),
x if x == SubSchema::MAGIC => Bindle::<SubSchema>::strict_decode(&mut reader)?.into(),
x if x == IfaceImpl::MAGIC => Bindle::<IfaceImpl>::strict_decode(&mut reader)?.into(),
x if x == Contract::MAGIC => Bindle::<Contract>::strict_decode(&mut reader)?.into(),
x if x == Transfer::MAGIC => Bindle::<Transfer>::strict_decode(&mut reader)?.into(),
_ => return Err(LoadError::InvalidMagic),
})
}
}

#[derive(Clone, Eq, PartialEq, Debug, Display, Error, From)]
#[display(doc_comments)]
pub enum LoadError {
/// invalid file data.
InvalidMagic,

#[display(inner)]
#[from]
#[from(io::Error)]
Decode(strict_encoding::DecodeError),
}

#[cfg(feature = "fs")]
mod _fs {
use std::io::{Read, Write};
use std::io::Write;
use std::path::Path;
use std::{fs, io};

use rgb::SubSchema;
use strict_encoding::{DecodeError, StrictEncode, StrictReader, StrictWriter};
use strict_encoding::{StrictEncode, StrictWriter};

use super::*;

#[derive(Clone, Eq, PartialEq, Debug, Display, Error, From)]
#[display(doc_comments)]
pub enum LoadError {
/// invalid file data.
InvalidMagic,

#[display(inner)]
#[from]
#[from(io::Error)]
Decode(DecodeError),
}

#[derive(Clone, Debug, From)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase", tag = "type")
)]
pub enum UniversalBindle {
#[from]
#[cfg_attr(feature = "serde", serde(rename = "interface"))]
Iface(Bindle<Iface>),

#[from]
Schema(Bindle<SubSchema>),

#[from]
#[cfg_attr(feature = "serde", serde(rename = "implementation"))]
Impl(Bindle<IfaceImpl>),

#[from]
Contract(Bindle<Contract>),

#[from]
Transfer(Bindle<Transfer>),
}

impl<C: BindleContent> Bindle<C> {
pub fn load(path: impl AsRef<Path>) -> Result<Self, LoadError> {
let mut rgb = [0u8; 3];
let mut magic = [0u8; 4];
let mut file = fs::File::open(path)?;
file.read_exact(&mut rgb)?;
file.read_exact(&mut magic)?;
if rgb != *b"RGB" || magic != C::MAGIC {
return Err(LoadError::InvalidMagic);
}
let mut reader = StrictReader::with(usize::MAX, file);
let me = Self::strict_decode(&mut reader)?;
Ok(me)
pub fn load_file(path: impl AsRef<Path>) -> Result<Self, LoadError> {
let file = fs::File::open(path)?;
Self::load(file)
}

pub fn save(&self, path: impl AsRef<Path>) -> Result<(), io::Error> {
Expand All @@ -351,28 +376,9 @@ mod _fs {
}

impl UniversalBindle {
pub fn load(path: impl AsRef<Path>) -> Result<Self, LoadError> {
let mut rgb = [0u8; 3];
let mut magic = [0u8; 4];
let mut file = fs::File::open(path)?;
file.read_exact(&mut rgb)?;
file.read_exact(&mut magic)?;
if rgb != *b"RGB" {
return Err(LoadError::InvalidMagic);
}
let mut reader = StrictReader::with(usize::MAX, file);
Ok(match magic {
x if x == Iface::MAGIC => Bindle::<Iface>::strict_decode(&mut reader)?.into(),
x if x == SubSchema::MAGIC => {
Bindle::<SubSchema>::strict_decode(&mut reader)?.into()
}
x if x == IfaceImpl::MAGIC => {
Bindle::<IfaceImpl>::strict_decode(&mut reader)?.into()
}
x if x == Contract::MAGIC => Bindle::<Contract>::strict_decode(&mut reader)?.into(),
x if x == Transfer::MAGIC => Bindle::<Transfer>::strict_decode(&mut reader)?.into(),
_ => return Err(LoadError::InvalidMagic),
})
pub fn load_file(path: impl AsRef<Path>) -> Result<Self, LoadError> {
let file = fs::File::open(path)?;
Self::load(file)
}
}
}
File renamed without changes.
Loading

0 comments on commit c224669

Please sign in to comment.