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

Update to RGB Core v0.11 beta 1 #105

Merged
merged 43 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9be5afc
refactor crates
dr-orlovsky Aug 1, 2023
325cf5b
refactor: include rgb-invoice crate
dr-orlovsky Aug 1, 2023
06d02c9
chore: update to resolver=2
dr-orlovsky Aug 1, 2023
82f6e1e
Merge branch 'master' into v0.11
dr-orlovsky Aug 1, 2023
f9fca92
interface: add convenience wrappers to OutpointFilter
dr-orlovsky Aug 2, 2023
4f816fe
containers: provide way for Bindles to load from in-memory data
dr-orlovsky Aug 4, 2023
5e21ad6
stl: improve CoinAmount display
dr-orlovsky Aug 4, 2023
7c4d490
move descriptor as a feature from rgb-runtime
dr-orlovsky Aug 6, 2023
8565fc3
stl: derive Hash for spec types missing it
dr-orlovsky Aug 6, 2023
78c1615
derive Hash on types missing it
dr-orlovsky Aug 6, 2023
e0df0e3
stl: implement Display for RicardianContract
dr-orlovsky Aug 6, 2023
352420b
iface: make RGB20 to return Amount in balance method
dr-orlovsky Aug 6, 2023
77a9939
descriptor: add default empty option
dr-orlovsky Aug 6, 2023
7e8f85c
stl: add convenience convertors to Precision
dr-orlovsky Aug 6, 2023
94d7dee
stl: add Amount and Precision arithmetics
dr-orlovsky Aug 7, 2023
1615823
stl: improve CoinAmount methods
dr-orlovsky Aug 7, 2023
17b9fec
chore: update to the new bp-std Keychain API
dr-orlovsky Aug 9, 2023
006ba12
descriptor: add serde serialization for descriptors
dr-orlovsky Aug 9, 2023
148d4be
descriptor: add RgbKeychain enum
dr-orlovsky Aug 9, 2023
c8a0a8f
descriptor: fix keychain display format
dr-orlovsky Aug 11, 2023
9cafedb
descriptor: add serde derivations to RgbKeychain
dr-orlovsky Aug 12, 2023
25fdeaa
descriptor: add converter functions
dr-orlovsky Aug 12, 2023
a3ec616
descriptor: impl From<K> for TapretKey
dr-orlovsky Aug 12, 2023
e50af46
iface: provide simple API to get a standard interface wrapper (Rgb20 …
dr-orlovsky Aug 15, 2023
3294d67
iface: make interface wrapper APIs more consistent
dr-orlovsky Aug 15, 2023
5898c9e
chore: update dependencies
dr-orlovsky Oct 5, 2023
69eb429
chore: update dependencies
dr-orlovsky Oct 9, 2023
fb3f13f
Merge branch 'v0.11' into hybrid
dr-orlovsky Oct 9, 2023
d15d2be
chore: remove unneeded code
dr-orlovsky Oct 10, 2023
6064d28
chore: refactor back std crate to be at the repo root
dr-orlovsky Oct 10, 2023
1fd676f
chore: fix build
dr-orlovsky Oct 10, 2023
a78ee05
Merge branch 'master' into hybrid
dr-orlovsky Nov 4, 2023
6414c20
iface: move SchemaTypeIndex from RB Core lib
dr-orlovsky Nov 4, 2023
b54e775
chore: update to RGB Core v0.11. Part 1: seal definitions and asset tags
dr-orlovsky Nov 5, 2023
8db4140
update resolver API
dr-orlovsky Nov 6, 2023
5f65ee7
chore: continue refactoring for multi-chain
dr-orlovsky Nov 7, 2023
d85d6a6
chore: fix clippy lints
dr-orlovsky Nov 8, 2023
b2b6786
chore: remove outdated descriptor mod
dr-orlovsky Nov 8, 2023
e0f4558
chore: fix export of bindle-related types
dr-orlovsky Nov 8, 2023
f4330ac
chore: fix clippy lints
dr-orlovsky Nov 8, 2023
932d33a
chore: update stl and compiled RGB interface files
dr-orlovsky Nov 8, 2023
f5b8b04
chore: rename library to rgbstd to avoid conflicts with rgbcore
dr-orlovsky Nov 8, 2023
40d635b
chore: run cargo update
dr-orlovsky Nov 8, 2023
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
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 <[email protected]>"]
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>) {

Check warning on line 36 in src/accessors/assignments.rs

View check run for this annotation

Codecov / codecov/patch

src/accessors/assignments.rs#L36

Added line #L36 was not covered by tests
fn reveal<State: ExposedState, Seal: ExposedSeal>(
vec: &mut SmallVec<Assign<State, Seal>>,
revealed: Seal,
revealed: SealDefinition<Seal>,

Check warning on line 39 in src/accessors/assignments.rs

View check run for this annotation

Codecov / codecov/patch

src/accessors/assignments.rs#L39

Added line #L39 was not covered by tests
) {
for assign in vec.iter_mut() {
match assign {
Expand Down Expand Up @@ -64,7 +65,7 @@
}
}

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

Check warning on line 68 in src/accessors/assignments.rs

View check run for this annotation

Codecov / codecov/patch

src/accessors/assignments.rs#L68

Added line #L68 was not covered by tests
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 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 @@
}

impl BundleExt for TransitionBundle {
fn reveal_seal(&mut self, seal: GraphSeal) {
fn reveal_seal(&mut self, seal: SealDefinition<GraphSeal>) {

Check warning on line 47 in src/accessors/bundle.rs

View check run for this annotation

Codecov / codecov/patch

src/accessors/bundle.rs#L47

Added line #L47 was not covered by tests
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 @@

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)

Check warning on line 69 in src/accessors/merge_reveal.rs

View check run for this annotation

Codecov / codecov/patch

src/accessors/merge_reveal.rs#L69

Added line #L69 was not covered by tests
}
}

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> 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)
}

Check warning on line 291 in src/containers/bindle.rs

View check run for this annotation

Codecov / codecov/patch

src/containers/bindle.rs#L280-L291

Added lines #L280 - L291 were not covered by tests
}

#[derive(Clone, Debug, From)]

Check warning on line 294 in src/containers/bindle.rs

View check run for this annotation

Codecov / codecov/patch

src/containers/bindle.rs#L294

Added line #L294 was not covered by tests
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),

Check warning on line 297 in src/containers/bindle.rs

View check run for this annotation

Codecov / codecov/patch

src/containers/bindle.rs#L297

Added line #L297 was not covered by tests
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),

Check warning on line 335 in src/containers/bindle.rs

View check run for this annotation

Codecov / codecov/patch

src/containers/bindle.rs#L320-L335

Added lines #L320 - L335 were not covered by tests
})
}

Check warning on line 337 in src/containers/bindle.rs

View check run for this annotation

Codecov / codecov/patch

src/containers/bindle.rs#L337

Added line #L337 was not covered by tests
}

#[derive(Clone, Eq, PartialEq, Debug, Display, Error, From)]

Check warning on line 340 in src/containers/bindle.rs

View check run for this annotation

Codecov / codecov/patch

src/containers/bindle.rs#L340

Added line #L340 was not covered by tests
#[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)

Check warning on line 365 in src/containers/bindle.rs

View check run for this annotation

Codecov / codecov/patch

src/containers/bindle.rs#L363-L365

Added lines #L363 - L365 were not covered by tests
}

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

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)

Check warning on line 381 in src/containers/bindle.rs

View check run for this annotation

Codecov / codecov/patch

src/containers/bindle.rs#L379-L381

Added lines #L379 - L381 were not covered by tests
}
}
}
File renamed without changes.
Loading
Loading