From 1077ec6fe650517e0e870c086d977908c9707a5a Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sat, 13 May 2023 10:54:53 +0200 Subject: [PATCH 01/33] stl: update to type names to match RGB-31 --- std/src/bin/rgb-stl.rs | 2 +- std/src/interface/rgb20.rs | 5 +- std/src/stl.rs | 123 ++++++++++++++++++++++++++----------- 3 files changed, 91 insertions(+), 39 deletions(-) diff --git a/std/src/bin/rgb-stl.rs b/std/src/bin/rgb-stl.rs index 0ab7988f..e6da41e0 100644 --- a/std/src/bin/rgb-stl.rs +++ b/std/src/bin/rgb-stl.rs @@ -41,7 +41,7 @@ fn main() -> Result<(), Box> { let filename = args .get(2) .cloned() - .unwrap_or_else(|| format!("stl/RGBContracts-v0.10.2.A.{ext}")); + .unwrap_or_else(|| format!("stl/RGBContracts-v0.10.3.A.{ext}")); let mut file = match args.len() { 1 => Box::new(stdout()) as Box, 2 | 3 => Box::new(fs::File::create(filename)?) as Box, diff --git a/std/src/interface/rgb20.rs b/std/src/interface/rgb20.rs index d10d8d31..e5d6c4bb 100644 --- a/std/src/interface/rgb20.rs +++ b/std/src/interface/rgb20.rs @@ -32,8 +32,9 @@ pub fn rgb20() -> Iface { version: VerNo::V1, name: tn!("RGB20"), global_state: tiny_bmap! { - tn!("Nominal") => Req::require(types.get("RGBContract.Nominal")), - tn!("ContractText") => Req::require(types.get("RGBContract.ContractText")), + tn!("spec") => Req::require(types.get("RGBContract.DivisibleAssetSpec")), + tn!("ContractText") => Req::require(types.get("RGBContract.RicardianContract")), + }, assignments: tiny_bmap! { tn!("Assets") => AssignIface::private(OwnedIface::Amount), diff --git a/std/src/stl.rs b/std/src/stl.rs index 2e0ea071..149d6d34 100644 --- a/std/src/stl.rs +++ b/std/src/stl.rs @@ -26,12 +26,12 @@ use std::fmt::{Debug, Formatter}; use std::str::FromStr; use amplify::ascii::AsciiString; -use amplify::confinement::{Confined, SmallString}; +use amplify::confinement::{Confined, NonEmptyString, SmallString, U8}; use amplify::IoError; use baid58::Baid58ParseError; use bp::dbc::LIB_NAME_BPCORE; use bp::LIB_NAME_BITCOIN; -use strict_encoding::{InvalidIdent, StrictDeserialize, StrictDumb, StrictSerialize}; +use strict_encoding::{InvalidIdent, StrictDeserialize, StrictDumb, StrictSerialize, StrictType}; use strict_types::typelib::{LibBuilder, TranslateError}; use strict_types::typesys::SystemBuilder; use strict_types::{typesys, Dependency, SemId, TypeLib, TypeLibId, TypeSystem}; @@ -49,6 +49,8 @@ pub const LIB_NAME_RGB_CONTRACT: &str = "RGBContract"; serde(crate = "serde_crate", transparent) )] pub struct Timestamp(i32); +impl StrictSerialize for Timestamp {} +impl StrictDeserialize for Timestamp {} #[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Default)] #[repr(u8)] @@ -94,6 +96,8 @@ impl StrictDeserialize for Precision {} serde(crate = "serde_crate", transparent) )] pub struct Ticker(Confined); +impl StrictSerialize for Ticker {} +impl StrictDeserialize for Ticker {} impl FromStr for Ticker { type Err = InvalidIdent; @@ -152,35 +156,39 @@ impl Debug for Ticker { derive(Serialize, Deserialize), serde(crate = "serde_crate", transparent) )] -pub struct ContractName(Confined); +pub struct Name(Confined); +impl StrictSerialize for Name {} +impl StrictDeserialize for Name {} -impl StrictDumb for ContractName { - fn strict_dumb() -> Self { Self(Confined::try_from(s!("Dumb contract name")).unwrap()) } +impl StrictDumb for Name { + fn strict_dumb() -> Self { Name::from("Dumb contract name") } } -impl FromStr for ContractName { +impl FromStr for Name { type Err = InvalidIdent; fn from_str(s: &str) -> Result { + let s = AsciiString::from_ascii(s.as_bytes())?; let s = Confined::try_from_iter(s.chars())?; Ok(Self(s)) } } -impl From<&'static str> for ContractName { +impl From<&'static str> for Name { fn from(s: &'static str) -> Self { Self::from_str(s).expect("invalid ticker name") } } -impl TryFrom for ContractName { +impl TryFrom for Name { type Error = InvalidIdent; fn try_from(name: String) -> Result { + let name = AsciiString::from_ascii(name.as_bytes())?; let s = Confined::try_from(name)?; Ok(Self(s)) } } -impl Debug for ContractName { +impl Debug for Name { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_tuple("ContractName").field(&self.as_str()).finish() } @@ -195,15 +203,17 @@ impl Debug for ContractName { derive(Serialize, Deserialize), serde(crate = "serde_crate", transparent) )] -pub struct ContractDetails(Confined); +pub struct Details(NonEmptyString); +impl StrictSerialize for Details {} +impl StrictDeserialize for Details {} -impl StrictDumb for ContractDetails { +impl StrictDumb for Details { fn strict_dumb() -> Self { Self(Confined::try_from(s!("Dumb long description which is stupid and so on...")).unwrap()) } } -impl FromStr for ContractDetails { +impl FromStr for Details { type Err = InvalidIdent; fn from_str(s: &str) -> Result { @@ -212,11 +222,11 @@ impl FromStr for ContractDetails { } } -impl From<&'static str> for ContractDetails { +impl From<&'static str> for Details { fn from(s: &'static str) -> Self { Self::from_str(s).expect("invalid ticker name") } } -impl TryFrom for ContractDetails { +impl TryFrom for Details { type Error = InvalidIdent; fn try_from(name: String) -> Result { @@ -225,7 +235,7 @@ impl TryFrom for ContractDetails { } } -impl Debug for ContractDetails { +impl Debug for Details { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_tuple("ContractDetails") .field(&self.as_str()) @@ -241,30 +251,71 @@ impl Debug for ContractDetails { derive(Serialize, Deserialize), serde(crate = "serde_crate", rename_all = "camelCase") )] -pub struct Nominal { - ticker: Ticker, - name: ContractName, - details: Option, - precision: Precision, +pub struct AssetNaming { + pub ticker: Ticker, + pub name: Name, + pub details: Option
, } -impl StrictSerialize for Nominal {} -impl StrictDeserialize for Nominal {} +impl StrictSerialize for AssetNaming {} +impl StrictDeserialize for AssetNaming {} -impl Nominal { - pub fn new(ticker: &'static str, name: &'static str, precision: Precision) -> Nominal { - Nominal { +impl AssetNaming { + pub fn new(ticker: &'static str, name: &'static str) -> AssetNaming { + AssetNaming { ticker: Ticker::from(ticker), - name: ContractName::from(name), + name: Name::from(name), details: None, - precision, } } - pub fn with(ticker: &str, name: &str, precision: Precision) -> Result { - Ok(Nominal { + pub fn with( + ticker: &str, + name: &str, + details: Option<&str>, + ) -> Result { + Ok(AssetNaming { ticker: Ticker::try_from(ticker.to_owned())?, - name: ContractName::try_from(name.to_owned())?, - details: None, + name: Name::try_from(name.to_owned())?, + details: details.map(Details::from_str).transpose()?, + }) + } +} + +#[derive(Clone, Eq, PartialEq, Debug)] +#[derive(StrictDumb, StrictType, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB_CONTRACT)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", rename_all = "camelCase") +)] +pub struct DivisibleAssetSpec { + pub naming: AssetNaming, + pub precision: Precision, +} +impl StrictSerialize for DivisibleAssetSpec {} +impl StrictDeserialize for DivisibleAssetSpec {} + +impl DivisibleAssetSpec { + pub fn new( + ticker: &'static str, + name: &'static str, + precision: Precision, + ) -> DivisibleAssetSpec { + DivisibleAssetSpec { + naming: AssetNaming::new(ticker, name), + precision, + } + } + + pub fn with( + ticker: &str, + name: &str, + precision: Precision, + details: Option<&str>, + ) -> Result { + Ok(DivisibleAssetSpec { + naming: AssetNaming::with(ticker, name, details)?, precision, }) } @@ -278,9 +329,9 @@ impl Nominal { derive(Serialize, Deserialize), serde(crate = "serde_crate", transparent) )] -pub struct ContractText(SmallString); -impl StrictSerialize for ContractText {} -impl StrictDeserialize for ContractText {} +pub struct RicardianContract(SmallString); +impl StrictSerialize for RicardianContract {} +impl StrictDeserialize for RicardianContract {} #[derive(Debug, From)] enum Error { @@ -316,8 +367,8 @@ impl StandardLib { LibBuilder::new(libname!(LIB_NAME_RGB_CONTRACT)) .process::()? - .process::()? - .process::()? + .process::()? + .process::()? .compile(imports) .map_err(Error::from) } From 2aa1f42f6b31f7afc4ccad1cd9a40ce720927682 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sat, 13 May 2023 11:02:24 +0200 Subject: [PATCH 02/33] stl: refactor module --- std/src/stl/error.rs | 39 +++++++++++++++ std/src/stl/mod.rs | 32 ++++++++++++ std/src/{stl.rs => stl/specs.rs} | 78 +---------------------------- std/src/stl/stl.rs | 85 ++++++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+), 77 deletions(-) create mode 100644 std/src/stl/error.rs create mode 100644 std/src/stl/mod.rs rename std/src/{stl.rs => stl/specs.rs} (80%) create mode 100644 std/src/stl/stl.rs diff --git a/std/src/stl/error.rs b/std/src/stl/error.rs new file mode 100644 index 00000000..e40b1e45 --- /dev/null +++ b/std/src/stl/error.rs @@ -0,0 +1,39 @@ +// RGB standard library for working with smart contracts on Bitcoin & Lightning +// +// SPDX-License-Identifier: Apache-2.0 +// +// Written in 2019-2023 by +// Dr Maxim Orlovsky +// +// Copyright (C) 2019-2023 LNP/BP Standards Association. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use amplify::IoError; +use baid58::Baid58ParseError; +use strict_types::typelib::TranslateError; +use strict_types::typesys; + +#[derive(Debug, From)] +pub(super) enum Error { + #[from(std::io::Error)] + Io(IoError), + #[from] + Baid58(Baid58ParseError), + #[from] + Translate(TranslateError), + #[from] + Compile(typesys::Error), + #[from] + Link(Vec), +} diff --git a/std/src/stl/mod.rs b/std/src/stl/mod.rs new file mode 100644 index 00000000..7c5f0336 --- /dev/null +++ b/std/src/stl/mod.rs @@ -0,0 +1,32 @@ +// RGB standard library for working with smart contracts on Bitcoin & Lightning +// +// SPDX-License-Identifier: Apache-2.0 +// +// Written in 2019-2023 by +// Dr Maxim Orlovsky +// +// Copyright (C) 2019-2023 LNP/BP Standards Association. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +mod specs; +mod stl; +mod error; + +pub(self) use error::Error; +pub use specs::{ + AssetNaming, Details, DivisibleAssetSpec, Name, Precision, RicardianContract, Ticker, Timestamp, +}; +pub use stl::{StandardLib, StandardTypes}; + +pub const LIB_NAME_RGB_CONTRACT: &str = "RGBContract"; diff --git a/std/src/stl.rs b/std/src/stl/specs.rs similarity index 80% rename from std/src/stl.rs rename to std/src/stl/specs.rs index 149d6d34..41fb654b 100644 --- a/std/src/stl.rs +++ b/std/src/stl/specs.rs @@ -27,16 +27,9 @@ use std::str::FromStr; use amplify::ascii::AsciiString; use amplify::confinement::{Confined, NonEmptyString, SmallString, U8}; -use amplify::IoError; -use baid58::Baid58ParseError; -use bp::dbc::LIB_NAME_BPCORE; -use bp::LIB_NAME_BITCOIN; use strict_encoding::{InvalidIdent, StrictDeserialize, StrictDumb, StrictSerialize, StrictType}; -use strict_types::typelib::{LibBuilder, TranslateError}; -use strict_types::typesys::SystemBuilder; -use strict_types::{typesys, Dependency, SemId, TypeLib, TypeLibId, TypeSystem}; -pub const LIB_NAME_RGB_CONTRACT: &str = "RGBContract"; +use super::LIB_NAME_RGB_CONTRACT; #[derive(Wrapper, WrapperMut, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Default, From)] #[wrapper(Deref, Display, FromStr, MathOps)] @@ -332,72 +325,3 @@ impl DivisibleAssetSpec { pub struct RicardianContract(SmallString); impl StrictSerialize for RicardianContract {} impl StrictDeserialize for RicardianContract {} - -#[derive(Debug, From)] -enum Error { - #[from(std::io::Error)] - Io(IoError), - #[from] - Baid58(Baid58ParseError), - #[from] - Translate(TranslateError), - #[from] - Compile(typesys::Error), - #[from] - Link(Vec), -} - -#[derive(Debug)] -pub struct StandardLib(TypeLib); - -impl StandardLib { - pub fn new() -> Self { - fn builder() -> Result { - let bitcoin_id = TypeLibId::from_str( - "circus_report_jeep_2bj6eDer24ZBSVq6JgQW2BrARt6vx56vMWzF35J45gzY", - )?; - let bpcore_id = TypeLibId::from_str( - "harlem_null_puma_DxuLX8d9UiMyEJMRJivMFviK1B8t1QWyjywXuDC13iKR", - )?; - - let imports = bset! { - Dependency::with(bitcoin_id, libname!(LIB_NAME_BITCOIN)), - Dependency::with(bpcore_id, libname!(LIB_NAME_BPCORE)), - }; - - LibBuilder::new(libname!(LIB_NAME_RGB_CONTRACT)) - .process::()? - .process::()? - .process::()? - .compile(imports) - .map_err(Error::from) - } - - Self(builder().expect("error in standard RGBContract type library")) - } - - pub fn type_lib(&self) -> TypeLib { self.0.clone() } -} - -#[derive(Debug)] -pub struct StandardTypes(TypeSystem); - -impl StandardTypes { - pub fn new() -> Self { - fn builder() -> Result { - let lib = StandardLib::new().type_lib(); - let sys = SystemBuilder::new().import(lib)?.finalize()?; - Ok(sys) - } - - Self(builder().expect("error in standard RGBContract type system")) - } - - pub fn type_system(&self) -> TypeSystem { self.0.clone() } - - pub fn get(&self, name: &'static str) -> SemId { - self.0 - .id_by_name(name) - .expect("type is absent in standard RGBContract type library") - } -} diff --git a/std/src/stl/stl.rs b/std/src/stl/stl.rs new file mode 100644 index 00000000..57444cd1 --- /dev/null +++ b/std/src/stl/stl.rs @@ -0,0 +1,85 @@ +// RGB standard library for working with smart contracts on Bitcoin & Lightning +// +// SPDX-License-Identifier: Apache-2.0 +// +// Written in 2019-2023 by +// Dr Maxim Orlovsky +// +// Copyright (C) 2019-2023 LNP/BP Standards Association. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use std::str::FromStr; + +use bp::dbc::LIB_NAME_BPCORE; +use bp::LIB_NAME_BITCOIN; +use strict_types::typelib::LibBuilder; +use strict_types::typesys::SystemBuilder; +use strict_types::{Dependency, SemId, TypeLib, TypeLibId, TypeSystem}; + +use super::{DivisibleAssetSpec, Error, RicardianContract, Timestamp, LIB_NAME_RGB_CONTRACT}; + +#[derive(Debug)] +pub struct StandardLib(TypeLib); + +impl StandardLib { + pub fn new() -> Self { + fn builder() -> Result { + let bitcoin_id = TypeLibId::from_str( + "circus_report_jeep_2bj6eDer24ZBSVq6JgQW2BrARt6vx56vMWzF35J45gzY", + )?; + let bpcore_id = TypeLibId::from_str( + "harlem_null_puma_DxuLX8d9UiMyEJMRJivMFviK1B8t1QWyjywXuDC13iKR", + )?; + + let imports = bset! { + Dependency::with(bitcoin_id, libname!(LIB_NAME_BITCOIN)), + Dependency::with(bpcore_id, libname!(LIB_NAME_BPCORE)), + }; + + LibBuilder::new(libname!(LIB_NAME_RGB_CONTRACT)) + .process::()? + .process::()? + .process::()? + .compile(imports) + .map_err(Error::from) + } + + Self(builder().expect("error in standard RGBContract type library")) + } + + pub fn type_lib(&self) -> TypeLib { self.0.clone() } +} + +#[derive(Debug)] +pub struct StandardTypes(TypeSystem); + +impl StandardTypes { + pub fn new() -> Self { + fn builder() -> Result { + let lib = StandardLib::new().type_lib(); + let sys = SystemBuilder::new().import(lib)?.finalize()?; + Ok(sys) + } + + Self(builder().expect("error in standard RGBContract type system")) + } + + pub fn type_system(&self) -> TypeSystem { self.0.clone() } + + pub fn get(&self, name: &'static str) -> SemId { + self.0 + .id_by_name(name) + .expect("type is absent in standard RGBContract type library") + } +} From 0d79ae6d6d4521faae4017fa2378cb39a36e7aa8 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sat, 13 May 2023 11:10:59 +0200 Subject: [PATCH 03/33] stl: add mime module and MimeChar type --- std/src/stl/mime.rs | 174 ++++++++++++++++++++++++++++++++++++++++++++ std/src/stl/mod.rs | 1 + 2 files changed, 175 insertions(+) create mode 100644 std/src/stl/mime.rs diff --git a/std/src/stl/mime.rs b/std/src/stl/mime.rs new file mode 100644 index 00000000..402b3e7a --- /dev/null +++ b/std/src/stl/mime.rs @@ -0,0 +1,174 @@ +// RGB standard library for working with smart contracts on Bitcoin & Lightning +// +// SPDX-License-Identifier: Apache-2.0 +// +// Written in 2019-2023 by +// Dr Maxim Orlovsky +// +// Copyright (C) 2019-2023 LNP/BP Standards Association. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use super::LIB_NAME_RGB_CONTRACT; + +#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)] +#[derive(StrictDumb, StrictType, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB_CONTRACT, tags = repr, into_u8, try_from_u8)] +#[display(inner)] +#[repr(u8)] +#[allow(non_camel_case_types)] +pub enum MimeChar { + #[strict_type(dumb)] + #[display("!")] + Excl = b'!', + #[display("#")] + Hash = b'#', + #[display("$")] + Dollar = b'$', + #[display("&")] + Amp = b'&', + #[display("+")] + Plus = b'+', + #[display("-")] + Dash = b'-', + #[display(".")] + Dot = b'.', + #[display("0")] + Zero = b'0', + #[display("1")] + One = b'1', + #[display("2")] + Two = b'2', + #[display("3")] + Three = b'3', + #[display("4")] + Four = b'4', + #[display("5")] + Five = b'5', + #[display("6")] + Six = b'6', + #[display("7")] + Seven = b'7', + #[display("8")] + Eight = b'8', + #[display("9")] + Nine = b'9', + #[strict_type(dumb, rename = "A")] + A = b'A', + #[strict_type(rename = "B")] + B = b'B', + #[strict_type(rename = "C")] + C = b'C', + #[strict_type(rename = "D")] + D = b'D', + #[strict_type(rename = "E")] + E = b'E', + #[strict_type(rename = "F")] + F = b'F', + #[strict_type(rename = "G")] + G = b'G', + #[strict_type(rename = "H")] + H = b'H', + #[strict_type(rename = "I")] + I = b'I', + #[strict_type(rename = "J")] + J = b'J', + #[strict_type(rename = "K")] + K = b'K', + #[strict_type(rename = "L")] + L = b'L', + #[strict_type(rename = "M")] + M = b'M', + #[strict_type(rename = "N")] + N = b'N', + #[strict_type(rename = "O")] + O = b'O', + #[strict_type(rename = "P")] + P = b'P', + #[strict_type(rename = "Q")] + Q = b'Q', + #[strict_type(rename = "R")] + R = b'R', + #[strict_type(rename = "S")] + S = b'S', + #[strict_type(rename = "T")] + T = b'T', + #[strict_type(rename = "U")] + U = b'U', + #[strict_type(rename = "V")] + V = b'V', + #[strict_type(rename = "W")] + W = b'W', + #[strict_type(rename = "X")] + X = b'X', + #[strict_type(rename = "Y")] + Y = b'Y', + #[strict_type(rename = "Z")] + Z = b'Z', + #[display("^")] + Caret = b'^', + #[display("_")] + Lodash = b'_', + #[display("a")] + a = b'a', + #[display("b")] + b = b'b', + #[display("c")] + c = b'c', + #[display("d")] + d = b'd', + #[display("e")] + e = b'e', + #[display("f")] + f = b'f', + #[display("g")] + g = b'g', + #[display("h")] + h = b'h', + #[display("i")] + i = b'i', + #[display("j")] + j = b'j', + #[display("k")] + k = b'k', + #[display("l")] + l = b'l', + #[display("m")] + m = b'm', + #[display("n")] + n = b'n', + #[display("o")] + o = b'o', + #[display("p")] + p = b'p', + #[display("q")] + q = b'q', + #[display("r")] + r = b'r', + #[display("s")] + s = b's', + #[display("t")] + t = b't', + #[display("u")] + u = b'u', + #[display("v")] + v = b'v', + #[display("w")] + w = b'w', + #[display("x")] + x = b'x', + #[display("y")] + y = b'y', + #[display("z")] + z = b'z', +} diff --git a/std/src/stl/mod.rs b/std/src/stl/mod.rs index 7c5f0336..556d83fa 100644 --- a/std/src/stl/mod.rs +++ b/std/src/stl/mod.rs @@ -22,6 +22,7 @@ mod specs; mod stl; mod error; +mod mime; pub(self) use error::Error; pub use specs::{ From 725ab9c03538b6a58f9cf36fa22d6fa9b60e292e Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sat, 13 May 2023 12:57:26 +0200 Subject: [PATCH 04/33] stl: refactor name types to use proper char sets matching RGB-31 --- std/src/stl/specs.rs | 31 +++++++++++++++++++++++++++---- stl/RGBContracts-v0.10.3.A.stl | Bin 0 -> 748 bytes stl/RGBContracts-v0.10.3.A.sty | 24 ++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 stl/RGBContracts-v0.10.3.A.stl create mode 100644 stl/RGBContracts-v0.10.3.A.sty diff --git a/std/src/stl/specs.rs b/std/src/stl/specs.rs index 41fb654b..082cfafa 100644 --- a/std/src/stl/specs.rs +++ b/std/src/stl/specs.rs @@ -26,8 +26,12 @@ use std::fmt::{Debug, Formatter}; use std::str::FromStr; use amplify::ascii::AsciiString; -use amplify::confinement::{Confined, NonEmptyString, SmallString, U8}; -use strict_encoding::{InvalidIdent, StrictDeserialize, StrictDumb, StrictSerialize, StrictType}; +use amplify::confinement::{Confined, NonEmptyString, NonEmptyVec, SmallString, U8}; +use strict_encoding::ascii::{AlphaCapsNum, AsciiPrintable}; +use strict_encoding::{ + InvalidIdent, StrictDeserialize, StrictDumb, StrictEncode, StrictSerialize, StrictType, + TypedWrite, +}; use super::LIB_NAME_RGB_CONTRACT; @@ -81,7 +85,7 @@ impl StrictDeserialize for Precision {} #[derive(Wrapper, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, From)] #[wrapper(Deref, Display)] -#[derive(StrictDumb, StrictType, StrictEncode, StrictDecode)] +#[derive(StrictDumb, StrictType, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB_CONTRACT, dumb = { Ticker::from("DUMB") })] #[cfg_attr( feature = "serde", @@ -89,9 +93,17 @@ impl StrictDeserialize for Precision {} serde(crate = "serde_crate", transparent) )] pub struct Ticker(Confined); +impl StrictEncode for Ticker { + fn strict_encode(&self, writer: W) -> std::io::Result { + writer.write_newtype::( + &NonEmptyVec::::try_from_iter([AlphaCapsNum::D]).unwrap(), + ) + } +} impl StrictSerialize for Ticker {} impl StrictDeserialize for Ticker {} +// TODO: Ensure all constructors filter invalid characters impl FromStr for Ticker { type Err = InvalidIdent; @@ -142,7 +154,7 @@ impl Debug for Ticker { #[derive(Wrapper, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, From)] #[wrapper(Deref, Display)] -#[derive(StrictType, StrictEncode, StrictDecode)] +#[derive(StrictType, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB_CONTRACT)] #[cfg_attr( feature = "serde", @@ -150,6 +162,16 @@ impl Debug for Ticker { serde(crate = "serde_crate", transparent) )] pub struct Name(Confined); +impl StrictEncode for Name { + fn strict_encode(&self, writer: W) -> std::io::Result { + writer.write_newtype::( + &NonEmptyVec::::try_from_iter([ + AsciiPrintable::try_from(b'D').unwrap() + ]) + .unwrap(), + ) + } +} impl StrictSerialize for Name {} impl StrictDeserialize for Name {} @@ -157,6 +179,7 @@ impl StrictDumb for Name { fn strict_dumb() -> Self { Name::from("Dumb contract name") } } +// TODO: Ensure all constructors filter invalid characters impl FromStr for Name { type Err = InvalidIdent; diff --git a/stl/RGBContracts-v0.10.3.A.stl b/stl/RGBContracts-v0.10.3.A.stl new file mode 100644 index 0000000000000000000000000000000000000000..d71ad5cf45a39bab68063f1bdbdcfbcf14f48905 GIT binary patch literal 748 zcmd-Ma(8mh&nqcPOfF&IVBmHvE>11+OU%v8OJ`$dE6GgGPAy_&3jx!TU1<(ePKZ5_ z{u=M`z%OO@mIE$tW=S>ezVE{;8N5|5h9xgCHB8f|oa@_BzaNi28# z+fmeG;vC?1qJMkSBUVLO_LS6;#LS#x1{Nj;mc0DDR0akHMwa6I+*AfuMn-lQi0niS z>CK!?p$oL#UVQ7D7qDM>$>+*a)`hkq{~xR{yU3CWQ^(2(bUGs=&GG}7O(L}G0Cw3*?6;oEco?_)MwD?-O z){%+ZISYzXlYu7X=P_~yz?ervg!`T{KYh1u9dnd{<)4{{*e{jN6@1e?x1~e%N4U>Y za4>)z#>D4XoSc~%P?VWhk_dDRTX0E=Pi9i+nzP)OTiO3l-70e4c#ri4Z}ZLPF6I`L ze7RKjJo86EH_SI0P~RYIW)|ko%u9j!je#Wv=r~5!=!DEgZI^1Mh#0ax`ugfo+B%o-V(qXn V$oaY + Copyright (C) 2023 LNP/BP Standards Association. All rights reserved. + License: Apache-2.0 +-} + +typelib RGBContract -- solid_bonus_easy_5Fs6HH4hnxvUKPhoXLFWAtjmrgWkhMFALuDLfF7izxLN + +-- no dependencies + +data AssetNaming :: ticker Ticker + , name Name + , details Details? +data Details :: [Unicode ^ 1..0xff] +data DivisibleAssetSpec :: naming AssetNaming, precision Precision +data Name :: [StdLib.AsciiPrintable ^ 1..0x28] +data Precision :: indivisible:0 | deci:1 | centi:2 | milli:3 | deciMilli:4 | centiMilli:5 | micro:6 | deciMicro:7 | centiMicro:8 | nano:9 | deciNano:10 | centiNano:11 | pico:12 | deciPico:13 | centiPico:14 | femto:15 | deciFemto:16 | centiFemto:17 | atto:18 +data RicardianContract :: [Unicode] +data Ticker :: [StdLib.AlphaCapsNum ^ 1..0x8] +data Timestamp :: I32 + From 4393694716d7c5c243575a97adb8f788ea0f220e Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sat, 13 May 2023 13:20:24 +0200 Subject: [PATCH 05/33] stl: add MediaType --- std/src/stl/mime.rs | 92 +++++++++++++++++++++++++++++++++ std/src/stl/mod.rs | 1 + std/src/stl/stl.rs | 5 +- stl/RGBContracts-v0.10.3.A.stl | Bin 748 -> 1300 bytes stl/RGBContracts-v0.10.3.A.sty | 9 +++- 5 files changed, 104 insertions(+), 3 deletions(-) diff --git a/std/src/stl/mime.rs b/std/src/stl/mime.rs index 402b3e7a..8e35c33c 100644 --- a/std/src/stl/mime.rs +++ b/std/src/stl/mime.rs @@ -19,8 +19,100 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::fmt::{self, Debug, Formatter}; +use std::str::FromStr; + +use amplify::ascii::AsciiString; +use amplify::confinement::{Confined, NonEmptyVec}; +use strict_encoding::{ + InvalidIdent, StrictDeserialize, StrictDumb, StrictEncode, StrictSerialize, TypedWrite, +}; + use super::LIB_NAME_RGB_CONTRACT; +#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] +#[derive(StrictType, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB_CONTRACT)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))] +pub struct MediaType { + pub r#type: MediaRegName, + pub subtype: MediaRegName, + pub charset: Option, +} +impl StrictDumb for MediaType { + fn strict_dumb() -> Self { MediaType::with("text/plain") } +} +impl StrictSerialize for MediaType {} +impl StrictDeserialize for MediaType {} + +impl MediaType { + /// # Safety + /// + /// Panics is the provided string is an invalid type specifier. + pub fn with(s: &'static str) -> Self { + let (ty, subty) = s.split_once("/").expect("invalid static media type string"); + MediaType { + r#type: MediaRegName::from(ty), + subtype: MediaRegName::from(subty), + charset: None, + } + } +} + +#[derive(Wrapper, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, From)] +#[wrapper(Deref, Display)] +#[derive(StrictType, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB_CONTRACT)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", transparent) +)] +pub struct MediaRegName(Confined); +impl StrictEncode for MediaRegName { + fn strict_encode(&self, writer: W) -> std::io::Result { + writer.write_newtype::( + &NonEmptyVec::::try_from_iter([MimeChar::try_from(b'D').unwrap()]) + .unwrap(), + ) + } +} + +impl StrictDumb for MediaRegName { + fn strict_dumb() -> Self { MediaRegName::from("dumb") } +} + +// TODO: Ensure all constructors filter invalid characters +impl FromStr for MediaRegName { + type Err = InvalidIdent; + + fn from_str(s: &str) -> Result { + let s = AsciiString::from_ascii(s.as_bytes())?; + let s = Confined::try_from_iter(s.chars())?; + Ok(Self(s)) + } +} + +impl From<&'static str> for MediaRegName { + fn from(s: &'static str) -> Self { Self::from_str(s).expect("invalid ticker name") } +} + +impl TryFrom for MediaRegName { + type Error = InvalidIdent; + + fn try_from(name: String) -> Result { + let name = AsciiString::from_ascii(name.as_bytes())?; + let s = Confined::try_from(name)?; + Ok(Self(s)) + } +} + +impl Debug for MediaRegName { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.debug_tuple("ContractName").field(&self.as_str()).finish() + } +} + #[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)] #[derive(StrictDumb, StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB_CONTRACT, tags = repr, into_u8, try_from_u8)] diff --git a/std/src/stl/mod.rs b/std/src/stl/mod.rs index 556d83fa..6aae6207 100644 --- a/std/src/stl/mod.rs +++ b/std/src/stl/mod.rs @@ -25,6 +25,7 @@ mod error; mod mime; pub(self) use error::Error; +pub use mime::MediaType; pub use specs::{ AssetNaming, Details, DivisibleAssetSpec, Name, Precision, RicardianContract, Ticker, Timestamp, }; diff --git a/std/src/stl/stl.rs b/std/src/stl/stl.rs index 57444cd1..d72bd41f 100644 --- a/std/src/stl/stl.rs +++ b/std/src/stl/stl.rs @@ -27,7 +27,9 @@ use strict_types::typelib::LibBuilder; use strict_types::typesys::SystemBuilder; use strict_types::{Dependency, SemId, TypeLib, TypeLibId, TypeSystem}; -use super::{DivisibleAssetSpec, Error, RicardianContract, Timestamp, LIB_NAME_RGB_CONTRACT}; +use super::{ + DivisibleAssetSpec, Error, MediaType, RicardianContract, Timestamp, LIB_NAME_RGB_CONTRACT, +}; #[derive(Debug)] pub struct StandardLib(TypeLib); @@ -51,6 +53,7 @@ impl StandardLib { .process::()? .process::()? .process::()? + .process::()? .compile(imports) .map_err(Error::from) } diff --git a/stl/RGBContracts-v0.10.3.A.stl b/stl/RGBContracts-v0.10.3.A.stl index d71ad5cf45a39bab68063f1bdbdcfbcf14f48905..e6d2d44198ca83ec12d997d0eb94d591cacd0d11 100644 GIT binary patch delta 566 zcma)%y=xO;9LMwJ?$Xvu5d=3aQgM;iXnm`LG;d9tYtr_Twn_1YCwIT(uD!eG`rLEL zB@PkA#X%4SXa58dp`(Kif}?clUKeL^P_R`I0}lR{@9^XEefg|CJ2EzE6f#-vOTkQ; z7=1aWqkptSmctBcm6=Bx62llSIUZ$gCiKY@%IyN>mlL?ZylP*83cL$8=Xf$A&uq+Uv*+i=a+lJ#{a}!%za9wyFd>@=6 d2(Y~kArOX;5>bS98=Vf~7~L* @@ -7,7 +7,7 @@ License: Apache-2.0 -} -typelib RGBContract -- solid_bonus_easy_5Fs6HH4hnxvUKPhoXLFWAtjmrgWkhMFALuDLfF7izxLN +typelib RGBContract -- patent_sonata_point_FSRZhbJ6DyS8zpyoB4XiY25Xt7bm8GgXKRJ9RF2mbQcK -- no dependencies @@ -16,6 +16,11 @@ data AssetNaming :: ticker Ticker , details Details? data Details :: [Unicode ^ 1..0xff] data DivisibleAssetSpec :: naming AssetNaming, precision Precision +data MediaRegName :: [MimeChar ^ 1..0x40] +data MediaType :: rType MediaRegName + , subtype MediaRegName + , charset MediaRegName? +data MimeChar :: excl:33 | hash:35 | dollar:36 | amp:38 | plus:43 | dash:45 | dot:46 | zero:48 | one:49 | two:50 | three:51 | four:52 | five:53 | six:54 | seven:55 | eight:56 | nine:57 | A:65 | B:66 | C:67 | D:68 | E:69 | F:70 | G:71 | H:72 | I:73 | J:74 | K:75 | L:76 | M:77 | N:78 | O:79 | P:80 | Q:81 | R:82 | S:83 | T:84 | U:85 | V:86 | W:87 | X:88 | Y:89 | Z:90 | caret:94 | lodash:95 | a:97 | b:98 | c:99 | d:100 | e:101 | f:102 | g:103 | h:104 | i:105 | j:106 | k:107 | l:108 | m:109 | n:110 | o:111 | p:112 | q:113 | r:114 | s:115 | t:116 | u:117 | v:118 | w:119 | x:120 | y:121 | z:122 data Name :: [StdLib.AsciiPrintable ^ 1..0x28] data Precision :: indivisible:0 | deci:1 | centi:2 | milli:3 | deciMilli:4 | centiMilli:5 | micro:6 | deciMicro:7 | centiMicro:8 | nano:9 | deciNano:10 | centiNano:11 | pico:12 | deciPico:13 | centiPico:14 | femto:15 | deciFemto:16 | centiFemto:17 | atto:18 data RicardianContract :: [Unicode] From 119f470078a43cef9ec9d4c4a5ce49ad7ccc3aed Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sat, 13 May 2023 20:45:15 +0200 Subject: [PATCH 06/33] stl: add ProofOfReserves type --- std/src/stl/chain.rs | 43 +++++++++++++++++++++++++++++++++ std/src/stl/mod.rs | 2 ++ std/src/stl/stl.rs | 2 ++ stl/RGBContracts-v0.10.3.A.stl | Bin 1300 -> 1440 bytes stl/RGBContracts-v0.10.3.A.sty | 8 +++--- 5 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 std/src/stl/chain.rs diff --git a/std/src/stl/chain.rs b/std/src/stl/chain.rs new file mode 100644 index 00000000..a5b6c959 --- /dev/null +++ b/std/src/stl/chain.rs @@ -0,0 +1,43 @@ +// RGB standard library for working with smart contracts on Bitcoin & Lightning +// +// SPDX-License-Identifier: Apache-2.0 +// +// Written in 2019-2023 by +// Dr Maxim Orlovsky +// +// Copyright (C) 2019-2023 LNP/BP Standards Association. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use amplify::confinement::SmallBlob; +use bp::Outpoint; +use strict_encoding::{StrictDeserialize, StrictSerialize}; + +use super::LIB_NAME_RGB_CONTRACT; + +#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, From)] +#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB_CONTRACT, dumb = ProofOfReserves::new(strict_dumb!(), strict_dumb!()))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))] +pub struct ProofOfReserves { + pub utxo: Outpoint, + pub proof: SmallBlob, +} +impl StrictSerialize for ProofOfReserves {} +impl StrictDeserialize for ProofOfReserves {} + +impl ProofOfReserves { + pub fn new(utxo: Outpoint, proof: SmallBlob) -> ProofOfReserves { + ProofOfReserves { utxo, proof } + } +} diff --git a/std/src/stl/mod.rs b/std/src/stl/mod.rs index 6aae6207..a2c78731 100644 --- a/std/src/stl/mod.rs +++ b/std/src/stl/mod.rs @@ -23,7 +23,9 @@ mod specs; mod stl; mod error; mod mime; +mod chain; +pub use chain::ProofOfReserves; pub(self) use error::Error; pub use mime::MediaType; pub use specs::{ diff --git a/std/src/stl/stl.rs b/std/src/stl/stl.rs index d72bd41f..d08d7c02 100644 --- a/std/src/stl/stl.rs +++ b/std/src/stl/stl.rs @@ -30,6 +30,7 @@ use strict_types::{Dependency, SemId, TypeLib, TypeLibId, TypeSystem}; use super::{ DivisibleAssetSpec, Error, MediaType, RicardianContract, Timestamp, LIB_NAME_RGB_CONTRACT, }; +use crate::stl::ProofOfReserves; #[derive(Debug)] pub struct StandardLib(TypeLib); @@ -54,6 +55,7 @@ impl StandardLib { .process::()? .process::()? .process::()? + .process::()? .compile(imports) .map_err(Error::from) } diff --git a/stl/RGBContracts-v0.10.3.A.stl b/stl/RGBContracts-v0.10.3.A.stl index e6d2d44198ca83ec12d997d0eb94d591cacd0d11..6863baeeffee8b1721aae09397c9c1c0917494c1 100644 GIT binary patch delta 168 zcmbQjwSe1x|p@aFLbF7CAw$pGJZGYMfu6 zihX5w$}CCF&&=c5$XCyj!XHqSpP%NR7L;0?T2z)=%*Mo0T2hhE#Nl6BQUFv{0#ly3 z`^(J=hB_|Jlt<~2^OO6TV(whlJill!yPHKROGxue)&h`03>*v$j0{ll|38E=xtFCK E0A-UrbpQYW delta 27 icmZ3$J%x*pJILM1IX|zYC^5N&fqSD_J @@ -7,9 +7,10 @@ License: Apache-2.0 -} -typelib RGBContract -- patent_sonata_point_FSRZhbJ6DyS8zpyoB4XiY25Xt7bm8GgXKRJ9RF2mbQcK +typelib RGBContract -- repair_client_truck_2RaHGu3LD3qZozNttdkPJkdiysTDqBkuNRL9eCjmqdma + +import circus_report_jeep_2bj6eDer24ZBSVq6JgQW2BrARt6vx56vMWzF35J45gzY as Bitcoin --- no dependencies data AssetNaming :: ticker Ticker , name Name @@ -23,6 +24,7 @@ data MediaType :: rType MediaRegName data MimeChar :: excl:33 | hash:35 | dollar:36 | amp:38 | plus:43 | dash:45 | dot:46 | zero:48 | one:49 | two:50 | three:51 | four:52 | five:53 | six:54 | seven:55 | eight:56 | nine:57 | A:65 | B:66 | C:67 | D:68 | E:69 | F:70 | G:71 | H:72 | I:73 | J:74 | K:75 | L:76 | M:77 | N:78 | O:79 | P:80 | Q:81 | R:82 | S:83 | T:84 | U:85 | V:86 | W:87 | X:88 | Y:89 | Z:90 | caret:94 | lodash:95 | a:97 | b:98 | c:99 | d:100 | e:101 | f:102 | g:103 | h:104 | i:105 | j:106 | k:107 | l:108 | m:109 | n:110 | o:111 | p:112 | q:113 | r:114 | s:115 | t:116 | u:117 | v:118 | w:119 | x:120 | y:121 | z:122 data Name :: [StdLib.AsciiPrintable ^ 1..0x28] data Precision :: indivisible:0 | deci:1 | centi:2 | milli:3 | deciMilli:4 | centiMilli:5 | micro:6 | deciMicro:7 | centiMicro:8 | nano:9 | deciNano:10 | centiNano:11 | pico:12 | deciPico:13 | centiPico:14 | femto:15 | deciFemto:16 | centiFemto:17 | atto:18 +data ProofOfReserves :: utxo Bitcoin.Outpoint, proof [U8] data RicardianContract :: [Unicode] data Ticker :: [StdLib.AlphaCapsNum ^ 1..0x8] data Timestamp :: I32 From 024ab3111b5665302072c14a0fa9a6a13192de65 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sat, 13 May 2023 20:46:52 +0200 Subject: [PATCH 07/33] stl: fix MediaType field names --- std/src/stl/mime.rs | 6 ++++-- stl/RGBContracts-v0.10.3.A.stl | Bin 1440 -> 1439 bytes stl/RGBContracts-v0.10.3.A.sty | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/std/src/stl/mime.rs b/std/src/stl/mime.rs index 8e35c33c..35c55a10 100644 --- a/std/src/stl/mime.rs +++ b/std/src/stl/mime.rs @@ -35,7 +35,9 @@ use super::LIB_NAME_RGB_CONTRACT; #[strict_type(lib = LIB_NAME_RGB_CONTRACT)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))] pub struct MediaType { - pub r#type: MediaRegName, + #[strict_type(rename = "type")] + #[cfg_attr(feature = "serde", serde(rename = "type"))] + pub ty: MediaRegName, pub subtype: MediaRegName, pub charset: Option, } @@ -52,7 +54,7 @@ impl MediaType { pub fn with(s: &'static str) -> Self { let (ty, subty) = s.split_once("/").expect("invalid static media type string"); MediaType { - r#type: MediaRegName::from(ty), + ty: MediaRegName::from(ty), subtype: MediaRegName::from(subty), charset: None, } diff --git a/stl/RGBContracts-v0.10.3.A.stl b/stl/RGBContracts-v0.10.3.A.stl index 6863baeeffee8b1721aae09397c9c1c0917494c1..9de31c9f560996f2e4424b204ce4095bfe177c6b 100644 GIT binary patch delta 18 acmZ3$J)e8S4Ms+m$pTEqn|YZgGXnrOMg+W-In diff --git a/stl/RGBContracts-v0.10.3.A.sty b/stl/RGBContracts-v0.10.3.A.sty index 41532489..240f73a4 100644 --- a/stl/RGBContracts-v0.10.3.A.sty +++ b/stl/RGBContracts-v0.10.3.A.sty @@ -1,5 +1,5 @@ {- - Id: repair_client_truck_2RaHGu3LD3qZozNttdkPJkdiysTDqBkuNRL9eCjmqdma + Id: union_raymond_planet_5qk5NKCECpDsFLf3C781omtThzS5jhNRis2vwGVxkrkv Name: RGBCore Description: Consensus layer for RGB smart contracts Author: Dr Maxim Orlovsky @@ -7,7 +7,7 @@ License: Apache-2.0 -} -typelib RGBContract -- repair_client_truck_2RaHGu3LD3qZozNttdkPJkdiysTDqBkuNRL9eCjmqdma +typelib RGBContract -- union_raymond_planet_5qk5NKCECpDsFLf3C781omtThzS5jhNRis2vwGVxkrkv import circus_report_jeep_2bj6eDer24ZBSVq6JgQW2BrARt6vx56vMWzF35J45gzY as Bitcoin @@ -18,7 +18,7 @@ data AssetNaming :: ticker Ticker data Details :: [Unicode ^ 1..0xff] data DivisibleAssetSpec :: naming AssetNaming, precision Precision data MediaRegName :: [MimeChar ^ 1..0x40] -data MediaType :: rType MediaRegName +data MediaType :: type MediaRegName , subtype MediaRegName , charset MediaRegName? data MimeChar :: excl:33 | hash:35 | dollar:36 | amp:38 | plus:43 | dash:45 | dot:46 | zero:48 | one:49 | two:50 | three:51 | four:52 | five:53 | six:54 | seven:55 | eight:56 | nine:57 | A:65 | B:66 | C:67 | D:68 | E:69 | F:70 | G:71 | H:72 | I:73 | J:74 | K:75 | L:76 | M:77 | N:78 | O:79 | P:80 | Q:81 | R:82 | S:83 | T:84 | U:85 | V:86 | W:87 | X:88 | Y:89 | Z:90 | caret:94 | lodash:95 | a:97 | b:98 | c:99 | d:100 | e:101 | f:102 | g:103 | h:104 | i:105 | j:106 | k:107 | l:108 | m:109 | n:110 | o:111 | p:112 | q:113 | r:114 | s:115 | t:116 | u:117 | v:118 | w:119 | x:120 | y:121 | z:122 From 9182e556a612d5f95afc097a5334888af9f95468 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sat, 13 May 2023 21:12:39 +0200 Subject: [PATCH 08/33] stl: import StdLib in explicit form --- std/src/stl/stl.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/std/src/stl/stl.rs b/std/src/stl/stl.rs index d08d7c02..5ceb9a32 100644 --- a/std/src/stl/stl.rs +++ b/std/src/stl/stl.rs @@ -23,6 +23,7 @@ use std::str::FromStr; use bp::dbc::LIB_NAME_BPCORE; use bp::LIB_NAME_BITCOIN; +use strict_encoding::STD_LIB; use strict_types::typelib::LibBuilder; use strict_types::typesys::SystemBuilder; use strict_types::{Dependency, SemId, TypeLib, TypeLibId, TypeSystem}; @@ -44,10 +45,14 @@ impl StandardLib { let bpcore_id = TypeLibId::from_str( "harlem_null_puma_DxuLX8d9UiMyEJMRJivMFviK1B8t1QWyjywXuDC13iKR", )?; + let stdlib_id = TypeLibId::from_str( + "alabama_speed_polo_J2wwnFdkbUQt2sg5EZndccZdPZgFUGmLcK3Uw5TbzjRh", + )?; let imports = bset! { Dependency::with(bitcoin_id, libname!(LIB_NAME_BITCOIN)), Dependency::with(bpcore_id, libname!(LIB_NAME_BPCORE)), + Dependency::with(stdlib_id, libname!(STD_LIB)), }; LibBuilder::new(libname!(LIB_NAME_RGB_CONTRACT)) From 6397cdfb15275cd2fd96190ecaf52b64f38960f6 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sat, 13 May 2023 21:15:06 +0200 Subject: [PATCH 09/33] stl: make Media names case-inseitive --- std/src/stl/mime.rs | 57 ++------------------------------- stl/RGBContracts-v0.10.3.A.stl | Bin 1439 -> 1361 bytes stl/RGBContracts-v0.10.3.A.sty | 6 ++-- 3 files changed, 5 insertions(+), 58 deletions(-) diff --git a/std/src/stl/mime.rs b/std/src/stl/mime.rs index 35c55a10..548741a2 100644 --- a/std/src/stl/mime.rs +++ b/std/src/stl/mime.rs @@ -74,8 +74,7 @@ pub struct MediaRegName(Confined); impl StrictEncode for MediaRegName { fn strict_encode(&self, writer: W) -> std::io::Result { writer.write_newtype::( - &NonEmptyVec::::try_from_iter([MimeChar::try_from(b'D').unwrap()]) - .unwrap(), + &NonEmptyVec::::try_from_iter([MimeChar::strict_dumb()]).unwrap(), ) } } @@ -122,7 +121,6 @@ impl Debug for MediaRegName { #[repr(u8)] #[allow(non_camel_case_types)] pub enum MimeChar { - #[strict_type(dumb)] #[display("!")] Excl = b'!', #[display("#")] @@ -157,62 +155,11 @@ pub enum MimeChar { Eight = b'8', #[display("9")] Nine = b'9', - #[strict_type(dumb, rename = "A")] - A = b'A', - #[strict_type(rename = "B")] - B = b'B', - #[strict_type(rename = "C")] - C = b'C', - #[strict_type(rename = "D")] - D = b'D', - #[strict_type(rename = "E")] - E = b'E', - #[strict_type(rename = "F")] - F = b'F', - #[strict_type(rename = "G")] - G = b'G', - #[strict_type(rename = "H")] - H = b'H', - #[strict_type(rename = "I")] - I = b'I', - #[strict_type(rename = "J")] - J = b'J', - #[strict_type(rename = "K")] - K = b'K', - #[strict_type(rename = "L")] - L = b'L', - #[strict_type(rename = "M")] - M = b'M', - #[strict_type(rename = "N")] - N = b'N', - #[strict_type(rename = "O")] - O = b'O', - #[strict_type(rename = "P")] - P = b'P', - #[strict_type(rename = "Q")] - Q = b'Q', - #[strict_type(rename = "R")] - R = b'R', - #[strict_type(rename = "S")] - S = b'S', - #[strict_type(rename = "T")] - T = b'T', - #[strict_type(rename = "U")] - U = b'U', - #[strict_type(rename = "V")] - V = b'V', - #[strict_type(rename = "W")] - W = b'W', - #[strict_type(rename = "X")] - X = b'X', - #[strict_type(rename = "Y")] - Y = b'Y', - #[strict_type(rename = "Z")] - Z = b'Z', #[display("^")] Caret = b'^', #[display("_")] Lodash = b'_', + #[strict_type(dumb)] #[display("a")] a = b'a', #[display("b")] diff --git a/stl/RGBContracts-v0.10.3.A.stl b/stl/RGBContracts-v0.10.3.A.stl index 9de31c9f560996f2e4424b204ce4095bfe177c6b..009f47b6bedc4b68260527917d3f8135d0c7c469 100644 GIT binary patch delta 188 zcmbQweUWR!97ct`FTL)bnaCQse(pJq?zfif+iLGGD9n=iWSGa$et6M6oymI`^~3&W z&8b?jG`~s5^||TXA5Zw|`6jW;m&hJ5J1)U?TP%4udvR$}No7GQBad%tN@ikEYPw%y kZYm*NlO36~wFxQW@XgFkbo8~)e9Xgzx_=<5Fzi{C48H`xHPGxvLKa_$2T=4GchPN-7hgW zm5{EdNTm#^~B;Ej#pvzL=;Ooa>&xip$LR0R7!bf17|0kD#26gR7!tx58p;?J#uy&X7!ko38OazG KwfQeo2onHp%U_TH diff --git a/stl/RGBContracts-v0.10.3.A.sty b/stl/RGBContracts-v0.10.3.A.sty index 240f73a4..bfccf1b8 100644 --- a/stl/RGBContracts-v0.10.3.A.sty +++ b/stl/RGBContracts-v0.10.3.A.sty @@ -1,5 +1,5 @@ {- - Id: union_raymond_planet_5qk5NKCECpDsFLf3C781omtThzS5jhNRis2vwGVxkrkv + Id: screen_julius_junior_J1PKHWvqJU1nBLFxjezAmsQpLHVo3JgnDh1VH2iFSHHR Name: RGBCore Description: Consensus layer for RGB smart contracts Author: Dr Maxim Orlovsky @@ -7,7 +7,7 @@ License: Apache-2.0 -} -typelib RGBContract -- union_raymond_planet_5qk5NKCECpDsFLf3C781omtThzS5jhNRis2vwGVxkrkv +typelib RGBContract -- screen_julius_junior_J1PKHWvqJU1nBLFxjezAmsQpLHVo3JgnDh1VH2iFSHHR import circus_report_jeep_2bj6eDer24ZBSVq6JgQW2BrARt6vx56vMWzF35J45gzY as Bitcoin @@ -21,7 +21,7 @@ data MediaRegName :: [MimeChar ^ 1..0x40] data MediaType :: type MediaRegName , subtype MediaRegName , charset MediaRegName? -data MimeChar :: excl:33 | hash:35 | dollar:36 | amp:38 | plus:43 | dash:45 | dot:46 | zero:48 | one:49 | two:50 | three:51 | four:52 | five:53 | six:54 | seven:55 | eight:56 | nine:57 | A:65 | B:66 | C:67 | D:68 | E:69 | F:70 | G:71 | H:72 | I:73 | J:74 | K:75 | L:76 | M:77 | N:78 | O:79 | P:80 | Q:81 | R:82 | S:83 | T:84 | U:85 | V:86 | W:87 | X:88 | Y:89 | Z:90 | caret:94 | lodash:95 | a:97 | b:98 | c:99 | d:100 | e:101 | f:102 | g:103 | h:104 | i:105 | j:106 | k:107 | l:108 | m:109 | n:110 | o:111 | p:112 | q:113 | r:114 | s:115 | t:116 | u:117 | v:118 | w:119 | x:120 | y:121 | z:122 +data MimeChar :: excl:33 | hash:35 | dollar:36 | amp:38 | plus:43 | dash:45 | dot:46 | zero:48 | one:49 | two:50 | three:51 | four:52 | five:53 | six:54 | seven:55 | eight:56 | nine:57 | caret:94 | lodash:95 | a:97 | b:98 | c:99 | d:100 | e:101 | f:102 | g:103 | h:104 | i:105 | j:106 | k:107 | l:108 | m:109 | n:110 | o:111 | p:112 | q:113 | r:114 | s:115 | t:116 | u:117 | v:118 | w:119 | x:120 | y:121 | z:122 data Name :: [StdLib.AsciiPrintable ^ 1..0x28] data Precision :: indivisible:0 | deci:1 | centi:2 | milli:3 | deciMilli:4 | centiMilli:5 | micro:6 | deciMicro:7 | centiMicro:8 | nano:9 | deciNano:10 | centiNano:11 | pico:12 | deciPico:13 | centiPico:14 | femto:15 | deciFemto:16 | centiFemto:17 | atto:18 data ProofOfReserves :: utxo Bitcoin.Outpoint, proof [U8] From 408b8f493db401efadfe4b2a29df4b5acd331c3f Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 02:28:57 +0200 Subject: [PATCH 10/33] stl: update to use new library generators --- .github/workflows/build.yml | 1 + Cargo.lock | 156 ++++++--------------------------- Cargo.toml | 11 ++- scripts/typelib.sh | 5 +- std/Cargo.toml | 7 +- std/src/bin/rgb-stl.rs | 76 +++++++--------- std/src/lib.rs | 1 + std/src/stl/mod.rs | 2 +- std/src/stl/specs.rs | 4 +- std/src/stl/stl.rs | 91 ++++++++++--------- std/tests/data/rgb20.asc.rgb | 10 +-- stl/RGBContract@0.1.0.sta | 40 +++++++++ stl/RGBContract@0.1.0.stl | Bin 0 -> 1391 bytes stl/RGBContract@0.1.0.sty | 47 ++++++++++ stl/RGBContracts-v0.10.1.C.stl | Bin 1088 -> 0 bytes stl/RGBContracts-v0.10.1.C.sty | 23 ----- stl/RGBContracts-v0.10.2.A.stl | Bin 1103 -> 0 bytes stl/RGBContracts-v0.10.2.A.sty | 24 ----- stl/RGBContracts-v0.10.3.A.stl | Bin 1361 -> 0 bytes stl/RGBContracts-v0.10.3.A.sty | 31 ------- 20 files changed, 220 insertions(+), 309 deletions(-) create mode 100644 stl/RGBContract@0.1.0.sta create mode 100644 stl/RGBContract@0.1.0.stl create mode 100644 stl/RGBContract@0.1.0.sty delete mode 100644 stl/RGBContracts-v0.10.1.C.stl delete mode 100644 stl/RGBContracts-v0.10.1.C.sty delete mode 100644 stl/RGBContracts-v0.10.2.A.stl delete mode 100644 stl/RGBContracts-v0.10.2.A.sty delete mode 100644 stl/RGBContracts-v0.10.3.A.stl delete mode 100644 stl/RGBContracts-v0.10.3.A.sty diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4b1e6717..fe1f26f0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,6 +30,7 @@ jobs: fail-fast: false matrix: feature: + - stl - fs - serde steps: diff --git a/Cargo.lock b/Cargo.lock index e96c3f8f..483da06b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,8 +5,7 @@ version = 3 [[package]] name = "aluvm" version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a1af50ff99955dc8f90a00f73e5c8e8d726088c561bd51a5349b5488e8434a7" +source = "git+https://github.com/AluVM/rust-aluvm#dd7410778ff2a9fe5808447a9efeb55ccbc68c54" dependencies = [ "amplify", "baid58", @@ -16,6 +15,7 @@ dependencies = [ "paste", "serde", "strict_encoding", + "strict_types", ] [[package]] @@ -222,8 +222,7 @@ dependencies = [ [[package]] name = "bp-core" version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1052718595cc1ec21aaf709181e00a6a23465181294c8d9138becd17595c3761" +source = "git+https://github.com/BP-WG/bp-core?branch=stl#f35d19a2ef7f329bb84813f8a2e37eb6ee97eeec" dependencies = [ "amplify", "bp-dbc", @@ -233,13 +232,13 @@ dependencies = [ "serde", "single_use_seals", "strict_encoding", + "strict_types", ] [[package]] name = "bp-dbc" version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a701a742b23d6bda5f92ec042f18a84a9ab0541488babf196c28a1f64d72c2a" +source = "git+https://github.com/BP-WG/bp-core?branch=stl#f35d19a2ef7f329bb84813f8a2e37eb6ee97eeec" dependencies = [ "amplify", "baid58", @@ -253,21 +252,20 @@ dependencies = [ [[package]] name = "bp-primitives" version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbfea68e7cf2a2962b609d4de56b8e855ecfe7ca5c2e6deac5ac02289fb5b656" +source = "git+https://github.com/BP-WG/bp-core?branch=stl#f35d19a2ef7f329bb84813f8a2e37eb6ee97eeec" dependencies = [ "amplify", "commit_verify", "secp256k1", "serde", "strict_encoding", + "strict_types", ] [[package]] name = "bp-seals" version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b78940b9213cff7e53f705b2ab1320679b02edd4d7d0f26648341a4089c8d979" +source = "git+https://github.com/BP-WG/bp-core?branch=stl#f35d19a2ef7f329bb84813f8a2e37eb6ee97eeec" dependencies = [ "amplify", "baid58", @@ -320,21 +318,10 @@ dependencies = [ "winapi", ] -[[package]] -name = "codespan-reporting" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" -dependencies = [ - "termcolor", - "unicode-width", -] - [[package]] name = "commit_encoding_derive" -version = "0.10.0-beta.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c90e218caace623ce81600c4abbf475d939068b3998d362fb6eb44172cfc1a" +version = "0.10.0" +source = "git+https://github.com/LNP-BP/client_side_validation?branch=stl#317d594d2c3d252bcb7d1a493cd49a04a320c3c9" dependencies = [ "amplify", "amplify_syn", @@ -346,14 +333,14 @@ dependencies = [ [[package]] name = "commit_verify" version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4909c1969590b4f3bf94e555a750f5d0a06322c358562c14ff9c1c90a6828e9e" +source = "git+https://github.com/LNP-BP/client_side_validation?branch=stl#317d594d2c3d252bcb7d1a493cd49a04a320c3c9" dependencies = [ "amplify", "commit_encoding_derive", "rand", "serde", "strict_encoding", + "strict_types", ] [[package]] @@ -394,50 +381,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "cxx" -version = "1.0.94" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93" -dependencies = [ - "cc", - "cxxbridge-flags", - "cxxbridge-macro", - "link-cplusplus", -] - -[[package]] -name = "cxx-build" -version = "1.0.94" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b" -dependencies = [ - "cc", - "codespan-reporting", - "once_cell", - "proc-macro2", - "quote", - "scratch", - "syn 2.0.15", -] - -[[package]] -name = "cxxbridge-flags" -version = "1.0.94" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb" - -[[package]] -name = "cxxbridge-macro" -version = "1.0.94" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.15", -] - [[package]] name = "darling" version = "0.20.1" @@ -459,7 +402,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.15", + "syn 2.0.16", ] [[package]] @@ -470,7 +413,7 @@ checksum = "29a358ff9f12ec09c3e61fef9b5a9902623a695a46a917b07f269bff1445611a" dependencies = [ "darling_core", "quote", - "syn 2.0.15", + "syn 2.0.16", ] [[package]] @@ -571,12 +514,11 @@ dependencies = [ [[package]] name = "iana-time-zone-haiku" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" dependencies = [ - "cxx", - "cxx-build", + "cc", ] [[package]] @@ -623,15 +565,6 @@ version = "0.2.144" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" -[[package]] -name = "link-cplusplus" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" -dependencies = [ - "cc", -] - [[package]] name = "log" version = "0.4.17" @@ -757,8 +690,7 @@ dependencies = [ [[package]] name = "rgb-core" version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8b1c35a490db37f992bba0706b63fa42b5e7bc8705b0c55fb4e244034f078d8" +source = "git+https://github.com/RGB-WG/rgb-core?branch=stl#a643a04b0ba287511d1069715e23942b690fc7ca" dependencies = [ "aluvm", "amplify", @@ -828,12 +760,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" -[[package]] -name = "scratch" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1" - [[package]] name = "secp256k1" version = "0.27.0" @@ -895,7 +821,7 @@ checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.16", ] [[package]] @@ -953,7 +879,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.16", ] [[package]] @@ -981,8 +907,7 @@ dependencies = [ [[package]] name = "strict_encoding" version = "2.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d8f58c66205b3eeb74ffc3c0e5b5cac77658a88ba0345018cc074ad4ddb6fef" +source = "git+https://github.com/strict-types/strict-encoding?branch=stl#09c260290112897b913a1fe025bb9c12c73785dd" dependencies = [ "amplify", "half", @@ -993,8 +918,7 @@ dependencies = [ [[package]] name = "strict_encoding_derive" version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f5adae55367464f5a229bfd539682c94f870b98a220be6e61dc43f85d612e7e" +source = "git+https://github.com/strict-types/strict-encoding?branch=stl#09c260290112897b913a1fe025bb9c12c73785dd" dependencies = [ "amplify_syn", "heck", @@ -1006,11 +930,11 @@ dependencies = [ [[package]] name = "strict_types" version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a03bb84c2de19c9f389c58fe9cb505ca3dbb4b9247209428cb3c6aa440cff87" +source = "git+https://github.com/strict-types/strict-types?branch=fix/typesys-builder#649eface5c47a117ff443bfac7ba70a73de2ba27" dependencies = [ "amplify", "baid58", + "base64 0.21.0", "blake3", "half", "indexmap", @@ -1057,24 +981,15 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.15" +version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" +checksum = "a6f671d4b5ffdb8eadec19c0ae67fe2639df8684bd7bc4b83d986b8db549cf01" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] -[[package]] -name = "termcolor" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" -dependencies = [ - "winapi-util", -] - [[package]] name = "time" version = "0.1.45" @@ -1168,12 +1083,6 @@ version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" -[[package]] -name = "unicode-width" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" - [[package]] name = "unsafe-libyaml" version = "0.2.8" @@ -1219,7 +1128,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.16", "wasm-bindgen-shared", ] @@ -1253,7 +1162,7 @@ checksum = "4783ce29f09b9d93134d41297aded3a712b7b979e9c6f28c32cb88c973a94869" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.16", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1314,15 +1223,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index ff923783..e69528fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,7 +62,8 @@ percent-encoding = "2.2.0" [features] default = [] -all = ["fs", "serde"] +all = ["fs", "serde", "stl"] +stl = ["rgb-std/stl"] serde = ["rgb-std/serde", "rgb-core/serde"] fs = ["rgb-std/fs"] @@ -76,3 +77,11 @@ wasm-bindgen-test = "0.3" [package.metadata.docs.rs] features = [ "all" ] + +[patch.crates-io] +strict_encoding = { git = "https://github.com/strict-types/strict-encoding", branch = "stl" } +strict_types = { git = "https://github.com/strict-types/strict-types", branch = "fix/typesys-builder" } +commit_verify = { git = "https://github.com/LNP-BP/client_side_validation", branch = "stl" } +bp-core = { git = "https://github.com/BP-WG/bp-core", branch = "stl" } +aluvm = { git = "https://github.com/AluVM/rust-aluvm" } +rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "stl" } diff --git a/scripts/typelib.sh b/scripts/typelib.sh index 2458a488..94d1e1ad 100755 --- a/scripts/typelib.sh +++ b/scripts/typelib.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash -cargo run --bin rgb-stl -- --sty -cargo run --bin rgb-stl -- --stl +cargo run --features stl --bin rgb-stl -- --sty +cargo run --features stl --bin rgb-stl -- --stl +cargo run --features stl --bin rgb-stl -- --sta diff --git a/std/Cargo.toml b/std/Cargo.toml index e82b1287..08c639be 100644 --- a/std/Cargo.toml +++ b/std/Cargo.toml @@ -16,6 +16,10 @@ readme = "../README.md" name = "rgbstd" crate-type = ["cdylib", "rlib"] # We need this for WASM +[[bin]] +name = "rgb-stl" +required-features = ["stl"] + [dependencies] amplify = { workspace = true } strict_encoding = { workspace = true } @@ -29,7 +33,8 @@ serde_crate = { package = "serde", version = "1", features = ["derive"] } [features] default = [] -all = ["fs", "serde"] +all = ["fs", "serde", "stl"] +stl = ["commit_verify/stl", "bp-core/stl", "rgb-core/stl"] serde = [ "amplify/serde", "strict_encoding/serde", "strict_types/serde", diff --git a/std/src/bin/rgb-stl.rs b/std/src/bin/rgb-stl.rs index e6da41e0..bfcea609 100644 --- a/std/src/bin/rgb-stl.rs +++ b/std/src/bin/rgb-stl.rs @@ -20,53 +20,41 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::io::stdout; -use std::{env, fs, io}; +use rgbstd::stl::rgb_contract_stl; +use strict_types::typelib::parse_args; -use amplify::num::u24; -use rgbstd::stl::StandardLib; -use strict_encoding::{StrictEncode, StrictWriter}; +fn main() { + let (format, dir) = parse_args(); -fn main() -> Result<(), Box> { - let args: Vec = env::args().collect(); - - let lib = StandardLib::new().type_lib(); - let id = lib.id(); - - let ext = match args.get(1).map(String::as_str) { - Some("--stl") => "stl", - Some("--sty") => "sty", - _ => "sty", - }; - let filename = args - .get(2) - .cloned() - .unwrap_or_else(|| format!("stl/RGBContracts-v0.10.3.A.{ext}")); - let mut file = match args.len() { - 1 => Box::new(stdout()) as Box, - 2 | 3 => Box::new(fs::File::create(filename)?) as Box, - _ => panic!("invalid argument count"), - }; - match ext { - "stl" => { - lib.strict_encode(StrictWriter::with(u24::MAX.into_usize(), file))?; - } - _ => { - writeln!( - file, - "{{- - Id: {id} - Name: RGBCore - Description: Consensus layer for RGB smart contracts + rgb_contract_stl() + .serialize( + format, + dir.as_ref(), + "0.1.0", + Some( + " + Description: Types for writing RGB contracts and interfaces Author: Dr Maxim Orlovsky Copyright (C) 2023 LNP/BP Standards Association. All rights reserved. - License: Apache-2.0 --}} -" - )?; - writeln!(file, "{lib}")?; - } - } + License: Apache-2.0", + ), + ) + .expect("unable to write to the file"); - Ok(()) + /* + bp::stl::bp_core_stl() + .serialize( + format, + dir, + "0.1.0", + Some( + " + Description: Bitcoin client-side-validation library + Author: Dr Maxim Orlovsky + Copyright (C) 2023 LNP/BP Standards Association. All rights reserved. + License: Apache-2.0", + ), + ) + .expect("unable to write to the file"); + */ } diff --git a/std/src/lib.rs b/std/src/lib.rs index e4f9026b..eb4039f7 100644 --- a/std/src/lib.rs +++ b/std/src/lib.rs @@ -78,6 +78,7 @@ extern crate serde_crate as serde; pub use rgb::{contract, schema, validation, vm}; +#[cfg(feature = "stl")] pub mod stl; pub mod interface; pub mod containers; diff --git a/std/src/stl/mod.rs b/std/src/stl/mod.rs index a2c78731..668e02e9 100644 --- a/std/src/stl/mod.rs +++ b/std/src/stl/mod.rs @@ -31,6 +31,6 @@ pub use mime::MediaType; pub use specs::{ AssetNaming, Details, DivisibleAssetSpec, Name, Precision, RicardianContract, Ticker, Timestamp, }; -pub use stl::{StandardLib, StandardTypes}; +pub use stl::{rgb_contract_stl, StandardTypes, LIB_ID_RGB_CONTRACT}; pub const LIB_NAME_RGB_CONTRACT: &str = "RGBContract"; diff --git a/std/src/stl/specs.rs b/std/src/stl/specs.rs index 082cfafa..086f6981 100644 --- a/std/src/stl/specs.rs +++ b/std/src/stl/specs.rs @@ -27,7 +27,7 @@ use std::str::FromStr; use amplify::ascii::AsciiString; use amplify::confinement::{Confined, NonEmptyString, NonEmptyVec, SmallString, U8}; -use strict_encoding::ascii::{AlphaCapsNum, AsciiPrintable}; +use strict_encoding::stl::{AlphaCapsNum, AsciiPrintable}; use strict_encoding::{ InvalidIdent, StrictDeserialize, StrictDumb, StrictEncode, StrictSerialize, StrictType, TypedWrite, @@ -139,7 +139,7 @@ impl TryFrom for Ticker { .copied() .find(|ch| !ch.is_ascii_uppercase()) { - return Err(InvalidIdent::InvalidChar(ch)); + return Err(InvalidIdent::InvalidChar(ascii, ch)); } let s = Confined::try_from(ascii)?; Ok(Self(s)) diff --git a/std/src/stl/stl.rs b/std/src/stl/stl.rs index 5ceb9a32..493861ad 100644 --- a/std/src/stl/stl.rs +++ b/std/src/stl/stl.rs @@ -19,56 +19,39 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::str::FromStr; - -use bp::dbc::LIB_NAME_BPCORE; -use bp::LIB_NAME_BITCOIN; -use strict_encoding::STD_LIB; -use strict_types::typelib::LibBuilder; +use bp::bc::stl::bitcoin_stl; +use strict_types::stl::std_stl; +use strict_types::typelib::{LibBuilder, TranslateError}; use strict_types::typesys::SystemBuilder; -use strict_types::{Dependency, SemId, TypeLib, TypeLibId, TypeSystem}; +use strict_types::{SemId, TypeLib, TypeSystem}; use super::{ DivisibleAssetSpec, Error, MediaType, RicardianContract, Timestamp, LIB_NAME_RGB_CONTRACT, }; use crate::stl::ProofOfReserves; -#[derive(Debug)] -pub struct StandardLib(TypeLib); - -impl StandardLib { - pub fn new() -> Self { - fn builder() -> Result { - let bitcoin_id = TypeLibId::from_str( - "circus_report_jeep_2bj6eDer24ZBSVq6JgQW2BrARt6vx56vMWzF35J45gzY", - )?; - let bpcore_id = TypeLibId::from_str( - "harlem_null_puma_DxuLX8d9UiMyEJMRJivMFviK1B8t1QWyjywXuDC13iKR", - )?; - let stdlib_id = TypeLibId::from_str( - "alabama_speed_polo_J2wwnFdkbUQt2sg5EZndccZdPZgFUGmLcK3Uw5TbzjRh", - )?; - - let imports = bset! { - Dependency::with(bitcoin_id, libname!(LIB_NAME_BITCOIN)), - Dependency::with(bpcore_id, libname!(LIB_NAME_BPCORE)), - Dependency::with(stdlib_id, libname!(STD_LIB)), - }; - - LibBuilder::new(libname!(LIB_NAME_RGB_CONTRACT)) - .process::()? - .process::()? - .process::()? - .process::()? - .process::()? - .compile(imports) - .map_err(Error::from) - } +/// Strict types id for the library providing data types from [`dbc`] and +/// [`seals`] crates. +pub const LIB_ID_RGB_CONTRACT: &str = + "level_decide_percent_6z2gZQEJsnP4xoNUC94vqYEE9V7gKQbeJhb5521xta5u"; - Self(builder().expect("error in standard RGBContract type library")) - } +fn _rgb_contract_stl() -> Result { + LibBuilder::new(libname!(LIB_NAME_RGB_CONTRACT)) + .transpile::() + .transpile::() + .transpile::() + .transpile::() + .transpile::() + .compile(bset! { + std_stl().to_dependency(), + bitcoin_stl().to_dependency() + }) +} - pub fn type_lib(&self) -> TypeLib { self.0.clone() } +/// Generates strict type library providing data types from [`dbc`] and +/// [`seals`] crates. +pub fn rgb_contract_stl() -> TypeLib { + _rgb_contract_stl().expect("invalid strict type RGBContract library") } #[derive(Debug)] @@ -77,9 +60,12 @@ pub struct StandardTypes(TypeSystem); impl StandardTypes { pub fn new() -> Self { fn builder() -> Result { - let lib = StandardLib::new().type_lib(); - let sys = SystemBuilder::new().import(lib)?.finalize()?; - Ok(sys) + SystemBuilder::new() + .import(std_stl())? + .import(bitcoin_stl())? + .import(rgb_contract_stl())? + .finalize() + .map_err(Error::from) } Self(builder().expect("error in standard RGBContract type system")) @@ -88,8 +74,19 @@ impl StandardTypes { pub fn type_system(&self) -> TypeSystem { self.0.clone() } pub fn get(&self, name: &'static str) -> SemId { - self.0 - .id_by_name(name) - .expect("type is absent in standard RGBContract type library") + self.0.id_by_name(name).unwrap_or_else(|| { + panic!("type '{name}' is absent in standard RGBContract type library") + }) + } +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn lib_id() { + let lib = rgb_contract_stl(); + assert_eq!(lib.id().to_string(), LIB_ID_RGB_CONTRACT); } } diff --git a/std/tests/data/rgb20.asc.rgb b/std/tests/data/rgb20.asc.rgb index f5fa5cf8..2d99bbb6 100644 --- a/std/tests/data/rgb20.asc.rgb +++ b/std/tests/data/rgb20.asc.rgb @@ -1,9 +1,9 @@ ----- BEGIN RGB INTERFACE ----- -Id: 3P9iZyY13tF87UwaEymNc5fKcZiK5wsAYi8XrZxPpicJ +Id: CHafPGXMya8spywxuJ3Sr9BCJc51ojbEKBqpT4xaEk22 -AAVSR0IyMAIMQ29udHJhY3RUZXh0AfDTqK9GOmPO/Eo6IS1J9JE3B2p4fm+I+YYwPQhj3cowAQdO -b21pbmFsAQYbxMgtYWuzsk/Vszum5R+kOtczd6sM1M9J+aoVoXS/AQEGQXNzZXRzAAIAAAIMQ29u -dHJhY3RUZXh0AQABAAdOb21pbmFsAQABAAEGQXNzZXRzAQD//wABCFRyYW5zZmVyAAABBkFzc2V0 -cwEA//8BBkFzc2V0cwEA//8AAQZBc3NldHMAAQhUcmFuc2Zlcg== +AAVSR0IyMAIMQ29udHJhY3RUZXh0AbC/tv4Ak69rMjDl/Q09aarxS/CY3wdyjSULrjd5hhBwAQRz +cGVjAXEb91tMkPjmLh7Tn4j0rGsW+l/fNNy+o7N/vJ4En1+oAQEGQXNzZXRzAAIAAAIMQ29udHJh +Y3RUZXh0AQABAAdOb21pbmFsAQABAAEGQXNzZXRzAQD//wABCFRyYW5zZmVyAAABBkFzc2V0cwEA +//8BBkFzc2V0cwEA//8AAQZBc3NldHMAAQhUcmFuc2Zlcg== ----- END RGB INTERFACE ----- diff --git a/stl/RGBContract@0.1.0.sta b/stl/RGBContract@0.1.0.sta new file mode 100644 index 00000000..30101f12 --- /dev/null +++ b/stl/RGBContract@0.1.0.sta @@ -0,0 +1,40 @@ +-----BEGIN STRICT TYPE LIB----- +Id: level_decide_percent_6z2gZQEJsnP4xoNUC94vqYEE9V7gKQbeJhb5521xta5u +Name: RGBContract +Dependencies: + Std@quota_conan_fashion_3TZmAPf8EkQZnbGS1g8uMGes6jEWPqNkFB6pLUKeoefg, + Bitcoin@cubic_filter_vampire_AqBBP1ZeTXrdAePf6SBcUGbttpvxpHKG7uJLKFkVxtGi + +C1JHQkNvbnRyYWN0AiSFhLGjG96fdR4TFEG0AGzfutGiP5FohicaA084WrP3A1N0 +ZJIQkg/ubfNGqW8oKZIsOFGI79ITsMEnykvtXkwVvWFzB0JpdGNvaW4MAAtBc3Nl +dE5hbWluZwYDBnRpY2tlcgEGVGlja2VytURY8FWOu2Psu6SH7h12Td7cMp4g7D9M +/ycWuxurLYEEbmFtZQEETmFtZcSvODtTRjEQqQHFn/5WcPnPELrPjibqWoArFs2z +51+7B2RldGFpbHMABAIABG5vbmUAAAABBHNvbWUABQEBB0RldGFpbHORKBuzCYJV +oCtG6PaOnlC/I6TzeXUFoT1U/+CoNtEEaQdEZXRhaWxzBQEACAABAQAAAAAAAAD/ +AAAAAAAAABJEaXZpc2libGVBc3NldFNwZWMGAgZuYW1pbmcBC0Fzc2V0TmFtaW5n +sOd4RBH2Kem5mVKp5Wr3obgUfguxBntblTQwxxwJ7HEJcHJlY2lzaW9uAQlQcmVj +aXNpb27FVBOO5QPl7q6uA1owOfyZwgfSdZ0R7IOdhIgl+FdMpQxNZWRpYVJlZ05h +bWUFAQAIAQhNaW1lQ2hhcr3pSt3MkQVZr53OKIvtOa+Gfd+gcWoc8jFuAIfDot4s +AQAAAAAAAABAAAAAAAAAAAlNZWRpYVR5cGUGAwR0eXBlAQxNZWRpYVJlZ05hbWX/ +apx6oKVvgixF5zWd+OQOfw6SBx90HcQ2xxgG2xZjuwdzdWJ0eXBlAQxNZWRpYVJl +Z05hbWX/apx6oKVvgixF5zWd+OQOfw6SBx90HcQ2xxgG2xZjuwdjaGFyc2V0AAQC +AARub25lAAAAAQRzb21lAAUBAQxNZWRpYVJlZ05hbWX/apx6oKVvgixF5zWd+OQO +fw6SBx90HcQ2xxgG2xZjuwhNaW1lQ2hhcgMtBGV4Y2whBGhhc2gjBmRvbGxhciQD +YW1wJgRwbHVzKwRkYXNoLQNkb3QuBHplcm8wA29uZTEDdHdvMgV0aHJlZTMEZm91 +cjQEZml2ZTUDc2l4NgVzZXZlbjcFZWlnaHQ4BG5pbmU5BWNhcmV0XgZsb2Rhc2hf +AWFhAWJiAWNjAWRkAWVlAWZmAWdnAWhoAWlpAWpqAWtrAWxsAW1tAW5uAW9vAXBw +AXFxAXJyAXNzAXR0AXV1AXZ2AXd3AXh4AXl5AXp6BE5hbWUFAQAIAg5Bc2NpaVBy +aW50YWJsZQNTdGRVrM0L04UH/5W1FM8zvDuwSzezztFtcHT00n7nafhwiwEAAAAA +AAAAKAAAAAAAAAAJUHJlY2lzaW9uAxMLaW5kaXZpc2libGUABGRlY2kBBWNlbnRp +AgVtaWxsaQMJZGVjaU1pbGxpBApjZW50aU1pbGxpBQVtaWNybwYJZGVjaU1pY3Jv +BwpjZW50aU1pY3JvCARuYW5vCQhkZWNpTmFubwoJY2VudGlOYW5vCwRwaWNvDAhk +ZWNpUGljbw0JY2VudGlQaWNvDgVmZW10bw8JZGVjaUZlbXRvEApjZW50aUZlbXRv +EQRhdHRvEg9Qcm9vZk9mUmVzZXJ2ZXMGAgR1dHhvAghPdXRwb2ludAdCaXRjb2lu +seQ77ILjghstfM7omn0hPai3fuoFGLz6T21vjf4Clt4FcHJvb2YACAAAQAAAAAAA +AAAA//8AAAAAAAARUmljYXJkaWFuQ29udHJhY3QFAQAIAAEAAAAAAAAAAP//AAAA +AAAABlRpY2tlcgUBAAgCDEFscGhhQ2Fwc051bQNTdGS72GBPmbXJBH3gfVWQaaKG +0nyUFDEG4vXq4mauRPcWhwEAAAAAAAAACAAAAAAAAAAJVGltZXN0YW1wBQEAAEQ= + + +-----END STRICT TYPE LIB----- + diff --git a/stl/RGBContract@0.1.0.stl b/stl/RGBContract@0.1.0.stl new file mode 100644 index 0000000000000000000000000000000000000000..c90c23d19c2b922a3b0b51f5230b301627b82f9c GIT binary patch literal 1391 zcmbVMYfKzf6rQ{DShkBi3X(=zwP`IhfPp?Jgfx}1Vq$s8!v`jNO*%BS`hVU_5jL>ya>9vOQtb@r6`a8h#Nhm3sf{Pf_y9)D-rLu`3o?f4Q~ zMZCQUz4436-QppfzP&dy@0nvi%_NO}miEqp)ChGTRNME2=lP#&x;PR>a&uYIHSy|+4Y{ao%ehob-SfQexMpc>YRtX#}` z4+bo%4ucK4X@@{1>SWnbCo z3OBhl9ZFOQtH4zeg_o<7y64!r#o=MLHaq{%zR#UAW`AP%_5LHr9$S8{nrs>woR<<=tQV8VxmKv- zY?fLhhb7H;2T%MuggZGOHuYVc4+Y?E)e33$B#Lg4d(`g-8^1B5_B188gnvJ4ajs4Bo1Xc}m00=f!gE8+9zhd8y?9FF}vx7 zVU?xO8D%Msp+l)+SBw=}M$tN#9ce)~ry&W)+EfKa53EoYjN^S!AvoUFEVf|6il&Vd zIgt>&KE6W7*jMhWga*_D&=4G)NrKoBQ*IKCZW9t+D`Phc!W}<$q-GtSy!B4o=Dp`W zYG2?tT==70!EfAmygkcnmJl6bChB-5vO2_xm5BC|4w4#Ocq_BM`h08ut!^m0EwP2N z<`;`Z%_uV!t0|#xUn=jL_>yb8-d6J_8tj}o{8n;~aO1ay8@^%BQc72}DKr85xT@)( M8id-C>M@?b05NywlK=n! literal 0 HcmV?d00001 diff --git a/stl/RGBContract@0.1.0.sty b/stl/RGBContract@0.1.0.sty new file mode 100644 index 00000000..fe15d73b --- /dev/null +++ b/stl/RGBContract@0.1.0.sty @@ -0,0 +1,47 @@ +{- + Id: level_decide_percent_6z2gZQEJsnP4xoNUC94vqYEE9V7gKQbeJhb5521xta5u + Name: RGBContract + Version: 0.1.0 + Description: Types for writing RGB contracts and interfaces + Author: Dr Maxim Orlovsky + Copyright (C) 2023 LNP/BP Standards Association. All rights reserved. + License: Apache-2.0 +-} + +typelib RGBContract -- level_decide_percent_6z2gZQEJsnP4xoNUC94vqYEE9V7gKQbeJhb5521xta5u + +import quota_conan_fashion_3TZmAPf8EkQZnbGS1g8uMGes6jEWPqNkFB6pLUKeoefg as Std +import cubic_filter_vampire_AqBBP1ZeTXrdAePf6SBcUGbttpvxpHKG7uJLKFkVxtGi as Bitcoin + + +data AssetNaming :: ticker Ticker + , name Name + , details Details? +data Details :: [Unicode ^ 1..0xff] +data DivisibleAssetSpec :: naming AssetNaming, precision Precision +data MediaRegName :: [MimeChar ^ 1..0x40] +data MediaType :: type MediaRegName + , subtype MediaRegName + , charset MediaRegName? +data MimeChar :: excl:33 | hash:35 | dollar:36 | amp:38 + | dash:45 | dot:46 | zero:48 | one:49 + | three:51 | four:52 | five:53 | six:54 + | eight:56 | nine:57 | caret:94 | lodash:95 + | b:98 | c:99 | d:100 | e:101 + | g:103 | h:104 | i:105 | j:106 + | l:108 | m:109 | n:110 | o:111 + | q:113 | r:114 | s:115 | t:116 + | v:118 | w:119 | x:120 | y:121 + + +data Name :: [Std.AsciiPrintable ^ 1..0x28] +data Precision :: indivisible:0 | deci:1 | centi:2 | milli:3 + | centiMilli:5 | micro:6 | deciMicro:7 | centiMicro:8 + | deciNano:10 | centiNano:11 | pico:12 | deciPico:13 + | femto:15 | deciFemto:16 | centiFemto:17 | atto:18 + +data ProofOfReserves :: utxo Bitcoin.Outpoint, proof [Byte] +data RicardianContract :: [Unicode] +data Ticker :: [Std.AlphaCapsNum ^ 1..0x8] +data Timestamp :: I32 + diff --git a/stl/RGBContracts-v0.10.1.C.stl b/stl/RGBContracts-v0.10.1.C.stl deleted file mode 100644 index 35619f8389e4a40db1cc5476ebeef85f14dedc32..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1088 zcmZA0OH9;I6b9gyc7_=qBC=3-D4-~UeLsAF@>GNoaTG(L{M1ZLQPQO zf?$*wOiWm@b7A7jM59|=7~Qy|+z|IPywyZHL2=k)a6HqGyBsc&#>Hy#SR zl$R>X=0?*ESk75jMLs=>U{50&*E5N(^r1}ePX71`tkBWP1{7-$Cd|w##id+WG`#uvGn>A z$RcVR9jf)s+;sEL*@4v`h9-c4$GBtnWX2q|rwkQ8OnUZ|Vj#wj@&=)l+HiBWaCv4iT zmE(z7(Wu4v$+dP8*}POCl|872oZDZvny)ARYx$E0B)?r46Xqw`T!hG*M4_K3UL;BbMA;%Lmx$^hQHv7w800yd$U8(~h$vnrN^zo`ASy0V9VTic jMEwdBxKSd1l_-o6#c`r^jVNCyDicI?GW(zVGJo@5)4VB7 diff --git a/stl/RGBContracts-v0.10.1.C.sty b/stl/RGBContracts-v0.10.1.C.sty deleted file mode 100644 index b81a83fd..00000000 --- a/stl/RGBContracts-v0.10.1.C.sty +++ /dev/null @@ -1,23 +0,0 @@ -{- - Id: august_plasma_info_5Dvn6nftvkfGSNavzjHwqgGnJgM1dgtbLNbyMGU8aoMx - Name: RGBCore - Description: Consensus layer for RGB smart contracts - Author: Dr Maxim Orlovsky - Copyright (C) 2023 LNP/BP Standards Association. All rights reserved. - License: Apache-2.0 --} - -typelib RGBContract -- august_plasma_info_5Dvn6nftvkfGSNavzjHwqgGnJgM1dgtbLNbyMGU8aoMx - --- no dependencies - -data ContractDetails :: [Unicode ^ 40..0xff] -data ContractName :: [Unicode ^ 1..0x28] -data ContractText :: [Unicode] -data Nominal :: ticker Ticker - , name ContractName - , details ContractDetails? - , precision Precision -data Precision :: indivisible:0 | deci:1 | centi:2 | milli:3 | deciMilli:4 | centiMilli:5 | micro:6 | deciMicro:7 | centiMicro:8 | nano:9 | deciNano:10 | centiNano:11 | pico:12 | deciPico:13 | centiPico:14 | femto:15 | deciFemto:16 | centiFemto:17 | atto:18 -data Ticker :: [Ascii ^ 1..0x8] - diff --git a/stl/RGBContracts-v0.10.2.A.stl b/stl/RGBContracts-v0.10.2.A.stl deleted file mode 100644 index 7a3f64b3584da0ea5be9ca3ed55529d2edb3c08d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1103 zcmZA0NlesW7zW^$b~Y9fIjA=jP!z%Liwh_Wpa_UKiXvEtp-5$>#hHQ#3I{x>2}(Q= zj1q&12`6qIOgx!r^oj?g7f%z3F&LwX9*p?@vtVKmPv7+W`gQ&DI-2V09ovnEBQE8m z3bQ$Ax?wAt@X(Z>qARHMwwBrFXS>?MF*DslXG+=D^_Gx1>ZV&V9n@N8jIYg!S#~(; zWxcKy88qXxHrYWxMixW@%!rL#i#o7z);+bSP9Fq=|Fonz6=%L zNixaRr6s0|(|_N8;aeV_FZwbyf8%EPug;by|2moCJj?F0Mlhi_YEo<;hS8pgX}eaA zCuT*X784-HT1jMcQ-xIapc;ug-b@wIm#rfE@m_2v;3ucHA>{^AXOfu54p|W=KUHc+ zDoB?|+~DaqW3E$}n%PL=#`MfoE@H#3>ukz=nACS}KKvsdG0aXXuKA`Vs z423%Y_=7;G0b(tX4gvWvQ0jnM540fA8yG|78Ufz~gd;#a3Z!Nr9|KAYP+Ni42K3{M zp>geiKLLaeAf5zL2*{^^avG?eKsy8Uvy7p0U4TCagl-`A0O>rC4WQs9>S`Ehy+Dt! z2G4PQMBXF{{Y3F1Q5qo17E!rGR0oM#l&Hrb&)G!YAqqo8@iI}06XgU^af#|MQ5zxZ uSD?U+68Wn{VT>q_6QyfJ`8rXVAgYtub?(os=0M1bnF%)>8^X^)1^)tRD=k$3 diff --git a/stl/RGBContracts-v0.10.2.A.sty b/stl/RGBContracts-v0.10.2.A.sty deleted file mode 100644 index dba19ad3..00000000 --- a/stl/RGBContracts-v0.10.2.A.sty +++ /dev/null @@ -1,24 +0,0 @@ -{- - Id: vocal_roman_atomic_4LGTZrsU9mS1f3pjm1Kzz5KSSSvfXUacTr9gw7d8TwCR - Name: RGBCore - Description: Consensus layer for RGB smart contracts - Author: Dr Maxim Orlovsky - Copyright (C) 2023 LNP/BP Standards Association. All rights reserved. - License: Apache-2.0 --} - -typelib RGBContract -- vocal_roman_atomic_4LGTZrsU9mS1f3pjm1Kzz5KSSSvfXUacTr9gw7d8TwCR - --- no dependencies - -data ContractDetails :: [Unicode ^ 40..0xff] -data ContractName :: [Unicode ^ 1..0x28] -data ContractText :: [Unicode] -data Nominal :: ticker Ticker - , name ContractName - , details ContractDetails? - , precision Precision -data Precision :: indivisible:0 | deci:1 | centi:2 | milli:3 | deciMilli:4 | centiMilli:5 | micro:6 | deciMicro:7 | centiMicro:8 | nano:9 | deciNano:10 | centiNano:11 | pico:12 | deciPico:13 | centiPico:14 | femto:15 | deciFemto:16 | centiFemto:17 | atto:18 -data Ticker :: [Ascii ^ 1..0x8] -data Timestamp :: I32 - diff --git a/stl/RGBContracts-v0.10.3.A.stl b/stl/RGBContracts-v0.10.3.A.stl deleted file mode 100644 index 009f47b6bedc4b68260527917d3f8135d0c7c469..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1361 zcmbVMZA=_R7~Z*^-Miy}3T@8Twi<#qXiEeAprvY3K14-6PB>yPO>xzr zpP6Uhci!iHLk;(qR}h_=l1#yk9|YdKe|qm*?|xjhcl#UP4sBU+{N|kMKh{0iw<!>XL>4WVcb#^w7xl$L}hvAz8EKOJ6DbbC0=yLq()&tnWncq>#7L zuOKR6)#9L!gF4X>$8i8!L_?eafWLB{?Jrn`H04~4*z%-mSH@|VYl{kql+^QlssYV0IqEBQovfRMm6K!reb2xBT?N6MR zs(&7PTe=j^&-+~2QlIvLAL4Uu&vg$TA-!wvxw3I!_PgxI zvY+waLRX$DIkQy!DlCusExYx9+>%+O%nScsq5l-XLgIWOL@8O#g9*t>h)>a_PKv4ifAQl7hI7lP_#-ObYw6_CQ1)2tQ z9S{Nx19Wr%(*%|UCr`Sc6C0^ggIk+k z`!sa%N&nolBTLS&f9KBEAJ}y4+y%{`*T#2T!L!Cbuet?Zbr&qfFAiZ{@l4A>g}Dw0 zGSVsb2^v;a%mEawHQA%g=(R6X+>VT(G8u1vLGJTy`}*ST=Z8-Et2Wy(x^r4E93j@locBE3T)K~Q8Zav- z>m}WrXY=ize!his=^^D-CbLX65>ka^Sar6RuFL2bkJKL;ISYFxdYYcbL%YTwJ-DP; foSgY#GB#ZKdw93^V-|zEf>GA47G>sSl3e9q@t4%J diff --git a/stl/RGBContracts-v0.10.3.A.sty b/stl/RGBContracts-v0.10.3.A.sty deleted file mode 100644 index bfccf1b8..00000000 --- a/stl/RGBContracts-v0.10.3.A.sty +++ /dev/null @@ -1,31 +0,0 @@ -{- - Id: screen_julius_junior_J1PKHWvqJU1nBLFxjezAmsQpLHVo3JgnDh1VH2iFSHHR - Name: RGBCore - Description: Consensus layer for RGB smart contracts - Author: Dr Maxim Orlovsky - Copyright (C) 2023 LNP/BP Standards Association. All rights reserved. - License: Apache-2.0 --} - -typelib RGBContract -- screen_julius_junior_J1PKHWvqJU1nBLFxjezAmsQpLHVo3JgnDh1VH2iFSHHR - -import circus_report_jeep_2bj6eDer24ZBSVq6JgQW2BrARt6vx56vMWzF35J45gzY as Bitcoin - - -data AssetNaming :: ticker Ticker - , name Name - , details Details? -data Details :: [Unicode ^ 1..0xff] -data DivisibleAssetSpec :: naming AssetNaming, precision Precision -data MediaRegName :: [MimeChar ^ 1..0x40] -data MediaType :: type MediaRegName - , subtype MediaRegName - , charset MediaRegName? -data MimeChar :: excl:33 | hash:35 | dollar:36 | amp:38 | plus:43 | dash:45 | dot:46 | zero:48 | one:49 | two:50 | three:51 | four:52 | five:53 | six:54 | seven:55 | eight:56 | nine:57 | caret:94 | lodash:95 | a:97 | b:98 | c:99 | d:100 | e:101 | f:102 | g:103 | h:104 | i:105 | j:106 | k:107 | l:108 | m:109 | n:110 | o:111 | p:112 | q:113 | r:114 | s:115 | t:116 | u:117 | v:118 | w:119 | x:120 | y:121 | z:122 -data Name :: [StdLib.AsciiPrintable ^ 1..0x28] -data Precision :: indivisible:0 | deci:1 | centi:2 | milli:3 | deciMilli:4 | centiMilli:5 | micro:6 | deciMicro:7 | centiMicro:8 | nano:9 | deciNano:10 | centiNano:11 | pico:12 | deciPico:13 | centiPico:14 | femto:15 | deciFemto:16 | centiFemto:17 | atto:18 -data ProofOfReserves :: utxo Bitcoin.Outpoint, proof [U8] -data RicardianContract :: [Unicode] -data Ticker :: [StdLib.AlphaCapsNum ^ 1..0x8] -data Timestamp :: I32 - From 3c10ee84a0af9a4abc16e7c3174fe9b7abbd43dd Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 02:37:54 +0200 Subject: [PATCH 11/33] stl: fix display of enum types --- Cargo.lock | 2 +- stl/RGBContract@0.1.0.sty | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 483da06b..03bd0a11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -930,7 +930,7 @@ dependencies = [ [[package]] name = "strict_types" version = "1.1.1" -source = "git+https://github.com/strict-types/strict-types?branch=fix/typesys-builder#649eface5c47a117ff443bfac7ba70a73de2ba27" +source = "git+https://github.com/strict-types/strict-types?branch=fix/typesys-builder#e34c1c64488a064334cb7abdc5dccab9d74a2ae2" dependencies = [ "amplify", "baid58", diff --git a/stl/RGBContract@0.1.0.sty b/stl/RGBContract@0.1.0.sty index fe15d73b..2267b5ec 100644 --- a/stl/RGBContract@0.1.0.sty +++ b/stl/RGBContract@0.1.0.sty @@ -24,21 +24,24 @@ data MediaType :: type MediaRegName , subtype MediaRegName , charset MediaRegName? data MimeChar :: excl:33 | hash:35 | dollar:36 | amp:38 - | dash:45 | dot:46 | zero:48 | one:49 - | three:51 | four:52 | five:53 | six:54 - | eight:56 | nine:57 | caret:94 | lodash:95 + | plus:43 | dash:45 | dot:46 | zero:48 + | one:49 | two:50 | three:51 | four:52 + | five:53 | six:54 | seven:55 | eight:56 + | nine:57 | caret:94 | lodash:95 | a:97 | b:98 | c:99 | d:100 | e:101 - | g:103 | h:104 | i:105 | j:106 - | l:108 | m:109 | n:110 | o:111 - | q:113 | r:114 | s:115 | t:116 + | f:102 | g:103 | h:104 | i:105 + | j:106 | k:107 | l:108 | m:109 + | n:110 | o:111 | p:112 | q:113 + | r:114 | s:115 | t:116 | u:117 | v:118 | w:119 | x:120 | y:121 - + | z:122 data Name :: [Std.AsciiPrintable ^ 1..0x28] data Precision :: indivisible:0 | deci:1 | centi:2 | milli:3 - | centiMilli:5 | micro:6 | deciMicro:7 | centiMicro:8 - | deciNano:10 | centiNano:11 | pico:12 | deciPico:13 - | femto:15 | deciFemto:16 | centiFemto:17 | atto:18 + | deciMilli:4 | centiMilli:5 | micro:6 | deciMicro:7 + | centiMicro:8 | nano:9 | deciNano:10 | centiNano:11 + | pico:12 | deciPico:13 | centiPico:14 | femto:15 + | deciFemto:16 | centiFemto:17 | atto:18 data ProofOfReserves :: utxo Bitcoin.Outpoint, proof [Byte] data RicardianContract :: [Unicode] From 5b42f3409b3ec421f9d55b4b9043d246476d5738 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 10:37:36 +0200 Subject: [PATCH 12/33] iface: add assignments requirement hint --- std/src/interface/iface.rs | 102 ++++++++++++++++++++++++------------- std/src/interface/mod.rs | 6 +-- std/src/interface/rgb20.rs | 1 + 3 files changed, 70 insertions(+), 39 deletions(-) diff --git a/std/src/interface/iface.rs b/std/src/interface/iface.rs index dae6b1e2..77e2b646 100644 --- a/std/src/interface/iface.rs +++ b/std/src/interface/iface.rs @@ -70,6 +70,19 @@ impl FromStr for IfaceId { fn from_str(s: &str) -> Result { Self::from_baid58_str(s) } } +#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)] +pub enum Req { + Optional, + Required, + NoneOrMore, + OneOrMore, +} + +impl Req { + pub fn is_required(self) -> bool { self == Req::Required || self == Req::OneOrMore } + pub fn is_multiple(self) -> bool { self == Req::NoneOrMore || self == Req::OneOrMore } +} + #[derive(Clone, PartialEq, Eq, Hash, Debug)] #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB_STD)] @@ -78,52 +91,63 @@ impl FromStr for IfaceId { derive(Serialize, Deserialize), serde(crate = "serde_crate", rename_all = "camelCase") )] -pub struct Req { - pub info: Info, +pub struct ValencyIface { pub required: bool, + pub multiple: bool, } -impl Req { - pub fn some() -> Self { - Req { - info: GlobalIface::Any, +#[derive(Clone, PartialEq, Eq, Hash, Debug)] +#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB_STD)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", rename_all = "camelCase") +)] +pub struct GlobalIface { + pub sem_id: Option, + pub required: bool, + pub multiple: bool, +} + +impl GlobalIface { + pub fn any(req: Req) -> Self { + GlobalIface { + sem_id: None, + required: req.is_required(), + multiple: req.is_multiple(), + } + } + pub fn optional(sem_id: SemId) -> Self { + GlobalIface { + sem_id: Some(sem_id), required: false, + multiple: false, } } - pub fn require_any() -> Self { - Req { - info: GlobalIface::Any, + pub fn required(sem_id: SemId) -> Self { + GlobalIface { + sem_id: Some(sem_id), required: true, + multiple: false, } } - pub fn optional(sem_id: SemId) -> Self { - Req { - info: GlobalIface::Typed(sem_id), + pub fn none_or_many(sem_id: SemId) -> Self { + GlobalIface { + sem_id: Some(sem_id), required: false, + multiple: true, } } - pub fn require(sem_id: SemId) -> Self { - Req { - info: GlobalIface::Typed(sem_id), + pub fn one_or_many(sem_id: SemId) -> Self { + GlobalIface { + sem_id: Some(sem_id), required: true, + multiple: true, } } } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] -#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] -#[strict_type(lib = LIB_NAME_RGB_STD, tags = order)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(crate = "serde_crate", rename_all = "camelCase") -)] -pub enum GlobalIface { - #[strict_type(dumb)] - Any, - Typed(SemId), -} - #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB_STD, tags = order)] @@ -133,22 +157,28 @@ pub enum GlobalIface { serde(crate = "serde_crate", rename_all = "camelCase") )] pub struct AssignIface { - pub public: bool, pub owned_state: OwnedIface, + pub public: bool, + pub required: bool, + pub multiple: bool, } impl AssignIface { - pub fn public(owned_state: OwnedIface) -> Self { + pub fn public(owned_state: OwnedIface, req: Req) -> Self { AssignIface { - public: true, owned_state, + public: true, + required: req.is_required(), + multiple: req.is_multiple(), } } - pub fn private(owned_state: OwnedIface) -> Self { + pub fn private(owned_state: OwnedIface, req: Req) -> Self { AssignIface { - public: false, owned_state, + public: false, + required: req.is_required(), + multiple: req.is_multiple(), } } } @@ -233,9 +263,9 @@ pub struct TransitionIface { pub struct Iface { pub version: VerNo, pub name: TypeName, - pub global_state: TinyOrdMap>, + pub global_state: TinyOrdMap, pub assignments: TinyOrdMap, - pub valencies: TinyOrdMap>, + pub valencies: TinyOrdMap, pub genesis: GenesisIface, pub transitions: TinyOrdMap, pub extensions: TinyOrdMap, diff --git a/std/src/interface/mod.rs b/std/src/interface/mod.rs index 97af3fa2..41998459 100644 --- a/std/src/interface/mod.rs +++ b/std/src/interface/mod.rs @@ -33,11 +33,11 @@ mod suppl; pub use builder::{BuilderError, ContractBuilder, OperationBuilder, TransitionBuilder}; pub use contract::{ContractIface, FungibleAllocation, TypedState}; pub use iface::{ - ExtensionIface, GenesisIface, GlobalIface, Iface, IfaceId, OwnedIface, Req, TransitionIface, - TypeReqMap, + AssignIface, ExtensionIface, GenesisIface, GlobalIface, Iface, IfaceId, OwnedIface, Req, + TransitionIface, TypeReqMap, ValencyIface, }; pub use iimpl::{IfaceImpl, IfacePair, ImplId, NamedType, SchemaIfaces}; -pub use rgb20::rgb20; +pub use rgb20::{rgb20, rgb20_stl, LIB_ID_RGB20, LIB_NAME_RGB20}; pub use suppl::{AppDeriveIndex, ContractSuppl, OwnedStateSuppl, SupplId, TickerSuppl}; #[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display, Default)] diff --git a/std/src/interface/rgb20.rs b/std/src/interface/rgb20.rs index e5d6c4bb..923e49c5 100644 --- a/std/src/interface/rgb20.rs +++ b/std/src/interface/rgb20.rs @@ -38,6 +38,7 @@ pub fn rgb20() -> Iface { }, assignments: tiny_bmap! { tn!("Assets") => AssignIface::private(OwnedIface::Amount), + tn!("assetOwner") => AssignIface::private(OwnedIface::Amount, Req::NoneOrMore), }, valencies: none!(), genesis: GenesisIface { From 716b29b975d5ccf35f8ef01b0f3fa49c5c74c5a9 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 10:38:32 +0200 Subject: [PATCH 13/33] stl: derive Debug for ProofOfReserves type --- std/src/stl/chain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/std/src/stl/chain.rs b/std/src/stl/chain.rs index a5b6c959..ed240353 100644 --- a/std/src/stl/chain.rs +++ b/std/src/stl/chain.rs @@ -25,7 +25,7 @@ use strict_encoding::{StrictDeserialize, StrictSerialize}; use super::LIB_NAME_RGB_CONTRACT; -#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, From)] +#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From)] #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB_CONTRACT, dumb = ProofOfReserves::new(strict_dumb!(), strict_dumb!()))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))] From ad3931fede9b9b30381c2ce67462c6f8a16dc359 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 10:41:56 +0200 Subject: [PATCH 14/33] iface: complete RGB20 type library --- std/src/bin/rgb-stl.rs | 20 +++++++++++-- std/src/interface/rgb20.rs | 57 ++++++++++++++++++++++++++++++++++--- std/src/stl/stl.rs | 32 ++++++++++++--------- stl/RGB20@0.1.0.sta | 15 ++++++++++ stl/RGB20@0.1.0.stl | Bin 0 -> 200 bytes stl/RGB20@0.1.0.sty | 19 +++++++++++++ 6 files changed, 124 insertions(+), 19 deletions(-) create mode 100644 stl/RGB20@0.1.0.sta create mode 100644 stl/RGB20@0.1.0.stl create mode 100644 stl/RGB20@0.1.0.sty diff --git a/std/src/bin/rgb-stl.rs b/std/src/bin/rgb-stl.rs index bfcea609..a4f5b737 100644 --- a/std/src/bin/rgb-stl.rs +++ b/std/src/bin/rgb-stl.rs @@ -20,6 +20,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use rgbstd::interface::rgb20_stl; use rgbstd::stl::rgb_contract_stl; use strict_types::typelib::parse_args; @@ -36,20 +37,35 @@ fn main() { Description: Types for writing RGB contracts and interfaces Author: Dr Maxim Orlovsky Copyright (C) 2023 LNP/BP Standards Association. All rights reserved. + License: Apache-2.0", + ), + ) + .expect("unable to write to the file"); + + rgb20_stl() + .serialize( + format, + dir.as_ref(), + "0.1.0", + Some( + " + Description: Types for RGB20 interface + Author: Dr Maxim Orlovsky + Copyright (C) 2023 LNP/BP Standards Association. All rights reserved. License: Apache-2.0", ), ) .expect("unable to write to the file"); /* - bp::stl::bp_core_stl() + bp::stl::rgb_std_stl() .serialize( format, dir, "0.1.0", Some( " - Description: Bitcoin client-side-validation library + Description: RGB standard library Author: Dr Maxim Orlovsky Copyright (C) 2023 LNP/BP Standards Association. All rights reserved. License: Apache-2.0", diff --git a/std/src/interface/rgb20.rs b/std/src/interface/rgb20.rs index 923e49c5..2299a69c 100644 --- a/std/src/interface/rgb20.rs +++ b/std/src/interface/rgb20.rs @@ -19,14 +19,57 @@ // See the License for the specific language governing permissions and // limitations under the License. +use amplify::confinement::SmallOrdSet; +use bp::bc::stl::bitcoin_stl; use rgb::Occurrences; +use strict_encoding::{StrictDeserialize, StrictSerialize}; +use strict_types::typelib::{LibBuilder, TranslateError}; +use strict_types::TypeLib; -use crate::interface::iface::AssignIface; -use crate::interface::{GenesisIface, Iface, OwnedIface, Req, TransitionIface, VerNo}; -use crate::stl::StandardTypes; +use super::{ + AssignIface, GenesisIface, GlobalIface, Iface, OwnedIface, Req, TransitionIface, VerNo, +}; +use crate::stl::{rgb_contract_stl, ProofOfReserves, StandardTypes}; + +pub const LIB_NAME_RGB20: &str = "RGB20"; +/// Strict types id for the library providing data types for RGB20 interface. +pub const LIB_ID_RGB20: &str = "escort_chamber_clone_8g3y7GatrZYywXA38YKq1vCWmtrTYSMEBNgPqDy8NBDF"; + +#[derive( + Wrapper, WrapperMut, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default, From +)] +#[wrapper(Display, FromStr, Add, Sub, Mul, Div, Rem)] +#[wrapper_mut(AddAssign, SubAssign, MulAssign, DivAssign, RemAssign)] +#[derive(StrictType, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB20)] +struct Amount(u64); +impl StrictSerialize for Amount {} +impl StrictDeserialize for Amount {} + +#[derive(Clone, Eq, PartialEq, Hash, Debug, Default)] +#[derive(StrictType, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB20)] +struct Meta { + pub reserves: SmallOrdSet, +} +impl StrictSerialize for Meta {} +impl StrictDeserialize for Meta {} + +fn _rgb20_stl() -> Result { + LibBuilder::new(libname!(LIB_NAME_RGB20)) + .transpile::() + .transpile::() + .compile(bset! { + bitcoin_stl().to_dependency(), + rgb_contract_stl().to_dependency() + }) +} + +/// Generates strict type library providing data types for RGB20 interface. +pub fn rgb20_stl() -> TypeLib { _rgb20_stl().expect("invalid strict type RGB20 library") } pub fn rgb20() -> Iface { - let types = StandardTypes::new(); + let types = StandardTypes::with(rgb20_stl()); Iface { version: VerNo::V1, @@ -78,6 +121,12 @@ mod test { const RGB20: &str = include_str!("../../tests/data/rgb20.asc.rgb"); + #[test] + fn lib_id() { + let lib = rgb20_stl(); + assert_eq!(lib.id().to_string(), LIB_ID_RGB20); + } + #[test] fn iface_creation() { rgb20(); } diff --git a/std/src/stl/stl.rs b/std/src/stl/stl.rs index 493861ad..78eb231c 100644 --- a/std/src/stl/stl.rs +++ b/std/src/stl/stl.rs @@ -30,8 +30,8 @@ use super::{ }; use crate::stl::ProofOfReserves; -/// Strict types id for the library providing data types from [`dbc`] and -/// [`seals`] crates. +/// Strict types id for the library providing standard data types which may be +/// used in RGB smart contracts. pub const LIB_ID_RGB_CONTRACT: &str = "level_decide_percent_6z2gZQEJsnP4xoNUC94vqYEE9V7gKQbeJhb5521xta5u"; @@ -48,8 +48,8 @@ fn _rgb_contract_stl() -> Result { }) } -/// Generates strict type library providing data types from [`dbc`] and -/// [`seals`] crates. +/// Generates strict type library providing standard data types which may be +/// used in RGB smart contracts. pub fn rgb_contract_stl() -> TypeLib { _rgb_contract_stl().expect("invalid strict type RGBContract library") } @@ -59,16 +59,22 @@ pub struct StandardTypes(TypeSystem); impl StandardTypes { pub fn new() -> Self { - fn builder() -> Result { - SystemBuilder::new() - .import(std_stl())? - .import(bitcoin_stl())? - .import(rgb_contract_stl())? - .finalize() - .map_err(Error::from) - } + Self::try_with([std_stl(), bitcoin_stl(), rgb_contract_stl()]) + .expect("error in standard RGBContract type system") + } - Self(builder().expect("error in standard RGBContract type system")) + pub fn with(lib: TypeLib) -> Self { + Self::try_with([std_stl(), bitcoin_stl(), rgb_contract_stl(), lib]) + .expect("error in standard RGBContract type system") + } + + fn try_with(libs: impl IntoIterator) -> Result { + let mut builder = SystemBuilder::new(); + for lib in libs.into_iter() { + builder = builder.import(lib)?; + } + let sys = builder.finalize()?; + Ok(Self(sys)) } pub fn type_system(&self) -> TypeSystem { self.0.clone() } diff --git a/stl/RGB20@0.1.0.sta b/stl/RGB20@0.1.0.sta new file mode 100644 index 00000000..5077df3f --- /dev/null +++ b/stl/RGB20@0.1.0.sta @@ -0,0 +1,15 @@ +-----BEGIN STRICT TYPE LIB----- +Id: escort_chamber_clone_8g3y7GatrZYywXA38YKq1vCWmtrTYSMEBNgPqDy8NBDF +Name: RGB20 +Dependencies: + RGBContract@level_decide_percent_6z2gZQEJsnP4xoNUC94vqYEE9V7gKQbeJhb5521xta5u, + Bitcoin@cubic_filter_vampire_AqBBP1ZeTXrdAePf6SBcUGbttpvxpHKG7uJLKFkVxtGi + +BVJHQjIwAljmcVEaBmUvNnuaNhdNwvUqhXbh6gDg28jkixwjzddoC1JHQkNvbnRy +YWN0khCSD+5t80apbygpkiw4UYjv0hOwwSfKS+1eTBW9YXMHQml0Y29pbgIABkFt +b3VudAUBAAAIBE1ldGEGAQhyZXNlcnZlcwAJAg9Qcm9vZk9mUmVzZXJ2ZXMLUkdC +Q29udHJhY3S6A6JqlDC0xrIg5HDyvbzYYjoMf7g5GsQVjl3ey3a8gAAAAAAAAAAA +//8AAAAAAAA= + +-----END STRICT TYPE LIB----- + diff --git a/stl/RGB20@0.1.0.stl b/stl/RGB20@0.1.0.stl new file mode 100644 index 0000000000000000000000000000000000000000..7f90119206a09f89a976680b2b8301cac9c4c08c GIT binary patch literal 200 zcmZP#a(6N^V2XHF7%0V-s&7_3%S_z&&{wV2vWKr29^5|hq+3S$?DY(8pfczDypp2C ziUACuz0Sf;AhcEzk14|qL literal 0 HcmV?d00001 diff --git a/stl/RGB20@0.1.0.sty b/stl/RGB20@0.1.0.sty new file mode 100644 index 00000000..8c23cb85 --- /dev/null +++ b/stl/RGB20@0.1.0.sty @@ -0,0 +1,19 @@ +{- + Id: escort_chamber_clone_8g3y7GatrZYywXA38YKq1vCWmtrTYSMEBNgPqDy8NBDF + Name: RGB20 + Version: 0.1.0 + Description: Types for RGB20 interface + Author: Dr Maxim Orlovsky + Copyright (C) 2023 LNP/BP Standards Association. All rights reserved. + License: Apache-2.0 +-} + +typelib RGB20 -- escort_chamber_clone_8g3y7GatrZYywXA38YKq1vCWmtrTYSMEBNgPqDy8NBDF + +import level_decide_percent_6z2gZQEJsnP4xoNUC94vqYEE9V7gKQbeJhb5521xta5u as RGBContract +import cubic_filter_vampire_AqBBP1ZeTXrdAePf6SBcUGbttpvxpHKG7uJLKFkVxtGi as Bitcoin + + +data Amount :: U64 +data Meta :: reserves {RGBContract.ProofOfReserves} + From b508af6a53f41a70fff8b89621bd22a34c31974d Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 10:42:20 +0200 Subject: [PATCH 15/33] iface: update RGB20 state types to match the standard --- std/src/interface/rgb20.rs | 25 +++++++++++++++++-------- std/tests/data/rgb20.asc.rgb | 16 +++++++++++----- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/std/src/interface/rgb20.rs b/std/src/interface/rgb20.rs index 2299a69c..b0cb05cd 100644 --- a/std/src/interface/rgb20.rs +++ b/std/src/interface/rgb20.rs @@ -75,23 +75,32 @@ pub fn rgb20() -> Iface { version: VerNo::V1, name: tn!("RGB20"), global_state: tiny_bmap! { - tn!("spec") => Req::require(types.get("RGBContract.DivisibleAssetSpec")), - tn!("ContractText") => Req::require(types.get("RGBContract.RicardianContract")), - + tn!("spec") => GlobalIface::required(types.get("RGBContract.DivisibleAssetSpec")), + tn!("terms") => GlobalIface::required(types.get("RGBContract.RicardianContract")), + tn!("created") => GlobalIface::required(types.get("RGBContract.Timestamp")), + tn!("issuedSupply") => GlobalIface::none_or_many(types.get("RGB20.Amount")), + tn!("burnedSupply") => GlobalIface::none_or_many(types.get("RGB20.Amount")), + tn!("replacedSupply") => GlobalIface::none_or_many(types.get("RGB20.Amount")), }, assignments: tiny_bmap! { - tn!("Assets") => AssignIface::private(OwnedIface::Amount), + tn!("inflationAllowance") => AssignIface::public(OwnedIface::Amount, Req::NoneOrMore), + tn!("updateRight") => AssignIface::public(OwnedIface::Amount, Req::Optional), + tn!("burnRight") => AssignIface::public(OwnedIface::Amount, Req::Optional), tn!("assetOwner") => AssignIface::private(OwnedIface::Amount, Req::NoneOrMore), }, valencies: none!(), genesis: GenesisIface { - metadata: None, + metadata: Some(types.get("RGB20.Meta")), global: tiny_bmap! { - tn!("Nominal") => Occurrences::Once, - tn!("ContractText") => Occurrences::Once, + tn!("spec") => Occurrences::Once, + tn!("terms") => Occurrences::Once, + tn!("issuedSupply") => Occurrences::Once, }, assignments: tiny_bmap! { - tn!("Assets") => Occurrences::OnceOrMore + tn!("assetOwner") => Occurrences::NoneOrMore, + tn!("inflationAllowance") => Occurrences::NoneOrMore, + tn!("updateRight") => Occurrences::NoneOrOnce, + tn!("burnRight") => Occurrences::NoneOrOnce, }, valencies: none!(), }, diff --git a/std/tests/data/rgb20.asc.rgb b/std/tests/data/rgb20.asc.rgb index 2d99bbb6..6ea5ee78 100644 --- a/std/tests/data/rgb20.asc.rgb +++ b/std/tests/data/rgb20.asc.rgb @@ -1,9 +1,15 @@ ----- BEGIN RGB INTERFACE ----- -Id: CHafPGXMya8spywxuJ3Sr9BCJc51ojbEKBqpT4xaEk22 +Id: 69tEWNpN5oVUD7jZkMsb5EMyzg1PAQ96mR24rpWEaJD1 -AAVSR0IyMAIMQ29udHJhY3RUZXh0AbC/tv4Ak69rMjDl/Q09aarxS/CY3wdyjSULrjd5hhBwAQRz -cGVjAXEb91tMkPjmLh7Tn4j0rGsW+l/fNNy+o7N/vJ4En1+oAQEGQXNzZXRzAAIAAAIMQ29udHJh -Y3RUZXh0AQABAAdOb21pbmFsAQABAAEGQXNzZXRzAQD//wABCFRyYW5zZmVyAAABBkFzc2V0cwEA -//8BBkFzc2V0cwEA//8AAQZBc3NldHMAAQhUcmFuc2Zlcg== +AAVSR0IyMAYMYnVybmVkU3VwcGx5AYJ+OfqsC5wwo0fJrMCAaFfa8AJgCgdyhb3HkpdLRUYaAAEH +Y3JlYXRlZAHK0bud73JnqPaARSzjY0/ngU2l+kvpLKccXt8S5qHkMAEADGlzc3VlZFN1cHBseQGC +fjn6rAucMKNHyazAgGhX2vACYAoHcoW9x5KXS0VGGgABDnJlcGxhY2VkU3VwcGx5AYJ+OfqsC5ww +o0fJrMCAaFfa8AJgCgdyhb3HkpdLRUYaAAEEc3BlYwFxG/dbTJD45i4e05+I9KxrFvpf3zTcvqOz +f7yeBJ9fqAEABXRlcm1zAbC/tv4Ak69rMjDl/Q09aarxS/CY3wdyjSULrjd5hhBwAQAECmFzc2V0 +T3duZXICAAABCWJ1cm5SaWdodAIBAAASaW5mbGF0aW9uQWxsb3dhbmNlAgEAAQt1cGRhdGVSaWdo +dAIBAAAAAVOp/1PXvEmPeBI4+UEyxeeg46mO/OeMrQ5xKPnpw7+uAwxpc3N1ZWRTdXBwbHkBAAEA +BHNwZWMBAAEABXRlcm1zAQABAAQKYXNzZXRPd25lcgAA//8JYnVyblJpZ2h0AAABABJpbmZsYXRp +b25BbGxvd2FuY2UAAP//C3VwZGF0ZVJpZ2h0AAABAAABCFRyYW5zZmVyAAABBkFzc2V0cwEA//8B +BkFzc2V0cwEA//8AAQZBc3NldHMAAQhUcmFuc2Zlcg== ----- END RGB INTERFACE ----- From ee622b3babac34264786bd45dc6452b9d7559ca5 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 12:01:07 +0200 Subject: [PATCH 16/33] iface: refactor to use FieldNames where appropriate --- src/invoice.rs | 4 +-- src/pay.rs | 2 +- std/src/interface/builder.rs | 42 ++++++++++++++----------- std/src/interface/contract.rs | 14 ++++----- std/src/interface/iface.rs | 14 ++++----- std/src/interface/iimpl.rs | 58 ++++++++++++++++++++++++++--------- std/src/interface/mod.rs | 2 +- std/src/interface/rgb20.rs | 40 ++++++++++++------------ std/tests/data/rgb20.asc.rgb | 6 ++-- 9 files changed, 108 insertions(+), 74 deletions(-) diff --git a/src/invoice.rs b/src/invoice.rs index a1124532..70bf0dd0 100644 --- a/src/invoice.rs +++ b/src/invoice.rs @@ -31,7 +31,7 @@ use indexmap::IndexMap; use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS}; use rgb::{AttachId, ContractId, SecretSeal}; use rgbstd::interface::TypedState; -use strict_encoding::{InvalidIdent, TypeName}; +use strict_encoding::{FieldName, InvalidIdent, TypeName}; const OMITTED: char = '~'; const EXPIRY: &str = "expiry"; @@ -137,7 +137,7 @@ pub struct RgbInvoice { pub contract: Option, pub iface: Option, pub operation: Option, - pub assignment: Option, + pub assignment: Option, pub beneficiary: Beneficiary, pub owned_state: TypedState, pub chain: Option, diff --git a/src/pay.rs b/src/pay.rs index 78cb6dd7..63c03497 100644 --- a/src/pay.rs +++ b/src/pay.rs @@ -181,7 +181,7 @@ pub trait InventoryWallet: Inventory { .ok_or(BuilderError::NoDefaultAssignment)?; let assignment_id = main_builder .assignments_type(assignment_name) - .ok_or(BuilderError::InvalidStateType(assignment_name.clone()))?; + .ok_or(BuilderError::InvalidStateField(assignment_name.clone()))?; // TODO: select supplement basing on the signer trust level let suppl = self .contract_suppl(contract_id) diff --git a/std/src/interface/builder.rs b/std/src/interface/builder.rs index 769ad257..a62529d3 100644 --- a/std/src/interface/builder.rs +++ b/std/src/interface/builder.rs @@ -30,7 +30,7 @@ use rgb::{ GenesisSeal, GlobalState, GraphSeal, Input, Inputs, Opout, RevealedValue, StateSchema, SubSchema, Transition, TransitionType, TypedAssigns, BLANK_TRANSITION_ID, }; -use strict_encoding::{SerializeError, StrictSerialize, TypeName}; +use strict_encoding::{FieldName, SerializeError, StrictSerialize, TypeName}; use strict_types::decode; use crate::containers::{BuilderSeal, Contract}; @@ -47,11 +47,17 @@ pub enum BuilderError { /// provided to the forge. SchemaMismatch, - /// type `{0}` is not known to the schema. - TypeNotFound(TypeName), + /// Global state `{0}` is not known to the schema. + GlobalNotFound(FieldName), - /// state `{0}` provided to the builder has invalid type - InvalidStateType(TypeName), + /// Assignment `{0}` is not known to the schema. + AssignmentNotFound(FieldName), + + /// transition `{0}` is not known to the schema. + TransitionNotFound(TypeName), + + /// state `{0}` provided to the builder has invalid name + InvalidStateField(FieldName), /// interface doesn't specifies default operation name, thus an explicit /// operation type must be provided with `set_operation_type` method. @@ -94,7 +100,7 @@ impl ContractBuilder { pub fn add_global_state( mut self, - name: impl Into, + name: impl Into, value: impl StrictSerialize, ) -> Result { self.builder = self.builder.add_global_state(name, value)?; @@ -103,7 +109,7 @@ impl ContractBuilder { pub fn add_fungible_state( mut self, - name: impl Into, + name: impl Into, seal: impl Into, value: u64, ) -> Result { @@ -151,7 +157,7 @@ impl TransitionBuilder { }) } - pub fn assignments_type(&self, name: &TypeName) -> Option { + pub fn assignments_type(&self, name: &FieldName) -> Option { self.builder.iimpl.assignments_type(name) } @@ -171,12 +177,12 @@ impl TransitionBuilder { .builder .iimpl .transition_type(&name) - .ok_or(BuilderError::TypeNotFound(name))?; + .ok_or(BuilderError::TransitionNotFound(name))?; self.transition_type = Some(transition_type); Ok(self) } - pub fn default_assignment(&self) -> Result<&TypeName, BuilderError> { + pub fn default_assignment(&self) -> Result<&FieldName, BuilderError> { let transition_type = self.transition_type()?; let transition_name = self .builder @@ -197,7 +203,7 @@ impl TransitionBuilder { pub fn add_global_state( mut self, - name: impl Into, + name: impl Into, value: impl StrictSerialize, ) -> Result { self.builder = self.builder.add_global_state(name, value)?; @@ -214,14 +220,14 @@ impl TransitionBuilder { .builder .iimpl .assignments_type(assignment_name) - .ok_or(BuilderError::InvalidStateType(assignment_name.clone()))?; + .ok_or(BuilderError::InvalidStateField(assignment_name.clone()))?; self.add_raw_state(id, seal, TypedState::Amount(value)) } pub fn add_fungible_state( mut self, - name: impl Into, + name: impl Into, seal: impl Into>, value: u64, ) -> Result { @@ -314,7 +320,7 @@ impl OperationBuilder { pub fn add_global_state( mut self, - name: impl Into, + name: impl Into, value: impl StrictSerialize, ) -> Result { let name = name.into(); @@ -322,7 +328,7 @@ impl OperationBuilder { // Check value matches type requirements let Some(type_id) = self.iimpl.global_state.iter().find(|t| t.name == name).map(|t| t.id) else { - return Err(BuilderError::TypeNotFound(name)); + return Err(BuilderError::GlobalNotFound(name)); }; let sem_id = self .schema @@ -341,14 +347,14 @@ impl OperationBuilder { pub fn add_fungible_state( mut self, - name: impl Into, + name: impl Into, seal: impl Into>, value: u64, ) -> Result { let name = name.into(); let Some(type_id) = self.iimpl.assignments.iter().find(|t| t.name == name).map(|t| t.id) else { - return Err(BuilderError::TypeNotFound(name)); + return Err(BuilderError::AssignmentNotFound(name)); }; let state_schema = self @@ -357,7 +363,7 @@ impl OperationBuilder { .get(&type_id) .expect("schema should match interface: must be checked by the constructor"); if *state_schema != StateSchema::Fungible(FungibleType::Unsigned64Bit) { - return Err(BuilderError::InvalidStateType(name)); + return Err(BuilderError::InvalidStateField(name)); } let state = RevealedValue::new(value, &mut thread_rng()); diff --git a/std/src/interface/contract.rs b/std/src/interface/contract.rs index bc7022de..74671911 100644 --- a/std/src/interface/contract.rs +++ b/std/src/interface/contract.rs @@ -25,7 +25,7 @@ use rgb::{ AssignmentType, AttachId, ContractState, FungibleOutput, MediaType, RevealedAttach, RevealedData, SealWitness, }; -use strict_encoding::TypeName; +use strict_encoding::FieldName; use strict_types::typify::TypedVal; use strict_types::{decode, StrictVal}; @@ -35,8 +35,8 @@ use crate::LIB_NAME_RGB_STD; #[derive(Clone, Eq, PartialEq, Debug, Display, Error, From)] #[display(doc_comments)] pub enum ContractError { - /// type name {0} is unknown to the contract interface - TypeNameUnknown(TypeName), + /// field name {0} is unknown to the contract interface + FieldNameUnknown(FieldName), #[from] #[display(inner)] @@ -113,13 +113,13 @@ impl ContractIface { /// /// If data are corrupted and contract schema doesn't match interface /// implementations. - pub fn global(&self, name: impl Into) -> Result, ContractError> { + pub fn global(&self, name: impl Into) -> Result, ContractError> { let name = name.into(); let type_system = &self.state.schema.type_system; let type_id = self .iface .global_type(&name) - .ok_or(ContractError::TypeNameUnknown(name))?; + .ok_or(ContractError::FieldNameUnknown(name))?; let type_schema = self .state .schema @@ -141,13 +141,13 @@ impl ContractIface { pub fn fungible( &self, - name: impl Into, + name: impl Into, ) -> Result, ContractError> { let name = name.into(); let type_id = self .iface .assignments_type(&name) - .ok_or(ContractError::TypeNameUnknown(name))?; + .ok_or(ContractError::FieldNameUnknown(name))?; let state = self .state .fungibles() diff --git a/std/src/interface/iface.rs b/std/src/interface/iface.rs index 77e2b646..12246cbf 100644 --- a/std/src/interface/iface.rs +++ b/std/src/interface/iface.rs @@ -28,8 +28,8 @@ use baid58::{Baid58ParseError, FromBaid58, ToBaid58}; use commit_verify::{CommitStrategy, CommitmentId}; use rgb::Occurrences; use strict_encoding::{ - StrictDecode, StrictDeserialize, StrictDumb, StrictEncode, StrictSerialize, StrictType, - TypeName, + FieldName, StrictDecode, StrictDeserialize, StrictDumb, StrictEncode, StrictSerialize, + StrictType, TypeName, }; use strict_types::SemId; @@ -201,7 +201,7 @@ pub enum OwnedIface { Data(SemId), } -pub type TypeReqMap = TinyOrdMap; +pub type TypeReqMap = TinyOrdMap; #[derive(Clone, PartialEq, Eq, Debug)] #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] @@ -248,7 +248,7 @@ pub struct TransitionIface { pub inputs: TypeReqMap, pub assignments: TypeReqMap, pub valencies: TypeReqMap, - pub default_assignment: Option, + pub default_assignment: Option, } /// Interface definition. @@ -263,9 +263,9 @@ pub struct TransitionIface { pub struct Iface { pub version: VerNo, pub name: TypeName, - pub global_state: TinyOrdMap, - pub assignments: TinyOrdMap, - pub valencies: TinyOrdMap, + pub global_state: TinyOrdMap, + pub assignments: TinyOrdMap, + pub valencies: TinyOrdMap, pub genesis: GenesisIface, pub transitions: TinyOrdMap, pub extensions: TinyOrdMap, diff --git a/std/src/interface/iimpl.rs b/std/src/interface/iimpl.rs index 353f3a90..e1f734b7 100644 --- a/std/src/interface/iimpl.rs +++ b/std/src/interface/iimpl.rs @@ -29,8 +29,9 @@ use rgb::{ AssignmentType, ExtensionType, GlobalStateType, SchemaId, SchemaTypeIndex, SubSchema, TransitionType, ValencyType, }; +use strict_encoding::{FieldName, TypeName}; use strict_types::encoding::{ - StrictDecode, StrictDeserialize, StrictEncode, StrictSerialize, StrictType, TypeName, + StrictDecode, StrictDeserialize, StrictEncode, StrictSerialize, StrictType, }; use crate::interface::iface::IfaceId; @@ -71,11 +72,38 @@ impl FromStr for ImplId { fn from_str(s: &str) -> Result { Self::from_baid58_str(s) } } -/// Maps certain form of type id (global or owned state or a specific operation -/// type) to a human-readable name. +/// Maps certain form of type id (global or owned state or a valency) to a +/// human-readable name. /// -/// Two distinct [`NamedType`] objects must always have both different state ids -/// and names. +/// Two distinct [`NamedField`] objects must always have both different state +/// ids and names. +#[derive(Clone, Eq, PartialOrd, Ord, Debug)] +#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB_STD)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", rename_all = "camelCase") +)] +pub struct NamedField { + pub id: T, + pub name: FieldName, +} + +impl PartialEq for NamedField +where T: SchemaTypeIndex +{ + fn eq(&self, other: &Self) -> bool { self.id == other.id || self.name == other.name } +} + +impl NamedField { + pub fn with(id: T, name: FieldName) -> NamedField { NamedField { id, name } } +} + +/// Maps operation numeric type id to a human-readable name. +/// +/// Two distinct [`NamedType`] objects must always have both different state +/// ids and names. #[derive(Clone, Eq, PartialOrd, Ord, Debug)] #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB_STD)] @@ -129,11 +157,11 @@ pub struct IfaceImpl { pub version: VerNo, pub schema_id: SchemaId, pub iface_id: IfaceId, - pub global_state: TinyOrdSet>, - pub assignments: TinyOrdSet>, - pub valencies: TinyOrdSet>, + pub global_state: TinyOrdSet>, + pub assignments: TinyOrdSet>, + pub valencies: TinyOrdSet>, pub transitions: TinyOrdSet>, - pub extensions: TinyOrdSet>, + pub extensions: TinyOrdSet>, } impl CommitStrategy for IfaceImpl { @@ -152,14 +180,14 @@ impl IfaceImpl { #[inline] pub fn impl_id(&self) -> ImplId { self.commitment_id() } - pub fn global_type(&self, name: &TypeName) -> Option { + pub fn global_type(&self, name: &FieldName) -> Option { self.global_state .iter() .find(|nt| &nt.name == name) .map(|nt| nt.id) } - pub fn assignments_type(&self, name: &TypeName) -> Option { + pub fn assignments_type(&self, name: &FieldName) -> Option { self.assignments .iter() .find(|nt| &nt.name == name) @@ -173,14 +201,14 @@ impl IfaceImpl { .map(|nt| nt.id) } - pub fn global_name(&self, id: GlobalStateType) -> Option<&TypeName> { + pub fn global_name(&self, id: GlobalStateType) -> Option<&FieldName> { self.global_state .iter() .find(|nt| nt.id == id) .map(|nt| &nt.name) } - pub fn assignment_name(&self, id: AssignmentType) -> Option<&TypeName> { + pub fn assignment_name(&self, id: AssignmentType) -> Option<&FieldName> { self.assignments .iter() .find(|nt| nt.id == id) @@ -215,10 +243,10 @@ impl IfacePair { pub fn iface_id(&self) -> IfaceId { self.iface.iface_id() } pub fn impl_id(&self) -> ImplId { self.iimpl.impl_id() } - pub fn global_type(&self, name: &TypeName) -> Option { + pub fn global_type(&self, name: &FieldName) -> Option { self.iimpl.global_type(name) } - pub fn assignments_type(&self, name: &TypeName) -> Option { + pub fn assignments_type(&self, name: &FieldName) -> Option { self.iimpl.assignments_type(name) } pub fn transition_type(&self, name: &TypeName) -> Option { diff --git a/std/src/interface/mod.rs b/std/src/interface/mod.rs index 41998459..9918fff8 100644 --- a/std/src/interface/mod.rs +++ b/std/src/interface/mod.rs @@ -36,7 +36,7 @@ pub use iface::{ AssignIface, ExtensionIface, GenesisIface, GlobalIface, Iface, IfaceId, OwnedIface, Req, TransitionIface, TypeReqMap, ValencyIface, }; -pub use iimpl::{IfaceImpl, IfacePair, ImplId, NamedType, SchemaIfaces}; +pub use iimpl::{IfaceImpl, IfacePair, ImplId, NamedField, NamedType, SchemaIfaces}; pub use rgb20::{rgb20, rgb20_stl, LIB_ID_RGB20, LIB_NAME_RGB20}; pub use suppl::{AppDeriveIndex, ContractSuppl, OwnedStateSuppl, SupplId, TickerSuppl}; diff --git a/std/src/interface/rgb20.rs b/std/src/interface/rgb20.rs index b0cb05cd..d108de02 100644 --- a/std/src/interface/rgb20.rs +++ b/std/src/interface/rgb20.rs @@ -75,32 +75,32 @@ pub fn rgb20() -> Iface { version: VerNo::V1, name: tn!("RGB20"), global_state: tiny_bmap! { - tn!("spec") => GlobalIface::required(types.get("RGBContract.DivisibleAssetSpec")), - tn!("terms") => GlobalIface::required(types.get("RGBContract.RicardianContract")), - tn!("created") => GlobalIface::required(types.get("RGBContract.Timestamp")), - tn!("issuedSupply") => GlobalIface::none_or_many(types.get("RGB20.Amount")), - tn!("burnedSupply") => GlobalIface::none_or_many(types.get("RGB20.Amount")), - tn!("replacedSupply") => GlobalIface::none_or_many(types.get("RGB20.Amount")), + fname!("spec") => GlobalIface::required(types.get("RGBContract.DivisibleAssetSpec")), + fname!("terms") => GlobalIface::required(types.get("RGBContract.RicardianContract")), + fname!("created") => GlobalIface::required(types.get("RGBContract.Timestamp")), + fname!("issuedSupply") => GlobalIface::none_or_many(types.get("RGB20.Amount")), + fname!("burnedSupply") => GlobalIface::none_or_many(types.get("RGB20.Amount")), + fname!("replacedSupply") => GlobalIface::none_or_many(types.get("RGB20.Amount")), }, assignments: tiny_bmap! { - tn!("inflationAllowance") => AssignIface::public(OwnedIface::Amount, Req::NoneOrMore), - tn!("updateRight") => AssignIface::public(OwnedIface::Amount, Req::Optional), - tn!("burnRight") => AssignIface::public(OwnedIface::Amount, Req::Optional), - tn!("assetOwner") => AssignIface::private(OwnedIface::Amount, Req::NoneOrMore), + fname!("inflationAllowance") => AssignIface::public(OwnedIface::Amount, Req::NoneOrMore), + fname!("updateRight") => AssignIface::public(OwnedIface::Amount, Req::Optional), + fname!("burnRight") => AssignIface::public(OwnedIface::Amount, Req::Optional), + fname!("assetOwner") => AssignIface::private(OwnedIface::Amount, Req::NoneOrMore), }, valencies: none!(), genesis: GenesisIface { metadata: Some(types.get("RGB20.Meta")), global: tiny_bmap! { - tn!("spec") => Occurrences::Once, - tn!("terms") => Occurrences::Once, - tn!("issuedSupply") => Occurrences::Once, + fname!("spec") => Occurrences::Once, + fname!("terms") => Occurrences::Once, + fname!("issuedSupply") => Occurrences::Once, }, assignments: tiny_bmap! { - tn!("assetOwner") => Occurrences::NoneOrMore, - tn!("inflationAllowance") => Occurrences::NoneOrMore, - tn!("updateRight") => Occurrences::NoneOrOnce, - tn!("burnRight") => Occurrences::NoneOrOnce, + fname!("assetOwner") => Occurrences::NoneOrMore, + fname!("inflationAllowance") => Occurrences::NoneOrMore, + fname!("updateRight") => Occurrences::NoneOrOnce, + fname!("burnRight") => Occurrences::NoneOrOnce, }, valencies: none!(), }, @@ -109,13 +109,13 @@ pub fn rgb20() -> Iface { metadata: None, globals: none!(), inputs: tiny_bmap! { - tn!("Assets") => Occurrences::OnceOrMore, + fname!("assetOwner") => Occurrences::OnceOrMore, }, assignments: tiny_bmap! { - tn!("Assets") => Occurrences::OnceOrMore, + fname!("assetOwner") => Occurrences::OnceOrMore, }, valencies: none!(), - default_assignment: Some(tn!("Assets")), + default_assignment: Some(fname!("assetOwner")), } }, extensions: none!(), diff --git a/std/tests/data/rgb20.asc.rgb b/std/tests/data/rgb20.asc.rgb index 6ea5ee78..1680a6a1 100644 --- a/std/tests/data/rgb20.asc.rgb +++ b/std/tests/data/rgb20.asc.rgb @@ -1,5 +1,5 @@ ----- BEGIN RGB INTERFACE ----- -Id: 69tEWNpN5oVUD7jZkMsb5EMyzg1PAQ96mR24rpWEaJD1 +Id: FFyTM1BkKKXQjWUcP6XrkuHvUZAYueF5PjwStoJC9M5h AAVSR0IyMAYMYnVybmVkU3VwcGx5AYJ+OfqsC5wwo0fJrMCAaFfa8AJgCgdyhb3HkpdLRUYaAAEH Y3JlYXRlZAHK0bud73JnqPaARSzjY0/ngU2l+kvpLKccXt8S5qHkMAEADGlzc3VlZFN1cHBseQGC @@ -9,7 +9,7 @@ f7yeBJ9fqAEABXRlcm1zAbC/tv4Ak69rMjDl/Q09aarxS/CY3wdyjSULrjd5hhBwAQAECmFzc2V0 T3duZXICAAABCWJ1cm5SaWdodAIBAAASaW5mbGF0aW9uQWxsb3dhbmNlAgEAAQt1cGRhdGVSaWdo dAIBAAAAAVOp/1PXvEmPeBI4+UEyxeeg46mO/OeMrQ5xKPnpw7+uAwxpc3N1ZWRTdXBwbHkBAAEA BHNwZWMBAAEABXRlcm1zAQABAAQKYXNzZXRPd25lcgAA//8JYnVyblJpZ2h0AAABABJpbmZsYXRp -b25BbGxvd2FuY2UAAP//C3VwZGF0ZVJpZ2h0AAABAAABCFRyYW5zZmVyAAABBkFzc2V0cwEA//8B -BkFzc2V0cwEA//8AAQZBc3NldHMAAQhUcmFuc2Zlcg== +b25BbGxvd2FuY2UAAP//C3VwZGF0ZVJpZ2h0AAABAAABCFRyYW5zZmVyAAABCmFzc2V0T3duZXIB +AP//AQphc3NldE93bmVyAQD//wABCmFzc2V0T3duZXIAAQhUcmFuc2Zlcg== ----- END RGB INTERFACE ----- From 22dbf3d51f6e7e39fa05439e5f7088e1409ea995 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 12:06:48 +0200 Subject: [PATCH 17/33] iface: add ArgSpec allowing operation argument aliases --- std/src/interface/iface.rs | 74 ++++++++++++++++---- std/src/interface/mod.rs | 4 +- std/src/interface/rgb20.rs | 22 +++--- std/tests/data/{rgb20.asc.rgb => rgb20.rgba} | 11 +-- 4 files changed, 81 insertions(+), 30 deletions(-) rename std/tests/data/{rgb20.asc.rgb => rgb20.rgba} (64%) diff --git a/std/src/interface/iface.rs b/std/src/interface/iface.rs index 12246cbf..de4cc6a1 100644 --- a/std/src/interface/iface.rs +++ b/std/src/interface/iface.rs @@ -201,7 +201,57 @@ pub enum OwnedIface { Data(SemId), } -pub type TypeReqMap = TinyOrdMap; +pub type ArgMap = TinyOrdMap; + +/// Structure providing information about state inputs and outputs for an RGB +/// operation. +#[derive(Clone, PartialEq, Eq, Debug, Default)] +#[derive(StrictType, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB_STD)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", rename_all = "camelCase") +)] +pub struct ArgSpec { + /// The name of the state field from the owned or global state fields + /// defined in the interface. Used only if this name is different from the + /// alias provided as [`ArgMap`] key. + pub name: Option, + /// Maximal number of occurrences of the input or output of this type. + pub req: Occurrences, +} + +impl ArgSpec { + pub fn new(req: Occurrences) -> Self { ArgSpec { name: None, req } } + + pub fn required() -> Self { ArgSpec::new(Occurrences::Once) } + + pub fn optional() -> Self { ArgSpec::new(Occurrences::NoneOrOnce) } + + pub fn non_empty() -> Self { ArgSpec::new(Occurrences::OnceOrMore) } + + pub fn many() -> Self { ArgSpec::new(Occurrences::NoneOrMore) } + + pub fn with(name: &'static str, req: Occurrences) -> Self { + ArgSpec { + name: Some(FieldName::from(name)), + req, + } + } + + pub fn from_required(name: &'static str) -> Self { ArgSpec::with(name, Occurrences::Once) } + + pub fn from_optional(name: &'static str) -> Self { + ArgSpec::with(name, Occurrences::NoneOrOnce) + } + + pub fn from_non_empty(name: &'static str) -> Self { + ArgSpec::with(name, Occurrences::OnceOrMore) + } + + pub fn from_many(name: &'static str) -> Self { ArgSpec::with(name, Occurrences::NoneOrMore) } +} #[derive(Clone, PartialEq, Eq, Debug)] #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] @@ -213,9 +263,9 @@ pub type TypeReqMap = TinyOrdMap; )] pub struct GenesisIface { pub metadata: Option, - pub global: TypeReqMap, - pub assignments: TypeReqMap, - pub valencies: TypeReqMap, + pub global: ArgMap, + pub assignments: ArgMap, + pub valencies: ArgMap, } #[derive(Clone, PartialEq, Eq, Debug)] @@ -228,10 +278,10 @@ pub struct GenesisIface { )] pub struct ExtensionIface { pub metadata: Option, - pub globals: TypeReqMap, - pub redeems: TypeReqMap, - pub assignments: TypeReqMap, - pub valencies: TypeReqMap, + pub globals: ArgMap, + pub redeems: ArgMap, + pub assignments: ArgMap, + pub valencies: ArgMap, } #[derive(Clone, PartialEq, Eq, Debug)] @@ -244,10 +294,10 @@ pub struct ExtensionIface { )] pub struct TransitionIface { pub metadata: Option, - pub globals: TypeReqMap, - pub inputs: TypeReqMap, - pub assignments: TypeReqMap, - pub valencies: TypeReqMap, + pub globals: ArgMap, + pub inputs: ArgMap, + pub assignments: ArgMap, + pub valencies: ArgMap, pub default_assignment: Option, } diff --git a/std/src/interface/mod.rs b/std/src/interface/mod.rs index 9918fff8..2b9e9cfc 100644 --- a/std/src/interface/mod.rs +++ b/std/src/interface/mod.rs @@ -33,8 +33,8 @@ mod suppl; pub use builder::{BuilderError, ContractBuilder, OperationBuilder, TransitionBuilder}; pub use contract::{ContractIface, FungibleAllocation, TypedState}; pub use iface::{ - AssignIface, ExtensionIface, GenesisIface, GlobalIface, Iface, IfaceId, OwnedIface, Req, - TransitionIface, TypeReqMap, ValencyIface, + ArgMap, ArgSpec, AssignIface, ExtensionIface, GenesisIface, GlobalIface, Iface, IfaceId, + OwnedIface, Req, TransitionIface, ValencyIface, }; pub use iimpl::{IfaceImpl, IfacePair, ImplId, NamedField, NamedType, SchemaIfaces}; pub use rgb20::{rgb20, rgb20_stl, LIB_ID_RGB20, LIB_NAME_RGB20}; diff --git a/std/src/interface/rgb20.rs b/std/src/interface/rgb20.rs index d108de02..c389ace9 100644 --- a/std/src/interface/rgb20.rs +++ b/std/src/interface/rgb20.rs @@ -21,7 +21,6 @@ use amplify::confinement::SmallOrdSet; use bp::bc::stl::bitcoin_stl; -use rgb::Occurrences; use strict_encoding::{StrictDeserialize, StrictSerialize}; use strict_types::typelib::{LibBuilder, TranslateError}; use strict_types::TypeLib; @@ -29,6 +28,7 @@ use strict_types::TypeLib; use super::{ AssignIface, GenesisIface, GlobalIface, Iface, OwnedIface, Req, TransitionIface, VerNo, }; +use crate::interface::ArgSpec; use crate::stl::{rgb_contract_stl, ProofOfReserves, StandardTypes}; pub const LIB_NAME_RGB20: &str = "RGB20"; @@ -92,15 +92,15 @@ pub fn rgb20() -> Iface { genesis: GenesisIface { metadata: Some(types.get("RGB20.Meta")), global: tiny_bmap! { - fname!("spec") => Occurrences::Once, - fname!("terms") => Occurrences::Once, - fname!("issuedSupply") => Occurrences::Once, + fname!("spec") => ArgSpec::required(), + fname!("terms") => ArgSpec::required(), + fname!("issuedSupply") => ArgSpec::required(), }, assignments: tiny_bmap! { - fname!("assetOwner") => Occurrences::NoneOrMore, - fname!("inflationAllowance") => Occurrences::NoneOrMore, - fname!("updateRight") => Occurrences::NoneOrOnce, - fname!("burnRight") => Occurrences::NoneOrOnce, + fname!("assetOwner") => ArgSpec::many(), + fname!("inflationAllowance") => ArgSpec::many(), + fname!("updateRight") => ArgSpec::optional(), + fname!("burnRight") => ArgSpec::optional(), }, valencies: none!(), }, @@ -109,10 +109,10 @@ pub fn rgb20() -> Iface { metadata: None, globals: none!(), inputs: tiny_bmap! { - fname!("assetOwner") => Occurrences::OnceOrMore, + fname!("previous") => ArgSpec::from_non_empty("assetOwner"), }, assignments: tiny_bmap! { - fname!("assetOwner") => Occurrences::OnceOrMore, + fname!("beneficiary") => ArgSpec::from_non_empty("assetOwner"), }, valencies: none!(), default_assignment: Some(fname!("assetOwner")), @@ -128,7 +128,7 @@ mod test { use super::*; use crate::containers::BindleContent; - const RGB20: &str = include_str!("../../tests/data/rgb20.asc.rgb"); + const RGB20: &str = include_str!("../../tests/data/rgb20.rgba"); #[test] fn lib_id() { diff --git a/std/tests/data/rgb20.asc.rgb b/std/tests/data/rgb20.rgba similarity index 64% rename from std/tests/data/rgb20.asc.rgb rename to std/tests/data/rgb20.rgba index 1680a6a1..26233174 100644 --- a/std/tests/data/rgb20.asc.rgb +++ b/std/tests/data/rgb20.rgba @@ -1,5 +1,5 @@ ----- BEGIN RGB INTERFACE ----- -Id: FFyTM1BkKKXQjWUcP6XrkuHvUZAYueF5PjwStoJC9M5h +Id: EWEq9idvZxa83NAPa24mWRtCJzRG5w9LD78pTuriimbf AAVSR0IyMAYMYnVybmVkU3VwcGx5AYJ+OfqsC5wwo0fJrMCAaFfa8AJgCgdyhb3HkpdLRUYaAAEH Y3JlYXRlZAHK0bud73JnqPaARSzjY0/ngU2l+kvpLKccXt8S5qHkMAEADGlzc3VlZFN1cHBseQGC @@ -7,9 +7,10 @@ fjn6rAucMKNHyazAgGhX2vACYAoHcoW9x5KXS0VGGgABDnJlcGxhY2VkU3VwcGx5AYJ+OfqsC5ww o0fJrMCAaFfa8AJgCgdyhb3HkpdLRUYaAAEEc3BlYwFxG/dbTJD45i4e05+I9KxrFvpf3zTcvqOz f7yeBJ9fqAEABXRlcm1zAbC/tv4Ak69rMjDl/Q09aarxS/CY3wdyjSULrjd5hhBwAQAECmFzc2V0 T3duZXICAAABCWJ1cm5SaWdodAIBAAASaW5mbGF0aW9uQWxsb3dhbmNlAgEAAQt1cGRhdGVSaWdo -dAIBAAAAAVOp/1PXvEmPeBI4+UEyxeeg46mO/OeMrQ5xKPnpw7+uAwxpc3N1ZWRTdXBwbHkBAAEA -BHNwZWMBAAEABXRlcm1zAQABAAQKYXNzZXRPd25lcgAA//8JYnVyblJpZ2h0AAABABJpbmZsYXRp -b25BbGxvd2FuY2UAAP//C3VwZGF0ZVJpZ2h0AAABAAABCFRyYW5zZmVyAAABCmFzc2V0T3duZXIB -AP//AQphc3NldE93bmVyAQD//wABCmFzc2V0T3duZXIAAQhUcmFuc2Zlcg== +dAIBAAAAAVOp/1PXvEmPeBI4+UEyxeeg46mO/OeMrQ5xKPnpw7+uAwxpc3N1ZWRTdXBwbHkAAQAB +AARzcGVjAAEAAQAFdGVybXMAAQABAAQKYXNzZXRPd25lcgAAAP//CWJ1cm5SaWdodAAAAAEAEmlu +ZmxhdGlvbkFsbG93YW5jZQAAAP//C3VwZGF0ZVJpZ2h0AAAAAQAAAQhUcmFuc2ZlcgAAAQhwcmV2 +aW91cwEKYXNzZXRPd25lcgEA//8BC2JlbmVmaWNpYXJ5AQphc3NldE93bmVyAQD//wABCmFzc2V0 +T3duZXIAAQhUcmFuc2Zlcg== ----- END RGB INTERFACE ----- From 809a379e915b57533219ec1e8a690d4cf644f1ea Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 12:08:57 +0200 Subject: [PATCH 18/33] iface: add ability to specify optional operations --- std/src/interface/iface.rs | 2 ++ std/src/interface/rgb20.rs | 1 + std/tests/data/rgb20.rgba | 8 ++++---- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/std/src/interface/iface.rs b/std/src/interface/iface.rs index de4cc6a1..b40045e3 100644 --- a/std/src/interface/iface.rs +++ b/std/src/interface/iface.rs @@ -293,6 +293,8 @@ pub struct ExtensionIface { serde(crate = "serde_crate", rename_all = "camelCase") )] pub struct TransitionIface { + /// Defines whence schema may omit providing this operation. + pub optional: bool, pub metadata: Option, pub globals: ArgMap, pub inputs: ArgMap, diff --git a/std/src/interface/rgb20.rs b/std/src/interface/rgb20.rs index c389ace9..8b0b0a57 100644 --- a/std/src/interface/rgb20.rs +++ b/std/src/interface/rgb20.rs @@ -106,6 +106,7 @@ pub fn rgb20() -> Iface { }, transitions: tiny_bmap! { tn!("Transfer") => TransitionIface { + optional: false, metadata: None, globals: none!(), inputs: tiny_bmap! { diff --git a/std/tests/data/rgb20.rgba b/std/tests/data/rgb20.rgba index 26233174..cfdc50f8 100644 --- a/std/tests/data/rgb20.rgba +++ b/std/tests/data/rgb20.rgba @@ -1,5 +1,5 @@ ----- BEGIN RGB INTERFACE ----- -Id: EWEq9idvZxa83NAPa24mWRtCJzRG5w9LD78pTuriimbf +Id: WAukdU6P7gzJgpoBiuruCjqqr7uWUTo1xpBSMN1pi7B AAVSR0IyMAYMYnVybmVkU3VwcGx5AYJ+OfqsC5wwo0fJrMCAaFfa8AJgCgdyhb3HkpdLRUYaAAEH Y3JlYXRlZAHK0bud73JnqPaARSzjY0/ngU2l+kvpLKccXt8S5qHkMAEADGlzc3VlZFN1cHBseQGC @@ -9,8 +9,8 @@ f7yeBJ9fqAEABXRlcm1zAbC/tv4Ak69rMjDl/Q09aarxS/CY3wdyjSULrjd5hhBwAQAECmFzc2V0 T3duZXICAAABCWJ1cm5SaWdodAIBAAASaW5mbGF0aW9uQWxsb3dhbmNlAgEAAQt1cGRhdGVSaWdo dAIBAAAAAVOp/1PXvEmPeBI4+UEyxeeg46mO/OeMrQ5xKPnpw7+uAwxpc3N1ZWRTdXBwbHkAAQAB AARzcGVjAAEAAQAFdGVybXMAAQABAAQKYXNzZXRPd25lcgAAAP//CWJ1cm5SaWdodAAAAAEAEmlu -ZmxhdGlvbkFsbG93YW5jZQAAAP//C3VwZGF0ZVJpZ2h0AAAAAQAAAQhUcmFuc2ZlcgAAAQhwcmV2 -aW91cwEKYXNzZXRPd25lcgEA//8BC2JlbmVmaWNpYXJ5AQphc3NldE93bmVyAQD//wABCmFzc2V0 -T3duZXIAAQhUcmFuc2Zlcg== +ZmxhdGlvbkFsbG93YW5jZQAAAP//C3VwZGF0ZVJpZ2h0AAAAAQAAAQhUcmFuc2ZlcgAAAAEIcHJl +dmlvdXMBCmFzc2V0T3duZXIBAP//AQtiZW5lZmljaWFyeQEKYXNzZXRPd25lcgEA//8AAQphc3Nl +dE93bmVyAAEIVHJhbnNmZXI= ----- END RGB INTERFACE ----- From d3ec445ae52a94dcc58def6e9e122f8d1c97827c Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 12:25:32 +0200 Subject: [PATCH 19/33] iface: add error information --- std/src/interface/iface.rs | 6 +++++- std/src/interface/rgb20.rs | 33 ++++++++++++++++++++++++++++++++- std/tests/data/rgb20.rgba | 9 +++++---- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/std/src/interface/iface.rs b/std/src/interface/iface.rs index b40045e3..04daf74e 100644 --- a/std/src/interface/iface.rs +++ b/std/src/interface/iface.rs @@ -22,7 +22,7 @@ use std::cmp::Ordering; use std::str::FromStr; -use amplify::confinement::TinyOrdMap; +use amplify::confinement::{SmallOrdSet, TinyOrdMap}; use amplify::{Bytes32, RawArray}; use baid58::{Baid58ParseError, FromBaid58, ToBaid58}; use commit_verify::{CommitStrategy, CommitmentId}; @@ -266,6 +266,7 @@ pub struct GenesisIface { pub global: ArgMap, pub assignments: ArgMap, pub valencies: ArgMap, + pub errors: SmallOrdSet, } #[derive(Clone, PartialEq, Eq, Debug)] @@ -282,6 +283,7 @@ pub struct ExtensionIface { pub redeems: ArgMap, pub assignments: ArgMap, pub valencies: ArgMap, + pub errors: SmallOrdSet, } #[derive(Clone, PartialEq, Eq, Debug)] @@ -300,6 +302,7 @@ pub struct TransitionIface { pub inputs: ArgMap, pub assignments: ArgMap, pub valencies: ArgMap, + pub errors: SmallOrdSet, pub default_assignment: Option, } @@ -321,6 +324,7 @@ pub struct Iface { pub genesis: GenesisIface, pub transitions: TinyOrdMap, pub extensions: TinyOrdMap, + pub error_type: SemId, pub default_operation: Option, } diff --git a/std/src/interface/rgb20.rs b/std/src/interface/rgb20.rs index 8b0b0a57..a4e54f8e 100644 --- a/std/src/interface/rgb20.rs +++ b/std/src/interface/rgb20.rs @@ -33,7 +33,7 @@ use crate::stl::{rgb_contract_stl, ProofOfReserves, StandardTypes}; pub const LIB_NAME_RGB20: &str = "RGB20"; /// Strict types id for the library providing data types for RGB20 interface. -pub const LIB_ID_RGB20: &str = "escort_chamber_clone_8g3y7GatrZYywXA38YKq1vCWmtrTYSMEBNgPqDy8NBDF"; +pub const LIB_ID_RGB20: &str = "phone_nickel_picasso_HxpamGfYpEBUS944ozetQsnS7YHmw3k3Ny2rpY9Eyp2G"; #[derive( Wrapper, WrapperMut, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default, From @@ -55,10 +55,32 @@ struct Meta { impl StrictSerialize for Meta {} impl StrictDeserialize for Meta {} +const SUPPLY_MISMATCH: u8 = 1; +const NON_EQUAL_AMOUNTS: u8 = 2; +const INVALID_PROOF: u8 = 3; +const INSUFFICIENT_RESERVES: u8 = 4; +const INSUFFICIENT_COVERAGE: u8 = 5; +const ISSUE_EXCEEDS_ALLOWANCE: u8 = 6; + +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] +#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB20, tags = repr, into_u8, try_from_u8)] +#[repr(u8)] +pub enum Error { + #[strict_type(dumb)] + SupplyMismatch = SUPPLY_MISMATCH, + NonEqualAmounts = NON_EQUAL_AMOUNTS, + InvalidProof = INVALID_PROOF, + InsufficientReserves = INSUFFICIENT_RESERVES, + InsufficientCoverage = INSUFFICIENT_COVERAGE, + IssueExceedsAllowance = ISSUE_EXCEEDS_ALLOWANCE, +} + fn _rgb20_stl() -> Result { LibBuilder::new(libname!(LIB_NAME_RGB20)) .transpile::() .transpile::() + .transpile::() .compile(bset! { bitcoin_stl().to_dependency(), rgb_contract_stl().to_dependency() @@ -103,6 +125,11 @@ pub fn rgb20() -> Iface { fname!("burnRight") => ArgSpec::optional(), }, valencies: none!(), + errors: small_bset! { + SUPPLY_MISMATCH, + INVALID_PROOF, + INSUFFICIENT_RESERVES + }, }, transitions: tiny_bmap! { tn!("Transfer") => TransitionIface { @@ -116,10 +143,14 @@ pub fn rgb20() -> Iface { fname!("beneficiary") => ArgSpec::from_non_empty("assetOwner"), }, valencies: none!(), + errors: small_bset! { + NON_EQUAL_AMOUNTS + }, default_assignment: Some(fname!("assetOwner")), } }, extensions: none!(), + error_type: types.get("RGB20.Error"), default_operation: Some(tn!("Transfer")), } } diff --git a/std/tests/data/rgb20.rgba b/std/tests/data/rgb20.rgba index cfdc50f8..d7ccfb95 100644 --- a/std/tests/data/rgb20.rgba +++ b/std/tests/data/rgb20.rgba @@ -1,5 +1,5 @@ ----- BEGIN RGB INTERFACE ----- -Id: WAukdU6P7gzJgpoBiuruCjqqr7uWUTo1xpBSMN1pi7B +Id: 9K2MqHHBSZFYfedrockgVwZzpYxrHMy5ASJbQrgh1NP8 AAVSR0IyMAYMYnVybmVkU3VwcGx5AYJ+OfqsC5wwo0fJrMCAaFfa8AJgCgdyhb3HkpdLRUYaAAEH Y3JlYXRlZAHK0bud73JnqPaARSzjY0/ngU2l+kvpLKccXt8S5qHkMAEADGlzc3VlZFN1cHBseQGC @@ -9,8 +9,9 @@ f7yeBJ9fqAEABXRlcm1zAbC/tv4Ak69rMjDl/Q09aarxS/CY3wdyjSULrjd5hhBwAQAECmFzc2V0 T3duZXICAAABCWJ1cm5SaWdodAIBAAASaW5mbGF0aW9uQWxsb3dhbmNlAgEAAQt1cGRhdGVSaWdo dAIBAAAAAVOp/1PXvEmPeBI4+UEyxeeg46mO/OeMrQ5xKPnpw7+uAwxpc3N1ZWRTdXBwbHkAAQAB AARzcGVjAAEAAQAFdGVybXMAAQABAAQKYXNzZXRPd25lcgAAAP//CWJ1cm5SaWdodAAAAAEAEmlu -ZmxhdGlvbkFsbG93YW5jZQAAAP//C3VwZGF0ZVJpZ2h0AAAAAQAAAQhUcmFuc2ZlcgAAAAEIcHJl -dmlvdXMBCmFzc2V0T3duZXIBAP//AQtiZW5lZmljaWFyeQEKYXNzZXRPd25lcgEA//8AAQphc3Nl -dE93bmVyAAEIVHJhbnNmZXI= +ZmxhdGlvbkFsbG93YW5jZQAAAP//C3VwZGF0ZVJpZ2h0AAAAAQAAAwABAwQBCFRyYW5zZmVyAAAA +AQhwcmV2aW91cwEKYXNzZXRPd25lcgEA//8BC2JlbmVmaWNpYXJ5AQphc3NldE93bmVyAQD//wAB +AAIBCmFzc2V0T3duZXIAMeTisG/6wkxUVaZ3w4cIHeFpfruRunHvOIJfyTAbyAMBCFRyYW5zZmVy + ----- END RGB INTERFACE ----- From 1c6f6b5d6588068d4deb153ade7825dc973a36e5 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 13:09:59 +0200 Subject: [PATCH 20/33] iface: add RGB20 issue operation --- std/src/interface/iface.rs | 8 ++++---- std/src/interface/rgb20.rs | 26 ++++++++++++++++++++++++-- std/tests/data/rgb20.rgba | 12 +++++++----- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/std/src/interface/iface.rs b/std/src/interface/iface.rs index 04daf74e..b5fe4fed 100644 --- a/std/src/interface/iface.rs +++ b/std/src/interface/iface.rs @@ -22,7 +22,7 @@ use std::cmp::Ordering; use std::str::FromStr; -use amplify::confinement::{SmallOrdSet, TinyOrdMap}; +use amplify::confinement::{TinyOrdMap, TinyOrdSet}; use amplify::{Bytes32, RawArray}; use baid58::{Baid58ParseError, FromBaid58, ToBaid58}; use commit_verify::{CommitStrategy, CommitmentId}; @@ -266,7 +266,7 @@ pub struct GenesisIface { pub global: ArgMap, pub assignments: ArgMap, pub valencies: ArgMap, - pub errors: SmallOrdSet, + pub errors: TinyOrdSet, } #[derive(Clone, PartialEq, Eq, Debug)] @@ -283,7 +283,7 @@ pub struct ExtensionIface { pub redeems: ArgMap, pub assignments: ArgMap, pub valencies: ArgMap, - pub errors: SmallOrdSet, + pub errors: TinyOrdSet, } #[derive(Clone, PartialEq, Eq, Debug)] @@ -302,7 +302,7 @@ pub struct TransitionIface { pub inputs: ArgMap, pub assignments: ArgMap, pub valencies: ArgMap, - pub errors: SmallOrdSet, + pub errors: TinyOrdSet, pub default_assignment: Option, } diff --git a/std/src/interface/rgb20.rs b/std/src/interface/rgb20.rs index a4e54f8e..de6ac1c0 100644 --- a/std/src/interface/rgb20.rs +++ b/std/src/interface/rgb20.rs @@ -125,7 +125,7 @@ pub fn rgb20() -> Iface { fname!("burnRight") => ArgSpec::optional(), }, valencies: none!(), - errors: small_bset! { + errors: tiny_bset! { SUPPLY_MISMATCH, INVALID_PROOF, INSUFFICIENT_RESERVES @@ -143,10 +143,32 @@ pub fn rgb20() -> Iface { fname!("beneficiary") => ArgSpec::from_non_empty("assetOwner"), }, valencies: none!(), - errors: small_bset! { + errors: tiny_bset! { NON_EQUAL_AMOUNTS }, default_assignment: Some(fname!("assetOwner")), + }, + tn!("Issue") => TransitionIface { + optional: true, + metadata: Some(types.get("RGB20.Meta")), + globals: tiny_bmap! { + fname!("issuedSupply") => ArgSpec::required(), + }, + inputs: tiny_bmap! { + fname!("used") => ArgSpec::from_non_empty("inflationAllowance"), + }, + assignments: tiny_bmap! { + fname!("beneficiary") => ArgSpec::from_many("assetOwner"), + fname!("future") => ArgSpec::from_many("inflationAllowance"), + }, + valencies: none!(), + errors: tiny_bset! { + SUPPLY_MISMATCH, + INVALID_PROOF, + ISSUE_EXCEEDS_ALLOWANCE, + INSUFFICIENT_RESERVES + }, + default_assignment: None, } }, extensions: none!(), diff --git a/std/tests/data/rgb20.rgba b/std/tests/data/rgb20.rgba index d7ccfb95..6aa986b1 100644 --- a/std/tests/data/rgb20.rgba +++ b/std/tests/data/rgb20.rgba @@ -1,5 +1,5 @@ ----- BEGIN RGB INTERFACE ----- -Id: 9K2MqHHBSZFYfedrockgVwZzpYxrHMy5ASJbQrgh1NP8 +Id: 8EoZwSPmBFiftEkar8T5qvSk1TavL1iJimxruqeJpQtQ AAVSR0IyMAYMYnVybmVkU3VwcGx5AYJ+OfqsC5wwo0fJrMCAaFfa8AJgCgdyhb3HkpdLRUYaAAEH Y3JlYXRlZAHK0bud73JnqPaARSzjY0/ngU2l+kvpLKccXt8S5qHkMAEADGlzc3VlZFN1cHBseQGC @@ -9,9 +9,11 @@ f7yeBJ9fqAEABXRlcm1zAbC/tv4Ak69rMjDl/Q09aarxS/CY3wdyjSULrjd5hhBwAQAECmFzc2V0 T3duZXICAAABCWJ1cm5SaWdodAIBAAASaW5mbGF0aW9uQWxsb3dhbmNlAgEAAQt1cGRhdGVSaWdo dAIBAAAAAVOp/1PXvEmPeBI4+UEyxeeg46mO/OeMrQ5xKPnpw7+uAwxpc3N1ZWRTdXBwbHkAAQAB AARzcGVjAAEAAQAFdGVybXMAAQABAAQKYXNzZXRPd25lcgAAAP//CWJ1cm5SaWdodAAAAAEAEmlu -ZmxhdGlvbkFsbG93YW5jZQAAAP//C3VwZGF0ZVJpZ2h0AAAAAQAAAwABAwQBCFRyYW5zZmVyAAAA -AQhwcmV2aW91cwEKYXNzZXRPd25lcgEA//8BC2JlbmVmaWNpYXJ5AQphc3NldE93bmVyAQD//wAB -AAIBCmFzc2V0T3duZXIAMeTisG/6wkxUVaZ3w4cIHeFpfruRunHvOIJfyTAbyAMBCFRyYW5zZmVy - +ZmxhdGlvbkFsbG93YW5jZQAAAP//C3VwZGF0ZVJpZ2h0AAAAAQAAAwEDBAIFSXNzdWUBAVOp/1PX +vEmPeBI4+UEyxeeg46mO/OeMrQ5xKPnpw7+uAQxpc3N1ZWRTdXBwbHkAAQABAAEEdXNlZAESaW5m +bGF0aW9uQWxsb3dhbmNlAQD//wILYmVuZWZpY2lhcnkBCmFzc2V0T3duZXIAAP//BmZ1dHVyZQES +aW5mbGF0aW9uQWxsb3dhbmNlAAD//wAEAQMEBgAIVHJhbnNmZXIAAAABCHByZXZpb3VzAQphc3Nl +dE93bmVyAQD//wELYmVuZWZpY2lhcnkBCmFzc2V0T3duZXIBAP//AAECAQphc3NldE93bmVyADHk +4rBv+sJMVFWmd8OHCB3haX67kbpx7ziCX8kwG8gDAQhUcmFuc2Zlcg== ----- END RGB INTERFACE ----- From 48faa6b62b35c58b74e3ed2704376553ac34f8e6 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 13:16:39 +0200 Subject: [PATCH 21/33] iface: add RGB20 burn and replace operations --- std/src/interface/rgb20.rs | 68 +++++++++++++++++++++++++++++++++----- std/tests/data/rgb20.rgba | 21 +++++++----- 2 files changed, 73 insertions(+), 16 deletions(-) diff --git a/std/src/interface/rgb20.rs b/std/src/interface/rgb20.rs index de6ac1c0..b86691d5 100644 --- a/std/src/interface/rgb20.rs +++ b/std/src/interface/rgb20.rs @@ -33,7 +33,7 @@ use crate::stl::{rgb_contract_stl, ProofOfReserves, StandardTypes}; pub const LIB_NAME_RGB20: &str = "RGB20"; /// Strict types id for the library providing data types for RGB20 interface. -pub const LIB_ID_RGB20: &str = "phone_nickel_picasso_HxpamGfYpEBUS944ozetQsnS7YHmw3k3Ny2rpY9Eyp2G"; +pub const LIB_ID_RGB20: &str = "giant_eagle_capsule_9QCXsi6d26jqNQVszMAYUDffRjwUkGRWeDCM84ZwPafA"; #[derive( Wrapper, WrapperMut, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default, From @@ -49,11 +49,20 @@ impl StrictDeserialize for Amount {} #[derive(Clone, Eq, PartialEq, Hash, Debug, Default)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB20)] -struct Meta { +struct IssueMeta { pub reserves: SmallOrdSet, } -impl StrictSerialize for Meta {} -impl StrictDeserialize for Meta {} +impl StrictSerialize for IssueMeta {} +impl StrictDeserialize for IssueMeta {} + +#[derive(Clone, Eq, PartialEq, Hash, Debug, Default)] +#[derive(StrictType, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB20)] +struct BurnMeta { + pub burn_proofs: SmallOrdSet, +} +impl StrictSerialize for BurnMeta {} +impl StrictDeserialize for BurnMeta {} const SUPPLY_MISMATCH: u8 = 1; const NON_EQUAL_AMOUNTS: u8 = 2; @@ -78,7 +87,8 @@ pub enum Error { fn _rgb20_stl() -> Result { LibBuilder::new(libname!(LIB_NAME_RGB20)) - .transpile::() + .transpile::() + .transpile::() .transpile::() .transpile::() .compile(bset! { @@ -112,7 +122,7 @@ pub fn rgb20() -> Iface { }, valencies: none!(), genesis: GenesisIface { - metadata: Some(types.get("RGB20.Meta")), + metadata: Some(types.get("RGB20.IssueMeta")), global: tiny_bmap! { fname!("spec") => ArgSpec::required(), fname!("terms") => ArgSpec::required(), @@ -150,7 +160,7 @@ pub fn rgb20() -> Iface { }, tn!("Issue") => TransitionIface { optional: true, - metadata: Some(types.get("RGB20.Meta")), + metadata: Some(types.get("RGB20.IssueMeta")), globals: tiny_bmap! { fname!("issuedSupply") => ArgSpec::required(), }, @@ -169,7 +179,49 @@ pub fn rgb20() -> Iface { INSUFFICIENT_RESERVES }, default_assignment: None, - } + }, + tn!("Burn") => TransitionIface { + optional: true, + metadata: Some(types.get("RGB20.BurnMeta")), + globals: tiny_bmap! { + fname!("burnedSupply") => ArgSpec::required(), + }, + inputs: tiny_bmap! { + fname!("used") => ArgSpec::from_required("burnRight"), + }, + assignments: tiny_bmap! { + fname!("future") => ArgSpec::from_optional("burnRight"), + }, + valencies: none!(), + errors: tiny_bset! { + SUPPLY_MISMATCH, + INVALID_PROOF, + INSUFFICIENT_COVERAGE + }, + default_assignment: None, + }, + tn!("Replace") => TransitionIface { + optional: true, + metadata: Some(types.get("RGB20.BurnMeta")), + globals: tiny_bmap! { + fname!("replacedSupply") => ArgSpec::required(), + }, + inputs: tiny_bmap! { + fname!("used") => ArgSpec::from_required("burnRight"), + }, + assignments: tiny_bmap! { + fname!("beneficiary") => ArgSpec::from_many("assetOwner"), + fname!("future") => ArgSpec::from_optional("burnRight"), + }, + valencies: none!(), + errors: tiny_bset! { + NON_EQUAL_AMOUNTS, + SUPPLY_MISMATCH, + INVALID_PROOF, + INSUFFICIENT_COVERAGE + }, + default_assignment: None, + }, }, extensions: none!(), error_type: types.get("RGB20.Error"), diff --git a/std/tests/data/rgb20.rgba b/std/tests/data/rgb20.rgba index 6aa986b1..8dd5f2c9 100644 --- a/std/tests/data/rgb20.rgba +++ b/std/tests/data/rgb20.rgba @@ -1,5 +1,5 @@ ----- BEGIN RGB INTERFACE ----- -Id: 8EoZwSPmBFiftEkar8T5qvSk1TavL1iJimxruqeJpQtQ +Id: HBrRRvUbZbeJ2vy6Hj5eC83GeBGTv7gt2yK6zG1Wbsjh AAVSR0IyMAYMYnVybmVkU3VwcGx5AYJ+OfqsC5wwo0fJrMCAaFfa8AJgCgdyhb3HkpdLRUYaAAEH Y3JlYXRlZAHK0bud73JnqPaARSzjY0/ngU2l+kvpLKccXt8S5qHkMAEADGlzc3VlZFN1cHBseQGC @@ -7,13 +7,18 @@ fjn6rAucMKNHyazAgGhX2vACYAoHcoW9x5KXS0VGGgABDnJlcGxhY2VkU3VwcGx5AYJ+OfqsC5ww o0fJrMCAaFfa8AJgCgdyhb3HkpdLRUYaAAEEc3BlYwFxG/dbTJD45i4e05+I9KxrFvpf3zTcvqOz f7yeBJ9fqAEABXRlcm1zAbC/tv4Ak69rMjDl/Q09aarxS/CY3wdyjSULrjd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XNlZAESaW5mbGF0aW9u +QWxsb3dhbmNlAQD//wILYmVuZWZpY2lhcnkBCmFzc2V0T3duZXIAAP//BmZ1dHVyZQESaW5mbGF0 +aW9uQWxsb3dhbmNlAAD//wAEAQMEBgAHUmVwbGFjZQEB9L3LR6p9scqrVlb0guZ4jyLPRTT5PVBs +2zUOE7nQ2esBDnJlcGxhY2VkU3VwcGx5AAEAAQABBHVzZWQBCWJ1cm5SaWdodAEAAQACC2JlbmVm +aWNpYXJ5AQphc3NldE93bmVyAAD//wZmdXR1cmUBCWJ1cm5SaWdodAAAAQAABAECAwUACFRyYW5z +ZmVyAAAAAQhwcmV2aW91cwEKYXNzZXRPd25lcgEA//8BC2JlbmVmaWNpYXJ5AQphc3NldE93bmVy +AQD//wABAgEKYXNzZXRPd25lcgAx5OKwb/rCTFRVpnfDhwgd4Wl+u5G6ce84gl/JMBvIAwEIVHJh +bnNmZXI= ----- END RGB INTERFACE ----- From 59f74ace51d4965503dfcc5136eff3eba0f60c64 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 13:19:46 +0200 Subject: [PATCH 22/33] iface: add RGB20 rename operation --- std/src/interface/rgb20.rs | 22 +++++++++++++++++++--- std/tests/data/rgb20.rgba | 17 +++++++++-------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/std/src/interface/rgb20.rs b/std/src/interface/rgb20.rs index b86691d5..822b459d 100644 --- a/std/src/interface/rgb20.rs +++ b/std/src/interface/rgb20.rs @@ -156,7 +156,7 @@ pub fn rgb20() -> Iface { errors: tiny_bset! { NON_EQUAL_AMOUNTS }, - default_assignment: Some(fname!("assetOwner")), + default_assignment: Some(fname!("beneficiary")), }, tn!("Issue") => TransitionIface { optional: true, @@ -178,7 +178,7 @@ pub fn rgb20() -> Iface { ISSUE_EXCEEDS_ALLOWANCE, INSUFFICIENT_RESERVES }, - default_assignment: None, + default_assignment: Some(fname!("beneficiary")), }, tn!("Burn") => TransitionIface { optional: true, @@ -220,7 +220,23 @@ pub fn rgb20() -> Iface { INVALID_PROOF, INSUFFICIENT_COVERAGE }, - default_assignment: None, + default_assignment: Some(fname!("beneficiary")), + }, + tn!("Rename") => TransitionIface { + optional: true, + metadata: None, + globals: tiny_bmap! { + fname!("spec") => ArgSpec::required(), + }, + inputs: tiny_bmap! { + fname!("used") => ArgSpec::from_required("updateRight"), + }, + assignments: tiny_bmap! { + fname!("future") => ArgSpec::from_optional("updateRight"), + }, + valencies: none!(), + errors: none!(), + default_assignment: Some(fname!("future")), }, }, extensions: none!(), diff --git a/std/tests/data/rgb20.rgba b/std/tests/data/rgb20.rgba index 8dd5f2c9..e689abf3 100644 --- a/std/tests/data/rgb20.rgba +++ b/std/tests/data/rgb20.rgba @@ -1,5 +1,5 @@ ----- BEGIN RGB INTERFACE ----- -Id: HBrRRvUbZbeJ2vy6Hj5eC83GeBGTv7gt2yK6zG1Wbsjh +Id: 3vEd1zxqAEeCGGtjpqMt2s2cvkdGnS1Ur2q3rYzLH3nh AAVSR0IyMAYMYnVybmVkU3VwcGx5AYJ+OfqsC5wwo0fJrMCAaFfa8AJgCgdyhb3HkpdLRUYaAAEH Y3JlYXRlZAHK0bud73JnqPaARSzjY0/ngU2l+kvpLKccXt8S5qHkMAEADGlzc3VlZFN1cHBseQGC @@ -9,16 +9,17 @@ f7yeBJ9fqAEABXRlcm1zAbC/tv4Ak69rMjDl/Q09aarxS/CY3wdyjSULrjd5hhBwAQAECmFzc2V0 T3duZXICAAABCWJ1cm5SaWdodAIBAAASaW5mbGF0aW9uQWxsb3dhbmNlAgEAAQt1cGRhdGVSaWdo dAIBAAAAAQcYNjUhwMLjGRXIMEqTPo+cPmnRH/maqqFJnGHpgxW3Awxpc3N1ZWRTdXBwbHkAAQAB AARzcGVjAAEAAQAFdGVybXMAAQABAAQKYXNzZXRPd25lcgAAAP//CWJ1cm5SaWdodAAAAAEAEmlu -ZmxhdGlvbkFsbG93YW5jZQAAAP//C3VwZGF0ZVJpZ2h0AAAAA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1cm5SaWdodAEAAQACC2JlbmVmaWNpYXJ5AQphc3NldE93bmVyAAD//wZm +dXR1cmUBCWJ1cm5SaWdodAAAAQAABAECAwUBC2JlbmVmaWNpYXJ5CFRyYW5zZmVyAAAAAQhwcmV2 +aW91cwEKYXNzZXRPd25lcgEA//8BC2JlbmVmaWNpYXJ5AQphc3NldE93bmVyAQD//wABAgELYmVu +ZWZpY2lhcnkAMeTisG/6wkxUVaZ3w4cIHeFpfruRunHvOIJfyTAbyAMBCFRyYW5zZmVy ----- END RGB INTERFACE ----- From 3e490b9d06c130762ac193dce35a2d28aa454ad4 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 13:46:08 +0200 Subject: [PATCH 23/33] iface: add RGB20 burn epochs --- std/src/interface/rgb20.rs | 20 ++++++++++++++++++-- std/tests/data/rgb20.rgba | 36 +++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/std/src/interface/rgb20.rs b/std/src/interface/rgb20.rs index 822b459d..cb7add62 100644 --- a/std/src/interface/rgb20.rs +++ b/std/src/interface/rgb20.rs @@ -117,7 +117,8 @@ pub fn rgb20() -> Iface { assignments: tiny_bmap! { fname!("inflationAllowance") => AssignIface::public(OwnedIface::Amount, Req::NoneOrMore), fname!("updateRight") => AssignIface::public(OwnedIface::Amount, Req::Optional), - fname!("burnRight") => AssignIface::public(OwnedIface::Amount, Req::Optional), + fname!("burnEpoch") => AssignIface::public(OwnedIface::Rights, Req::Optional), + fname!("burnRight") => AssignIface::public(OwnedIface::Rights, Req::NoneOrMore), fname!("assetOwner") => AssignIface::private(OwnedIface::Amount, Req::NoneOrMore), }, valencies: none!(), @@ -132,7 +133,7 @@ pub fn rgb20() -> Iface { fname!("assetOwner") => ArgSpec::many(), fname!("inflationAllowance") => ArgSpec::many(), fname!("updateRight") => ArgSpec::optional(), - fname!("burnRight") => ArgSpec::optional(), + fname!("burnEpoch") => ArgSpec::optional(), }, valencies: none!(), errors: tiny_bset! { @@ -180,6 +181,21 @@ pub fn rgb20() -> Iface { }, default_assignment: Some(fname!("beneficiary")), }, + tn!("OpenEpoch") => TransitionIface { + optional: true, + metadata: None, + globals: none!(), + inputs: tiny_bmap! { + fname!("used") => ArgSpec::from_required("burnEpoch"), + }, + assignments: tiny_bmap! { + fname!("next") => ArgSpec::from_optional("burnEpoch"), + fname!("burnRight") => ArgSpec::required() + }, + valencies: none!(), + errors: none!(), + default_assignment: Some(fname!("burnRight")), + }, tn!("Burn") => TransitionIface { optional: true, metadata: Some(types.get("RGB20.BurnMeta")), diff --git a/std/tests/data/rgb20.rgba b/std/tests/data/rgb20.rgba index e689abf3..af3b1b65 100644 --- a/std/tests/data/rgb20.rgba +++ b/std/tests/data/rgb20.rgba @@ -1,25 +1,27 @@ ----- BEGIN RGB INTERFACE ----- -Id: 3vEd1zxqAEeCGGtjpqMt2s2cvkdGnS1Ur2q3rYzLH3nh +Id: AkCncFR3xzCikU1udAVnsZD1mVu8kXG6EBuFCPFDBsTe AAVSR0IyMAYMYnVybmVkU3VwcGx5AYJ+OfqsC5wwo0fJrMCAaFfa8AJgCgdyhb3HkpdLRUYaAAEH Y3JlYXRlZAHK0bud73JnqPaARSzjY0/ngU2l+kvpLKccXt8S5qHkMAEADGlzc3VlZFN1cHBseQGC fjn6rAucMKNHyazAgGhX2vACYAoHcoW9x5KXS0VGGgABDnJlcGxhY2VkU3VwcGx5AYJ+OfqsC5ww o0fJrMCAaFfa8AJgCgdyhb3HkpdLRUYaAAEEc3BlYwFxG/dbTJD45i4e05+I9KxrFvpf3zTcvqOz -f7yeBJ9fqAEABXRlcm1zAbC/tv4Ak69rMjDl/Q09aarxS/CY3wdyjSULrjd5hhBwAQAECmFzc2V0 -T3duZXICAAABCWJ1cm5SaWdodAIBAAASaW5mbGF0aW9uQWxsb3dhbmNlAgEAAQt1cGRhdGVSaWdo -dAIBAAAAAQcYNjUhwMLjGRXIMEqTPo+cPmnRH/maqqFJnGHpgxW3Awxpc3N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yeQEKYXNzZXRPd25lcgAA//8GZnV0dXJlAQlidXJuUmlnaHQA +AAEAAAQBAgMFAQtiZW5lZmljaWFyeQhUcmFuc2ZlcgAAAAEIcHJldmlvdXMBCmFzc2V0T3duZXIB +AP//AQtiZW5lZmljaWFyeQEKYXNzZXRPd25lcgEA//8AAQIBC2JlbmVmaWNpYXJ5ADHk4rBv+sJM +VFWmd8OHCB3haX67kbpx7ziCX8kwG8gDAQhUcmFuc2Zlcg== ----- END RGB INTERFACE ----- From 37513e8cef33aebb63555b19aaafa4b7b6232598 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 13:58:08 +0200 Subject: [PATCH 24/33] containers: improve Bindle armored format --- std/src/containers/bindle.rs | 45 +++++++++++++++++++++++++++--- std/src/containers/util.rs | 3 +- std/tests/data/rgb20.rgba | 53 ++++++++++++++++++++---------------- 3 files changed, 72 insertions(+), 29 deletions(-) diff --git a/std/src/containers/bindle.rs b/std/src/containers/bindle.rs index 84a90194..84ab9dac 100644 --- a/std/src/containers/bindle.rs +++ b/std/src/containers/bindle.rs @@ -23,6 +23,7 @@ //! and optionally signed by the creator with certain id and send over to a //! remote party. +use std::collections::BTreeMap; use std::fmt::Display; use std::ops::Deref; @@ -49,6 +50,7 @@ pub trait BindleContent: StrictSerialize + StrictDeserialize + StrictDumb { type Id: Copy + Eq + Display + StrictType + StrictDumb + StrictEncode + StrictDecode; fn bindle_id(&self) -> Self::Id; + fn bindle_headers(&self) -> BTreeMap<&'static str, String> { none!() } fn bindle(self) -> Bindle { Bindle::new(self) } } @@ -64,6 +66,16 @@ impl BindleContent for Contract { const PLATE_TITLE: &'static str = "RGB CONTRACT"; type Id = ContractId; fn bindle_id(&self) -> Self::Id { self.contract_id() } + fn bindle_headers(&self) -> BTreeMap<&'static str, String> { + bmap! { + "Version" => self.version.to_string(), + "Terminals" => self.terminals + .iter() + .map(|t| t.seal.to_string()) + .collect::>() + .join(",\n "), + } + } } impl BindleContent for Transfer { @@ -71,6 +83,17 @@ impl BindleContent for Transfer { const PLATE_TITLE: &'static str = "RGB STATE TRANSFER"; type Id = TransferId; fn bindle_id(&self) -> Self::Id { self.transfer_id() } + fn bindle_headers(&self) -> BTreeMap<&'static str, String> { + bmap! { + "Version" => self.version.to_string(), + "ContractId" => self.contract_id().to_string(), + "Terminals" => self.terminals + .iter() + .map(|t| t.seal.to_string()) + .collect::>() + .join(",\n "), + } + } } impl BindleContent for Iface { @@ -78,6 +101,11 @@ impl BindleContent for Iface { const PLATE_TITLE: &'static str = "RGB INTERFACE"; type Id = IfaceId; fn bindle_id(&self) -> Self::Id { self.iface_id() } + fn bindle_headers(&self) -> BTreeMap<&'static str, String> { + bmap! { + "Name" => self.name.to_string() + } + } } impl BindleContent for IfaceImpl { @@ -85,6 +113,12 @@ impl BindleContent for IfaceImpl { const PLATE_TITLE: &'static str = "RGB INTERFACE IMPLEMENTATION"; type Id = ImplId; fn bindle_id(&self) -> Self::Id { self.impl_id() } + fn bindle_headers(&self) -> BTreeMap<&'static str, String> { + bmap! { + "IfaceId" => self.iface_id.to_string(), + "SchemaId" => self.schema_id.to_string(), + } + } } #[derive(Clone, PartialEq, Eq, Hash, Debug)] @@ -129,8 +163,11 @@ impl Display for Bindle { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { use base64::Engine; - writeln!(f, "----- BEGIN {} -----", C::PLATE_TITLE)?; + writeln!(f, "-----BEGIN {}-----", C::PLATE_TITLE)?; writeln!(f, "Id: {}", self.id)?; + for (header, value) in self.bindle_headers() { + writeln!(f, "{header}: {value}")?; + } for cert in &self.sigs { writeln!(f, "Signed-By: {}", cert.signer)?; } @@ -144,14 +181,14 @@ impl Display for Bindle { let engine = base64::engine::general_purpose::STANDARD; let data = engine.encode(data); let mut data = data.as_str(); - while data.len() >= 76 { - let (line, rest) = data.split_at(76); + while data.len() >= 64 { + let (line, rest) = data.split_at(64); writeln!(f, "{}", line)?; data = rest; } writeln!(f, "{}", data)?; - writeln!(f, "\n----- END {} -----", C::PLATE_TITLE)?; + writeln!(f, "\n-----END {}-----", C::PLATE_TITLE)?; Ok(()) } } diff --git a/std/src/containers/util.rs b/std/src/containers/util.rs index 4f39bb4c..adc236fa 100644 --- a/std/src/containers/util.rs +++ b/std/src/containers/util.rs @@ -41,7 +41,7 @@ impl Terminal { pub fn with(bundle_id: BundleId, seal: TerminalSeal) -> Self { Terminal { bundle_id, seal } } } -#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default)] +#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display, Default)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB_STD, tags = repr, into_u8, try_from_u8)] #[cfg_attr( @@ -49,6 +49,7 @@ impl Terminal { derive(Serialize, Deserialize), serde(crate = "serde_crate", rename_all = "camelCase") )] +#[display(lowercase)] #[non_exhaustive] #[repr(u8)] pub enum ContainerVer { diff --git a/std/tests/data/rgb20.rgba b/std/tests/data/rgb20.rgba index af3b1b65..cc8ceaf2 100644 --- a/std/tests/data/rgb20.rgba +++ b/std/tests/data/rgb20.rgba @@ -1,27 +1,32 @@ ------ BEGIN RGB INTERFACE ----- +-----BEGIN RGB INTERFACE----- Id: AkCncFR3xzCikU1udAVnsZD1mVu8kXG6EBuFCPFDBsTe +Name: RGB20 -AAVSR0IyMAYMYnVybmVkU3VwcGx5AYJ+OfqsC5wwo0fJrMCAaFfa8AJgCgdyhb3HkpdLRUYaAAEH -Y3JlYXRlZAHK0bud73JnqPaARSzjY0/ngU2l+kvpLKccXt8S5qHkMAEADGlzc3VlZFN1cHBseQGC -fjn6rAucMKNHyazAgGhX2vACYAoHcoW9x5KXS0VGGgABDnJlcGxhY2VkU3VwcGx5AYJ+OfqsC5ww -o0fJrMCAaFfa8AJgCgdyhb3HkpdLRUYaAAEEc3BlYwFxG/dbTJD45i4e05+I9KxrFvpf3zTcvqOz -f7yeBJ9fqAEABXR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J1cm5SaWdodAEAAQABBmZ1dHVyZQEJYnVyblJpZ2h0AAABAAADAQMFAAVJ +c3N1ZQEBBxg2NSHAwuMZFcgwSpM+j5w+adEf+ZqqoUmcYemDFbcBDGlzc3VlZFN1 +cHBseQABAAEAAQR1c2VkARJpbmZsYXRpb25BbGxvd2FuY2UBAP//AgtiZW5lZmlj +aWFyeQEKYXNzZXRPd25lcgAA//8GZnV0dXJlARJpbmZsYXRpb25BbGxvd2FuY2UA +AP//AAQBAwQGAQtiZW5lZmljaWFyeQlPcGVuRXBvY2gBAAABBHVzZWQBCWJ1cm5F +cG9jaAEAAQACCWJ1cm5SaWdodAABAAEABG5leHQBCWJ1cm5FcG9jaAAAAQAAAAEJ +YnVyblJpZ2h0BlJlbmFtZQEAAQRzcGVjAAEAAQABBHVzZWQBC3VwZGF0ZVJpZ2h0 +AQABAAEGZnV0dXJlAQt1cGRhdGVSaWdodAAAAQAAAAEGZnV0dXJlB1JlcGxhY2UB +AfS9y0eqfbHKq1ZW9ILmeI8iz0U0+T1QbNs1DhO50NnrAQ5yZXBsYWNlZFN1cHBs +eQABAAEAAQR1c2VkAQlidXJuUmlnaHQBAAEAAgtiZW5lZmljaWFyeQEKYXNzZXRP +d25lcgAA//8GZnV0dXJlAQlidXJuUmlnaHQAAAEAAAQBAgMFAQtiZW5lZmljaWFy +eQhUcmFuc2ZlcgAAAAEIcHJldmlvdXMBCmFzc2V0T3duZXIBAP//AQtiZW5lZmlj +aWFyeQEKYXNzZXRPd25lcgEA//8AAQIBC2JlbmVmaWNpYXJ5ADHk4rBv+sJMVFWm +d8OHCB3haX67kbpx7ziCX8kwG8gDAQhUcmFuc2Zlcg== ------ END RGB INTERFACE ----- +-----END RGB INTERFACE----- From e0e422e1f40acdd858a2871dd8e11c467bd403e1 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 14:06:06 +0200 Subject: [PATCH 25/33] iface: update RGB20 stl --- stl/RGB20@0.1.0.sta | 14 +++++++++----- stl/RGB20@0.1.0.stl | Bin 200 -> 428 bytes stl/RGB20@0.1.0.sty | 10 +++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/stl/RGB20@0.1.0.sta b/stl/RGB20@0.1.0.sta index 5077df3f..b099b32c 100644 --- a/stl/RGB20@0.1.0.sta +++ b/stl/RGB20@0.1.0.sta @@ -1,15 +1,19 @@ -----BEGIN STRICT TYPE LIB----- -Id: escort_chamber_clone_8g3y7GatrZYywXA38YKq1vCWmtrTYSMEBNgPqDy8NBDF +Id: giant_eagle_capsule_9QCXsi6d26jqNQVszMAYUDffRjwUkGRWeDCM84ZwPafA Name: RGB20 Dependencies: RGBContract@level_decide_percent_6z2gZQEJsnP4xoNUC94vqYEE9V7gKQbeJhb5521xta5u, Bitcoin@cubic_filter_vampire_AqBBP1ZeTXrdAePf6SBcUGbttpvxpHKG7uJLKFkVxtGi BVJHQjIwAljmcVEaBmUvNnuaNhdNwvUqhXbh6gDg28jkixwjzddoC1JHQkNvbnRy -YWN0khCSD+5t80apbygpkiw4UYjv0hOwwSfKS+1eTBW9YXMHQml0Y29pbgIABkFt -b3VudAUBAAAIBE1ldGEGAQhyZXNlcnZlcwAJAg9Qcm9vZk9mUmVzZXJ2ZXMLUkdC -Q29udHJhY3S6A6JqlDC0xrIg5HDyvbzYYjoMf7g5GsQVjl3ey3a8gAAAAAAAAAAA -//8AAAAAAAA= +YWN0khCSD+5t80apbygpkiw4UYjv0hOwwSfKS+1eTBW9YXMHQml0Y29pbgQABkFt +b3VudAUBAAAICEJ1cm5NZXRhBgEKYnVyblByb29mcwAJAg9Qcm9vZk9mUmVzZXJ2 +ZXMLUkdCQ29udHJhY3S6A6JqlDC0xrIg5HDyvbzYYjoMf7g5GsQVjl3ey3a8gAAA +AAAAAAAA//8AAAAAAAAFRXJyb3IDBg5zdXBwbHlNaXNtYXRjaAEPbm9uRXF1YWxB +bW91bnRzAgxpbnZhbGlkUHJvb2YDFGluc3VmZmljaWVudFJlc2VydmVzBBRpbnN1 +ZmZpY2llbnRDb3ZlcmFnZQUVaXNzdWVFeGNlZWRzQWxsb3dhbmNlBglJc3N1ZU1l +dGEGAQhyZXNlcnZlcwAJAg9Qcm9vZk9mUmVzZXJ2ZXMLUkdCQ29udHJhY3S6A6Jq +lDC0xrIg5HDyvbzYYjoMf7g5GsQVjl3ey3a8gAAAAAAAAAAA//8AAAAAAAA= -----END STRICT TYPE LIB----- diff --git a/stl/RGB20@0.1.0.stl b/stl/RGB20@0.1.0.stl index 7f90119206a09f89a976680b2b8301cac9c4c08c..49c5cc383601701f3b5c6814e0761322c6cecf90 100644 GIT binary patch delta 178 zcmY+6K@Ng25CEw_gU0AZU*Jp7aPUAvyqcKQvS>}&Vz)&+`33oh5Aj(NJ$ai Date: Mon, 15 May 2023 19:29:14 +0200 Subject: [PATCH 26/33] iface: fixes for RGB20 to match the standard --- std/src/interface/rgb20.rs | 7 +++---- std/tests/data/rgb20.rgba | 41 +++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/std/src/interface/rgb20.rs b/std/src/interface/rgb20.rs index cb7add62..96d1d491 100644 --- a/std/src/interface/rgb20.rs +++ b/std/src/interface/rgb20.rs @@ -43,8 +43,6 @@ pub const LIB_ID_RGB20: &str = "giant_eagle_capsule_9QCXsi6d26jqNQVszMAYUDffRjwU #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB20)] struct Amount(u64); -impl StrictSerialize for Amount {} -impl StrictDeserialize for Amount {} #[derive(Clone, Eq, PartialEq, Hash, Debug, Default)] #[derive(StrictType, StrictEncode, StrictDecode)] @@ -116,7 +114,7 @@ pub fn rgb20() -> Iface { }, assignments: tiny_bmap! { fname!("inflationAllowance") => AssignIface::public(OwnedIface::Amount, Req::NoneOrMore), - fname!("updateRight") => AssignIface::public(OwnedIface::Amount, Req::Optional), + fname!("updateRight") => AssignIface::public(OwnedIface::Rights, Req::Optional), fname!("burnEpoch") => AssignIface::public(OwnedIface::Rights, Req::Optional), fname!("burnRight") => AssignIface::public(OwnedIface::Rights, Req::NoneOrMore), fname!("assetOwner") => AssignIface::private(OwnedIface::Amount, Req::NoneOrMore), @@ -127,6 +125,7 @@ pub fn rgb20() -> Iface { global: tiny_bmap! { fname!("spec") => ArgSpec::required(), fname!("terms") => ArgSpec::required(), + fname!("created") => ArgSpec::required(), fname!("issuedSupply") => ArgSpec::required(), }, assignments: tiny_bmap! { @@ -242,7 +241,7 @@ pub fn rgb20() -> Iface { optional: true, metadata: None, globals: tiny_bmap! { - fname!("spec") => ArgSpec::required(), + fname!("new") => ArgSpec::from_required("spec"), }, inputs: tiny_bmap! { fname!("used") => ArgSpec::from_required("updateRight"), diff --git a/std/tests/data/rgb20.rgba b/std/tests/data/rgb20.rgba index cc8ceaf2..874f43ef 100644 --- a/std/tests/data/rgb20.rgba +++ b/std/tests/data/rgb20.rgba @@ -1,5 +1,5 @@ -----BEGIN RGB INTERFACE----- -Id: AkCncFR3xzCikU1udAVnsZD1mVu8kXG6EBuFCPFDBsTe +Id: Hi9HY8XN955imFe2DsJHeaoZQLM7rVSSSGtsP5JHsZx2 Name: RGB20 AAVSR0IyMAYMYnVybmVkU3VwcGx5AYJ+OfqsC5wwo0fJrMCAaFfa8AJgCgdyhb3H @@ -9,24 +9,25 @@ GgABDnJlcGxhY2VkU3VwcGx5AYJ+OfqsC5wwo0fJrMCAaFfa8AJgCgdyhb3HkpdL RUYaAAEEc3BlYwFxG/dbTJD45i4e05+I9KxrFvpf3zTcvqOzf7yeBJ9fqAEABXRl cm1zAbC/tv4Ak69rMjDl/Q09aarxS/CY3wdyjSULrjd5hhBwAQAFCmFzc2V0T3du ZXICAAABCWJ1cm5FcG9jaAEBAAAJYnVyblJpZ2h0AQEAARJpbmZsYXRpb25BbGxv -d2FuY2UCAQABC3VwZGF0ZVJpZ2h0AgEAAAABBxg2NSHAwuMZFcgwSpM+j5w+adEf -+ZqqoUmcYemDFbcDDGlzc3VlZFN1cHBseQ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E93bmVyAAD//wZmdXR1cmUBCWJ1cm5SaWdodAAAAQAA +BAECAwUBC2JlbmVmaWNpYXJ5CFRyYW5zZmVyAAAAAQhwcmV2aW91cwEKYXNzZXRP +d25lcgEA//8BC2JlbmVmaWNpYXJ5AQphc3NldE93bmVyAQD//wABAgELYmVuZWZp +Y2lhcnkAMeTisG/6wkxUVaZ3w4cIHeFpfruRunHvOIJfyTAbyAMBCFRyYW5zZmVy + -----END RGB INTERFACE----- From a10e1127d4c114c753de35a604f1e3a447e6c36e Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 19:29:38 +0200 Subject: [PATCH 27/33] stl: add MediaType Debug derivation --- std/src/stl/mime.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/std/src/stl/mime.rs b/std/src/stl/mime.rs index 548741a2..a4b3cfcf 100644 --- a/std/src/stl/mime.rs +++ b/std/src/stl/mime.rs @@ -19,6 +19,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![allow(unused_braces)] + use std::fmt::{self, Debug, Formatter}; use std::str::FromStr; @@ -30,7 +32,7 @@ use strict_encoding::{ use super::LIB_NAME_RGB_CONTRACT; -#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] +#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Hash)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB_CONTRACT)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))] @@ -63,8 +65,8 @@ impl MediaType { #[derive(Wrapper, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, From)] #[wrapper(Deref, Display)] -#[derive(StrictType, StrictDecode)] -#[strict_type(lib = LIB_NAME_RGB_CONTRACT)] +#[derive(StrictType, StrictDumb, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB_CONTRACT, dumb = { MediaRegName::from("dumb") })] #[cfg_attr( feature = "serde", derive(Serialize, Deserialize), @@ -79,10 +81,6 @@ impl StrictEncode for MediaRegName { } } -impl StrictDumb for MediaRegName { - fn strict_dumb() -> Self { MediaRegName::from("dumb") } -} - // TODO: Ensure all constructors filter invalid characters impl FromStr for MediaRegName { type Err = InvalidIdent; @@ -95,7 +93,7 @@ impl FromStr for MediaRegName { } impl From<&'static str> for MediaRegName { - fn from(s: &'static str) -> Self { Self::from_str(s).expect("invalid ticker name") } + fn from(s: &'static str) -> Self { Self::from_str(s).expect("invalid media-reg name") } } impl TryFrom for MediaRegName { @@ -110,7 +108,7 @@ impl TryFrom for MediaRegName { impl Debug for MediaRegName { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - f.debug_tuple("ContractName").field(&self.as_str()).finish() + f.debug_tuple("MediaRegName").field(&self.as_str()).finish() } } From b40791052e5b66a4dc0cf3df3d80a351411ba85c Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 19:29:53 +0200 Subject: [PATCH 28/33] iface: impl RGB21 according to the standard --- std/src/bin/rgb-stl.rs | 17 +- std/src/interface/mod.rs | 2 + std/src/interface/rgb21.rs | 375 +++++++++++++++++++++++++++++++++++++ std/tests/data/rgb21.rgba | 29 +++ stl/RGB21@0.1.0.sta | 46 +++++ stl/RGB21@0.1.0.stl | Bin 0 -> 1637 bytes stl/RGB21@0.1.0.sty | 39 ++++ 7 files changed, 507 insertions(+), 1 deletion(-) create mode 100644 std/tests/data/rgb21.rgba create mode 100644 stl/RGB21@0.1.0.sta create mode 100644 stl/RGB21@0.1.0.stl create mode 100644 stl/RGB21@0.1.0.sty diff --git a/std/src/bin/rgb-stl.rs b/std/src/bin/rgb-stl.rs index a4f5b737..7defd51c 100644 --- a/std/src/bin/rgb-stl.rs +++ b/std/src/bin/rgb-stl.rs @@ -20,7 +20,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use rgbstd::interface::rgb20_stl; +use rgbstd::interface::{rgb20_stl, rgb21_stl}; use rgbstd::stl::rgb_contract_stl; use strict_types::typelib::parse_args; @@ -52,6 +52,21 @@ fn main() { Description: Types for RGB20 interface Author: Dr Maxim Orlovsky Copyright (C) 2023 LNP/BP Standards Association. All rights reserved. + License: Apache-2.0", + ), + ) + .expect("unable to write to the file"); + + rgb21_stl() + .serialize( + format, + dir.as_ref(), + "0.1.0", + Some( + " + Description: Types for RGB21 interface + Author: Dr Maxim Orlovsky + Copyright (C) 2023 LNP/BP Standards Association. All rights reserved. License: Apache-2.0", ), ) diff --git a/std/src/interface/mod.rs b/std/src/interface/mod.rs index 2b9e9cfc..5bc0ddf6 100644 --- a/std/src/interface/mod.rs +++ b/std/src/interface/mod.rs @@ -28,6 +28,7 @@ mod iimpl; mod contract; mod builder; mod rgb20; +mod rgb21; mod suppl; pub use builder::{BuilderError, ContractBuilder, OperationBuilder, TransitionBuilder}; @@ -38,6 +39,7 @@ pub use iface::{ }; pub use iimpl::{IfaceImpl, IfacePair, ImplId, NamedField, NamedType, SchemaIfaces}; pub use rgb20::{rgb20, rgb20_stl, LIB_ID_RGB20, LIB_NAME_RGB20}; +pub use rgb21::{rgb21, rgb21_stl, LIB_ID_RGB21, LIB_NAME_RGB21}; pub use suppl::{AppDeriveIndex, ContractSuppl, OwnedStateSuppl, SupplId, TickerSuppl}; #[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display, Default)] diff --git a/std/src/interface/rgb21.rs b/std/src/interface/rgb21.rs index 6b73fd53..96f13e53 100644 --- a/std/src/interface/rgb21.rs +++ b/std/src/interface/rgb21.rs @@ -18,3 +18,378 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + +#![allow(unused_braces)] + +use std::collections::BTreeMap; +use std::fmt::{self, Debug, Formatter}; +use std::str::FromStr; + +use amplify::ascii::AsciiString; +use amplify::confinement::{Confined, NonEmptyVec, SmallBlob, SmallOrdSet}; +use bp::bc::stl::bitcoin_stl; +use strict_encoding::stl::AsciiPrintable; +use strict_encoding::{ + InvalidIdent, StrictDeserialize, StrictDumb, StrictEncode, StrictSerialize, TypedWrite, +}; +use strict_types::stl::std_stl; +use strict_types::typelib::{LibBuilder, TranslateError}; +use strict_types::TypeLib; + +use super::{ + AssignIface, GenesisIface, GlobalIface, Iface, OwnedIface, Req, TransitionIface, VerNo, +}; +use crate::interface::ArgSpec; +use crate::stl::{ + rgb_contract_stl, Details, MediaType, Name, ProofOfReserves, StandardTypes, Ticker, +}; + +pub const LIB_NAME_RGB21: &str = "RGB21"; +/// Strict types id for the library providing data types for RGB21 interface. +pub const LIB_ID_RGB21: &str = + "express_lexicon_penguin_CwXVUoq1fEobWoRsfwdWqEBXRTdWK7BxFpR5dtJtBJrg"; + +#[derive( + Wrapper, WrapperMut, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default, From +)] +#[wrapper(Display, FromStr, Add, Sub, Mul, Div, Rem)] +#[wrapper_mut(AddAssign, SubAssign, MulAssign, DivAssign, RemAssign)] +#[derive(StrictType, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB21)] +struct ItemsCount(u32); + +#[derive( + Wrapper, WrapperMut, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default, From +)] +#[wrapper(Display, FromStr, Add, Sub, Mul, Div, Rem)] +#[wrapper_mut(AddAssign, SubAssign, MulAssign, DivAssign, RemAssign)] +#[derive(StrictType, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB21)] +struct TokenIndex(u32); + +#[derive( + Wrapper, WrapperMut, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default, From +)] +#[wrapper(Display, FromStr, Add, Sub, Mul, Div, Rem)] +#[wrapper_mut(AddAssign, SubAssign, MulAssign, DivAssign, RemAssign)] +#[derive(StrictType, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB21)] +struct OwnedFraction(u64); + +#[derive(Clone, Eq, PartialEq, Hash, Debug, Default)] +#[derive(StrictType, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB21)] +struct IssueMeta { + pub reserves: SmallOrdSet, +} +impl StrictSerialize for IssueMeta {} +impl StrictDeserialize for IssueMeta {} + +#[derive(Clone, Eq, PartialEq, Hash, Debug, Default)] +#[derive(StrictType, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB21)] +struct Allocation(TokenIndex, OwnedFraction); + +#[derive(Clone, Eq, PartialEq, Hash, Debug)] +#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB21)] +struct EngravingData { + pub applied_to: TokenIndex, + pub content: EmbeddedMedia, +} + +#[derive(Clone, Eq, PartialEq, Hash, Debug)] +#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB21)] +struct EmbeddedMedia { + pub ty: MediaType, + pub data: SmallBlob, +} + +#[derive(Clone, Eq, PartialEq, Hash, Debug)] +#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB21)] +struct Attachment { + #[strict_type(rename = "type")] + pub ty: MediaType, + pub digest: [u8; 32], +} + +#[derive(Clone, Eq, PartialEq, Hash, Debug)] +#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB21, dumb = { AttachmentType::with(0, "dumb") })] +struct AttachmentType { + pub id: u8, + pub name: AttachmentName, +} + +impl AttachmentType { + pub fn with(id: u8, name: &'static str) -> AttachmentType { + AttachmentType { + id, + name: AttachmentName::from(name), + } + } +} + +#[derive(Wrapper, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, From)] +#[wrapper(Deref, Display)] +#[derive(StrictType, StrictDumb, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB21, dumb = { AttachmentName::from("dumb") })] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", transparent) +)] +struct AttachmentName(Confined); +impl StrictEncode for AttachmentName { + fn strict_encode(&self, writer: W) -> std::io::Result { + writer.write_newtype::( + &NonEmptyVec::::try_from_iter([AsciiPrintable::strict_dumb()]) + .unwrap(), + ) + } +} + +// TODO: Ensure all constructors filter invalid characters +impl FromStr for AttachmentName { + type Err = InvalidIdent; + + fn from_str(s: &str) -> Result { + let s = AsciiString::from_ascii(s.as_bytes())?; + let s = Confined::try_from_iter(s.chars())?; + Ok(Self(s)) + } +} + +impl From<&'static str> for AttachmentName { + fn from(s: &'static str) -> Self { Self::from_str(s).expect("invalid attachment name") } +} + +impl TryFrom for AttachmentName { + type Error = InvalidIdent; + + fn try_from(name: String) -> Result { + let name = AsciiString::from_ascii(name.as_bytes())?; + let s = Confined::try_from(name)?; + Ok(Self(s)) + } +} + +impl Debug for AttachmentName { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.debug_tuple("AttachmentName") + .field(&self.as_str()) + .finish() + } +} + +#[derive(Clone, Eq, PartialEq, Hash, Debug, Default)] +#[derive(StrictType, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB21)] +struct TokenData { + pub index: TokenIndex, + pub ticker: Option, + pub name: Option, + pub details: Option
, + pub preview: Option, + pub media: Option, + pub attachments: Confined, 0, 20>, + pub reserves: Option, +} + +const FRACTION_OVERFLOW: u8 = 1; +const NON_EQUAL_VALUES: u8 = 2; +const INVALID_PROOF: u8 = 3; +const INSUFFICIENT_RESERVES: u8 = 4; +const ISSUE_EXCEEDS_ALLOWANCE: u8 = 6; +const NON_FRACTIONAL_TOKEN: u8 = 7; +const NON_ENGRAVABLE_TOKEN: u8 = 8; +const INVALID_ATTACHMENT_TYPE: u8 = 9; + +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] +#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] +#[strict_type(lib = LIB_NAME_RGB21, tags = repr, into_u8, try_from_u8)] +#[repr(u8)] +pub enum Error { + #[strict_type(dumb)] + /// amount of token > 1 + FractionOverflow = FRACTION_OVERFLOW, + NonEqualValues = NON_EQUAL_VALUES, + InvalidProof = INVALID_PROOF, + InsufficientReserves = INSUFFICIENT_RESERVES, + IssueExceedsAllowance = ISSUE_EXCEEDS_ALLOWANCE, + NonFractionalToken = NON_FRACTIONAL_TOKEN, + NonEngravableToken = NON_ENGRAVABLE_TOKEN, + InvalidAttachmentType = INVALID_ATTACHMENT_TYPE, +} + +fn _rgb21_stl() -> Result { + LibBuilder::new(libname!(LIB_NAME_RGB21)) + .transpile::() + .transpile::() + .transpile::() + .transpile::() + .transpile::() + .transpile::() + .transpile::() + .compile(bset! { + std_stl().to_dependency(), + bitcoin_stl().to_dependency(), + rgb_contract_stl().to_dependency() + }) +} + +/// Generates strict type library providing data types for RGB21 interface. +pub fn rgb21_stl() -> TypeLib { _rgb21_stl().expect("invalid strict type RGB21 library") } + +pub fn rgb21() -> Iface { + let types = StandardTypes::with(rgb21_stl()); + + Iface { + version: VerNo::V1, + name: tn!("RGB21"), + global_state: tiny_bmap! { + fname!("spec") => GlobalIface::required(types.get("RGBContract.DivisibleAssetSpec")), + fname!("terms") => GlobalIface::required(types.get("RGBContract.RicardianContract")), + fname!("created") => GlobalIface::required(types.get("RGBContract.Timestamp")), + fname!("tokens") => GlobalIface::none_or_many(types.get("RGB21.TokenData")), + fname!("engravings") => GlobalIface::none_or_many(types.get("RGB21.EngravingData")), + fname!("attachmentTypes") => GlobalIface::none_or_many(types.get("RGB21.AttachmentType")), + }, + assignments: tiny_bmap! { + fname!("inflationAllowance") => AssignIface::public(OwnedIface::Data(types.get("RGB21.ItemsCount")), Req::NoneOrMore), + fname!("updateRight") => AssignIface::public(OwnedIface::Rights, Req::Optional), + fname!("assetOwner") => AssignIface::private(OwnedIface::Data(types.get("RGB21.Allocation")), Req::NoneOrMore), + }, + valencies: none!(), + genesis: GenesisIface { + metadata: Some(types.get("RGB21.IssueMeta")), + global: tiny_bmap! { + fname!("spec") => ArgSpec::required(), + fname!("terms") => ArgSpec::required(), + fname!("created") => ArgSpec::required(), + fname!("tokens") => ArgSpec::many(), + fname!("attachmentTypes") => ArgSpec::many(), + }, + assignments: tiny_bmap! { + fname!("assetOwner") => ArgSpec::many(), + fname!("inflationAllowance") => ArgSpec::many(), + fname!("updateRight") => ArgSpec::optional(), + }, + valencies: none!(), + errors: tiny_bset! { + FRACTION_OVERFLOW, + INVALID_PROOF, + INSUFFICIENT_RESERVES, + INVALID_ATTACHMENT_TYPE + }, + }, + transitions: tiny_bmap! { + tn!("Transfer") => TransitionIface { + optional: false, + metadata: None, + globals: none!(), + inputs: tiny_bmap! { + fname!("previous") => ArgSpec::from_non_empty("assetOwner"), + }, + assignments: tiny_bmap! { + fname!("beneficiary") => ArgSpec::from_non_empty("assetOwner"), + }, + valencies: none!(), + errors: tiny_bset! { + NON_EQUAL_VALUES, + FRACTION_OVERFLOW, + NON_FRACTIONAL_TOKEN + }, + default_assignment: Some(fname!("beneficiary")), + }, + tn!("Engrave") => TransitionIface { + optional: true, + metadata: None, + globals: tiny_bmap! { + fname!("engravings") => ArgSpec::required(), + }, + inputs: tiny_bmap! { + fname!("previous") => ArgSpec::from_non_empty("assetOwner"), + }, + assignments: tiny_bmap! { + fname!("beneficiary") => ArgSpec::from_non_empty("assetOwner"), + }, + valencies: none!(), + errors: tiny_bset! { + NON_EQUAL_VALUES, + FRACTION_OVERFLOW, + NON_FRACTIONAL_TOKEN, + NON_ENGRAVABLE_TOKEN + }, + default_assignment: Some(fname!("beneficiary")), + }, + tn!("Issue") => TransitionIface { + optional: true, + metadata: Some(types.get("RGB21.IssueMeta")), + globals: tiny_bmap! { + fname!("newTokens") => ArgSpec::from_many("tokens"), + fname!("newAttachmentTypes") => ArgSpec::from_many("attachmentTypes"), + }, + inputs: tiny_bmap! { + fname!("used") => ArgSpec::from_non_empty("inflationAllowance"), + }, + assignments: tiny_bmap! { + fname!("beneficiary") => ArgSpec::from_many("assetOwner"), + fname!("future") => ArgSpec::from_many("inflationAllowance"), + }, + valencies: none!(), + errors: tiny_bset! { + FRACTION_OVERFLOW, + INVALID_PROOF, + INSUFFICIENT_RESERVES, + INVALID_ATTACHMENT_TYPE, + ISSUE_EXCEEDS_ALLOWANCE, + }, + default_assignment: Some(fname!("beneficiary")), + }, + tn!("Rename") => TransitionIface { + optional: true, + metadata: None, + globals: tiny_bmap! { + fname!("new") => ArgSpec::from_required("spec"), + }, + inputs: tiny_bmap! { + fname!("used") => ArgSpec::from_required("updateRight"), + }, + assignments: tiny_bmap! { + fname!("future") => ArgSpec::from_optional("updateRight"), + }, + valencies: none!(), + errors: none!(), + default_assignment: Some(fname!("future")), + }, + }, + extensions: none!(), + error_type: types.get("RGB21.Error"), + default_operation: Some(tn!("Transfer")), + } +} + +#[cfg(test)] +mod test { + use super::*; + use crate::containers::BindleContent; + + const RGB21: &str = include_str!("../../tests/data/rgb21.rgba"); + + #[test] + fn lib_id() { + let lib = rgb21_stl(); + assert_eq!(lib.id().to_string(), LIB_ID_RGB21); + } + + #[test] + fn iface_creation() { rgb21(); } + + #[test] + fn iface_bindle() { + assert_eq!(format!("{}", rgb21().bindle()), RGB21); + } +} diff --git a/std/tests/data/rgb21.rgba b/std/tests/data/rgb21.rgba new file mode 100644 index 00000000..c897ea98 --- /dev/null +++ b/std/tests/data/rgb21.rgba @@ -0,0 +1,29 @@ +-----BEGIN RGB INTERFACE----- +Id: 6Se5zVRA81aXmaybzyNpo2yj2z6jowYnev3awVWG1w4P +Name: RGB21 + +AAVSR0IyMQYPYXR0YWNobWVudFR5cGVzAYadjHl/3bNf7942lcLfTuzlt245mXs+ +0naU/n6DU5n2AAEHY3JlYXRlZAHK0bud73JnqPaARSzjY0/ngU2l+kvpLKccXt8S +5qHkMAEACmVuZ3JhdmluZ3MBKsfhWc3PLkeQ2DfUfRjoAmdkGR/nb4U4a6RPEdY8 +Kk0AAQRzcGVjAXEb91tMkPjmLh7Tn4j0rGsW+l/fNNy+o7N/vJ4En1+oAQAFdGVy +bXMBsL+2/g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WZpY2lhcnkBCmFz +c2V0T3duZXIBAP//AAMBAgcBC2JlbmVmaWNpYXJ5AJBIISytLtbgmj6FPJBPcYiS +huF+wj0KO2Mm7O5yG3uZAQhUcmFuc2Zlcg== + +-----END RGB INTERFACE----- diff --git a/stl/RGB21@0.1.0.sta b/stl/RGB21@0.1.0.sta new file mode 100644 index 00000000..b0f14d47 --- /dev/null +++ b/stl/RGB21@0.1.0.sta @@ -0,0 +1,46 @@ +-----BEGIN STRICT TYPE LIB----- +Id: express_lexicon_penguin_CwXVUoq1fEobWoRsfwdWqEBXRTdWK7BxFpR5dtJtBJrg +Name: RGB21 +Dependencies: + Std@quota_conan_fashion_3TZmAPf8EkQZnbGS1g8uMGes6jEWPqNkFB6pLUKeoefg, + RGBContract@level_decide_percent_6z2gZQEJsnP4xoNUC94vqYEE9V7gKQbeJhb5521xta5u, + Bitcoin@cubic_filter_vampire_AqBBP1ZeTXrdAePf6SBcUGbttpvxpHKG7uJLKFkVxtGi + +BVJHQjIxAySFhLGjG96fdR4TFEG0AGzfutGiP5FohicaA084WrP3A1N0ZFjmcVEa +BmUvNnuaNhdNwvUqhXbh6gDg28jkixwjzddoC1JHQkNvbnRyYWN0khCSD+5t80ap +bygpkiw4UYjv0hOwwSfKS+1eTBW9YXMHQml0Y29pbgwACkFsbG9jYXRpb24FAgEK +VG9rZW5JbmRleNOEYZKk80SR5kMm4dx7RhTXXaWwe/SieERqYv7mLXZkAQ1Pd25l +ZEZyYWN0aW9uCTF+E2fA7bv/+2dbUynWVUoOxiWAxeWlIVrzGCcKiLMKQXR0YWNo +bWVudAYCBHR5cGUCCU1lZGlhVHlwZQtSR0JDb250cmFjdBYUl51fFWFkEWGDVwKr +c/8khH/gDVtC0/gQdUm4zVeqBmRpZ2VzdAAHAABAIAAOQXR0YWNobWVudE5hbWUF +AQAIAg5Bc2NpaVByaW50YWJsZQNTdGRVrM0L04UH/5W1FM8zvDuwSzezztFtcHT0 +0n7nafhwiwEAAAAAAAAAFAAAAA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7U0Yx +EKkBxZ/+VnD5zxC6z44m6lqAKxbNs+dfuwdkZXRhaWxzAAQCAARub25lAAAAAQRz +b21lAAUBAgdEZXRhaWxzC1JHQkNvbnRyYWN0kSgbswmCVaArRuj2jp5QvyOk83l1 +BaE9VP/gqDbRBGkHcHJldmlldwAEAgAEbm9uZQAAAAEEc29tZQAFAQENRW1iZWRk +ZWRNZWRpYc8yN4uoeVSNzHrBzWthtiiBwilIovB1rd5JQzi9XZi3BW1lZGlhAAQC +AARub25lAAAAAQRzb21lAAUBAQpBdHRhY2htZW50wRZmeN6ujgdSZSqbvuHAULOg +c3qAKwFiBBCdrT1OJGQLYXR0YWNobWVudHMACgABAQpBdHRhY2htZW50wRZmeN6u +jgdSZSqbvuHAULOgc3qAKwFiBBCdrT1OJGQAAAAAAAAAABQAAAAAAAAACHJlc2Vy +dmVzAAQCAARub25lAAAAAQRzb21lAAUBAg9Qcm9vZk9mUmVzZXJ2ZXMLUkdCQ29u +dHJhY3S6A6JqlDC0xrIg5HDyvbzYYjoMf7g5GsQVjl3ey3a8gApUb2tlbkluZGV4 +BQEAAAQ= + +-----END STRICT TYPE LIB----- + diff --git a/stl/RGB21@0.1.0.stl b/stl/RGB21@0.1.0.stl new file mode 100644 index 0000000000000000000000000000000000000000..97d636cf62b62327bd00530503c4595d0eac15d6 GIT binary patch literal 1637 zcmZP#a(6N^WL9Zy*|=Ex-uzNIVG+kI3_16AU0h^8F{4dgirL>HYV&vI;F6SxXN7@M zY^nNY)w9gReGh%rYAt*Cis8ZS6HmHjl+Rwz;07AyoS#=xl$cyHNnjHHyWG!iEAurp zC+S!OcD%nNyy2kwDet#&KB9XQi`ktrOOo?5^LQAz9CLE=lM_oa^Yd7l7`a07vs3dt z^HNePF1I93TJqUt;xlKphj*&oM6Sm!-BA5yQH4uZ(!XcAWhsoj{^fb8DQ+O^fSNfC z>x9z}yxsl(cY1WN=Cx2SzGJElN1rZLjQT90&egG*%dw;+F*zeQHLrw?iKV2nAeD*J zH#H?QF$Bm&cDk6z^tth(i7A4K&EZU|i~p;%)IZ>jcDnpSpwx56+3;0tDVgc1#U%{v z3=9qm415S<{StFiSs58PnD`uvlQS~|iZb&`5|eULL17oV<}CN+R`&l>w~CxM-ebMN z+kEr6i@60QUoO=>&-_u)&By=&B2XI1SdjbJn3ytC7#J8?@_=?QB1wYmoFTd4$4<+ zWk~Ots)J{<6SrwJ9@6w!^r3X^Jx^zgy|FX4v$_@)GfX#Q-Ka(WGT+iO=VzZWMT^eOCoz>CK!?p$oL#UVQ7D7qDM>$>+*a)`hkq{~xR{yU3EsUQm=; zmYG_P)kIR0XfCLz!EO>#$#hUGt>WIgKK7tgt=an?9thaHpt!0*n=y$+VD4I5Ka~{j jM0g=q%)rIK$Vh@-SZaY4F^E)%H99Ftm`J5KI3WT6E96}x literal 0 HcmV?d00001 diff --git a/stl/RGB21@0.1.0.sty b/stl/RGB21@0.1.0.sty new file mode 100644 index 00000000..83aa2253 --- /dev/null +++ b/stl/RGB21@0.1.0.sty @@ -0,0 +1,39 @@ +{- + Id: express_lexicon_penguin_CwXVUoq1fEobWoRsfwdWqEBXRTdWK7BxFpR5dtJtBJrg + Name: RGB21 + Version: 0.1.0 + Description: Types for RGB21 interface + Author: Dr Maxim Orlovsky + Copyright (C) 2023 LNP/BP Standards Association. All rights reserved. + License: Apache-2.0 +-} + +typelib RGB21 -- express_lexicon_penguin_CwXVUoq1fEobWoRsfwdWqEBXRTdWK7BxFpR5dtJtBJrg + +import quota_conan_fashion_3TZmAPf8EkQZnbGS1g8uMGes6jEWPqNkFB6pLUKeoefg as Std +import level_decide_percent_6z2gZQEJsnP4xoNUC94vqYEE9V7gKQbeJhb5521xta5u as RGBContract +import cubic_filter_vampire_AqBBP1ZeTXrdAePf6SBcUGbttpvxpHKG7uJLKFkVxtGi as Bitcoin + + +data Allocation :: TokenIndex, OwnedFraction +data Attachment :: type RGBContract.MediaType, digest [Byte ^ 32] +data AttachmentName :: [Std.AsciiPrintable ^ 1..0x14] +data AttachmentType :: id U8, name AttachmentName +data EmbeddedMedia :: ty RGBContract.MediaType, data [Byte] +data EngravingData :: appliedTo TokenIndex, content EmbeddedMedia +data Error :: fractionOverflow:1 | nonEqualValues:2 | invalidProof:3 | insufficientReserves:4 + | issueExceedsAllowance:6 | nonFractionalToken:7 | nonEngravableToken:8 | invalidAttachmentType:9 + +data IssueMeta :: reserves {RGBContract.ProofOfReserves} +data ItemsCount :: U32 +data OwnedFraction :: U64 +data TokenData :: index TokenIndex + , ticker RGBContract.Ticker? + , name RGBContract.Name? + , details RGBContract.Details? + , preview EmbeddedMedia? + , media Attachment? + , attachments {U8 -> ^ ..0x14 Attachment} + , reserves RGBContract.ProofOfReserves? +data TokenIndex :: U32 + From 303b973ab685756a777da128547617c120ad8fa4 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 20:52:30 +0200 Subject: [PATCH 29/33] chore: update dependencies --- Cargo.lock | 55 ++++++++++++++++++++++++++++++++---------------------- Cargo.toml | 18 +++++------------- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 03bd0a11..4764ef49 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,8 +4,9 @@ version = 3 [[package]] name = "aluvm" -version = "0.10.1" -source = "git+https://github.com/AluVM/rust-aluvm#dd7410778ff2a9fe5808447a9efeb55ccbc68c54" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ebb162f495c9b467476c4287fbdf5afaf816a9c91c7e37de9d0ff13804ef502" dependencies = [ "amplify", "baid58", @@ -221,8 +222,9 @@ dependencies = [ [[package]] name = "bp-core" -version = "0.10.2" -source = "git+https://github.com/BP-WG/bp-core?branch=stl#f35d19a2ef7f329bb84813f8a2e37eb6ee97eeec" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77895cc1d62865613d3c2aa0331de273974c4901fe00ecbdbd51fe69337a9bda" dependencies = [ "amplify", "bp-dbc", @@ -237,8 +239,9 @@ dependencies = [ [[package]] name = "bp-dbc" -version = "0.10.2" -source = "git+https://github.com/BP-WG/bp-core?branch=stl#f35d19a2ef7f329bb84813f8a2e37eb6ee97eeec" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa85f689829ecbb13f56cc9e06ebf3c101bdd4df85fc10049df080f997020e26" dependencies = [ "amplify", "baid58", @@ -251,8 +254,9 @@ dependencies = [ [[package]] name = "bp-primitives" -version = "0.10.2" -source = "git+https://github.com/BP-WG/bp-core?branch=stl#f35d19a2ef7f329bb84813f8a2e37eb6ee97eeec" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e69ae41e82b139784dc3fd8318a8a892d75300954c6bfc0ab16c4a056745602" dependencies = [ "amplify", "commit_verify", @@ -264,8 +268,9 @@ dependencies = [ [[package]] name = "bp-seals" -version = "0.10.2" -source = "git+https://github.com/BP-WG/bp-core?branch=stl#f35d19a2ef7f329bb84813f8a2e37eb6ee97eeec" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b3380f6c3cb42f4ebf3b39bde6239381481097d70594729f630db46c3bee9b0" dependencies = [ "amplify", "baid58", @@ -321,7 +326,8 @@ dependencies = [ [[package]] name = "commit_encoding_derive" version = "0.10.0" -source = "git+https://github.com/LNP-BP/client_side_validation?branch=stl#317d594d2c3d252bcb7d1a493cd49a04a320c3c9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00033f14d67c4169d588f085ea2faeb7b610cf03a74d42ea09eeba31abef2047" dependencies = [ "amplify", "amplify_syn", @@ -332,8 +338,9 @@ dependencies = [ [[package]] name = "commit_verify" -version = "0.10.1" -source = "git+https://github.com/LNP-BP/client_side_validation?branch=stl#317d594d2c3d252bcb7d1a493cd49a04a320c3c9" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1baccabac24e468b317b3a627fa0a07e2708f9efbad2d1b44eb64fe993f7c621" dependencies = [ "amplify", "commit_encoding_derive", @@ -641,9 +648,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.56" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +checksum = "c4ec6d5fe0b140acb27c9a0444118cf55bfbb4e0b259739429abb4521dd67c16" dependencies = [ "unicode-ident", ] @@ -689,8 +696,9 @@ dependencies = [ [[package]] name = "rgb-core" -version = "0.10.2" -source = "git+https://github.com/RGB-WG/rgb-core?branch=stl#a643a04b0ba287511d1069715e23942b690fc7ca" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f265335d2ea2ac9b36f52cf7b34e0aaa10e48e502d56111d4dde0b6edf98647" dependencies = [ "aluvm", "amplify", @@ -906,8 +914,9 @@ dependencies = [ [[package]] name = "strict_encoding" -version = "2.1.2" -source = "git+https://github.com/strict-types/strict-encoding?branch=stl#09c260290112897b913a1fe025bb9c12c73785dd" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fff0b729ca136cddccc87481dd932a442133a12a490f349d67f5d4c20b421e5" dependencies = [ "amplify", "half", @@ -918,7 +927,8 @@ dependencies = [ [[package]] name = "strict_encoding_derive" version = "2.0.0" -source = "git+https://github.com/strict-types/strict-encoding?branch=stl#09c260290112897b913a1fe025bb9c12c73785dd" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f5adae55367464f5a229bfd539682c94f870b98a220be6e61dc43f85d612e7e" dependencies = [ "amplify_syn", "heck", @@ -929,8 +939,9 @@ dependencies = [ [[package]] name = "strict_types" -version = "1.1.1" -source = "git+https://github.com/strict-types/strict-types?branch=fix/typesys-builder#e34c1c64488a064334cb7abdc5dccab9d74a2ae2" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7af86f31fce50e8e4635509b6114c71aaa3a37cb3df1b8ea0ab5d5cf58afd688" dependencies = [ "amplify", "baid58", diff --git a/Cargo.toml b/Cargo.toml index e69528fe..d0a55425 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,11 +19,11 @@ license = "Apache-2.0" [workspace.dependencies] amplify = "4.0.0" baid58 = "0.3.1" -strict_encoding = "2.1.2" -strict_types = "1.1.1" -commit_verify = "0.10.1" -bp-core = "0.10.2" -rgb-core = "0.10.2" +strict_encoding = "2.2.0" +strict_types = "1.2.0" +commit_verify = "0.10.2" +bp-core = "0.10.3" +rgb-core = "0.10.3" [package] name = "rgb-wallet" @@ -77,11 +77,3 @@ wasm-bindgen-test = "0.3" [package.metadata.docs.rs] features = [ "all" ] - -[patch.crates-io] -strict_encoding = { git = "https://github.com/strict-types/strict-encoding", branch = "stl" } -strict_types = { git = "https://github.com/strict-types/strict-types", branch = "fix/typesys-builder" } -commit_verify = { git = "https://github.com/LNP-BP/client_side_validation", branch = "stl" } -bp-core = { git = "https://github.com/BP-WG/bp-core", branch = "stl" } -aluvm = { git = "https://github.com/AluVM/rust-aluvm" } -rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "stl" } From 4b2118407bb4e8300463f21a628001289d3a3728 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 21:09:24 +0200 Subject: [PATCH 30/33] chore: remove stl feature --- .github/workflows/build.yml | 1 - Cargo.toml | 9 ++++----- std/Cargo.toml | 4 +--- std/src/lib.rs | 4 +--- std/src/stl/mod.rs | 1 + 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fe1f26f0..4b1e6717 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,7 +30,6 @@ jobs: fail-fast: false matrix: feature: - - stl - fs - serde steps: diff --git a/Cargo.toml b/Cargo.toml index d0a55425..fea734b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,9 +21,9 @@ amplify = "4.0.0" baid58 = "0.3.1" strict_encoding = "2.2.0" strict_types = "1.2.0" -commit_verify = "0.10.2" -bp-core = "0.10.3" -rgb-core = "0.10.3" +commit_verify = { version = "0.10.2", features = ["stl"] } +bp-core = { version = "0.10.3", features = ["stl"] } +rgb-core = { version = "0.10.3", features = ["stl"] } [package] name = "rgb-wallet" @@ -62,8 +62,7 @@ percent-encoding = "2.2.0" [features] default = [] -all = ["fs", "serde", "stl"] -stl = ["rgb-std/stl"] +all = ["fs", "serde"] serde = ["rgb-std/serde", "rgb-core/serde"] fs = ["rgb-std/fs"] diff --git a/std/Cargo.toml b/std/Cargo.toml index 08c639be..a5a2fbe8 100644 --- a/std/Cargo.toml +++ b/std/Cargo.toml @@ -18,7 +18,6 @@ crate-type = ["cdylib", "rlib"] # We need this for WASM [[bin]] name = "rgb-stl" -required-features = ["stl"] [dependencies] amplify = { workspace = true } @@ -33,8 +32,7 @@ serde_crate = { package = "serde", version = "1", features = ["derive"] } [features] default = [] -all = ["fs", "serde", "stl"] -stl = ["commit_verify/stl", "bp-core/stl", "rgb-core/stl"] +all = ["fs", "serde"] serde = [ "amplify/serde", "strict_encoding/serde", "strict_types/serde", diff --git a/std/src/lib.rs b/std/src/lib.rs index eb4039f7..e954cb12 100644 --- a/std/src/lib.rs +++ b/std/src/lib.rs @@ -78,7 +78,6 @@ extern crate serde_crate as serde; pub use rgb::{contract, schema, validation, vm}; -#[cfg(feature = "stl")] pub mod stl; pub mod interface; pub mod containers; @@ -87,5 +86,4 @@ pub mod resolvers; pub mod accessors; pub use bp::{Chain, Outpoint, Txid}; - -pub const LIB_NAME_RGB_STD: &str = "RGBStd"; +pub use stl::{LIB_NAME_RGB_CONTRACT, LIB_NAME_RGB_STD}; diff --git a/std/src/stl/mod.rs b/std/src/stl/mod.rs index 668e02e9..5c79ea5c 100644 --- a/std/src/stl/mod.rs +++ b/std/src/stl/mod.rs @@ -34,3 +34,4 @@ pub use specs::{ pub use stl::{rgb_contract_stl, StandardTypes, LIB_ID_RGB_CONTRACT}; pub const LIB_NAME_RGB_CONTRACT: &str = "RGBContract"; +pub const LIB_NAME_RGB_STD: &str = "RGBStd"; From afe4f82279f681931cca4a9e07d690d22cd1bb2b Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 21:11:16 +0200 Subject: [PATCH 31/33] iface: export rgb20 and rgb21 modules and types --- scripts/typelib.sh | 6 +++--- std/src/interface/mod.rs | 4 ++-- std/src/interface/rgb20.rs | 6 +++--- std/src/interface/rgb21.rs | 22 +++++++++++----------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/scripts/typelib.sh b/scripts/typelib.sh index 94d1e1ad..34d2fe78 100755 --- a/scripts/typelib.sh +++ b/scripts/typelib.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -cargo run --features stl --bin rgb-stl -- --sty -cargo run --features stl --bin rgb-stl -- --stl -cargo run --features stl --bin rgb-stl -- --sta +cargo run --bin rgb-stl -- --sty +cargo run --bin rgb-stl -- --stl +cargo run --bin rgb-stl -- --sta diff --git a/std/src/interface/mod.rs b/std/src/interface/mod.rs index 5bc0ddf6..17adf5ab 100644 --- a/std/src/interface/mod.rs +++ b/std/src/interface/mod.rs @@ -27,8 +27,8 @@ mod iface; mod iimpl; mod contract; mod builder; -mod rgb20; -mod rgb21; +pub mod rgb20; +pub mod rgb21; mod suppl; pub use builder::{BuilderError, ContractBuilder, OperationBuilder, TransitionBuilder}; diff --git a/std/src/interface/rgb20.rs b/std/src/interface/rgb20.rs index 96d1d491..708f173f 100644 --- a/std/src/interface/rgb20.rs +++ b/std/src/interface/rgb20.rs @@ -42,12 +42,12 @@ pub const LIB_ID_RGB20: &str = "giant_eagle_capsule_9QCXsi6d26jqNQVszMAYUDffRjwU #[wrapper_mut(AddAssign, SubAssign, MulAssign, DivAssign, RemAssign)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB20)] -struct Amount(u64); +pub struct Amount(u64); #[derive(Clone, Eq, PartialEq, Hash, Debug, Default)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB20)] -struct IssueMeta { +pub struct IssueMeta { pub reserves: SmallOrdSet, } impl StrictSerialize for IssueMeta {} @@ -56,7 +56,7 @@ impl StrictDeserialize for IssueMeta {} #[derive(Clone, Eq, PartialEq, Hash, Debug, Default)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB20)] -struct BurnMeta { +pub struct BurnMeta { pub burn_proofs: SmallOrdSet, } impl StrictSerialize for BurnMeta {} diff --git a/std/src/interface/rgb21.rs b/std/src/interface/rgb21.rs index 96f13e53..23e7928b 100644 --- a/std/src/interface/rgb21.rs +++ b/std/src/interface/rgb21.rs @@ -56,7 +56,7 @@ pub const LIB_ID_RGB21: &str = #[wrapper_mut(AddAssign, SubAssign, MulAssign, DivAssign, RemAssign)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] -struct ItemsCount(u32); +pub struct ItemsCount(u32); #[derive( Wrapper, WrapperMut, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default, From @@ -65,7 +65,7 @@ struct ItemsCount(u32); #[wrapper_mut(AddAssign, SubAssign, MulAssign, DivAssign, RemAssign)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] -struct TokenIndex(u32); +pub struct TokenIndex(u32); #[derive( Wrapper, WrapperMut, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default, From @@ -74,12 +74,12 @@ struct TokenIndex(u32); #[wrapper_mut(AddAssign, SubAssign, MulAssign, DivAssign, RemAssign)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] -struct OwnedFraction(u64); +pub struct OwnedFraction(u64); #[derive(Clone, Eq, PartialEq, Hash, Debug, Default)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] -struct IssueMeta { +pub struct IssueMeta { pub reserves: SmallOrdSet, } impl StrictSerialize for IssueMeta {} @@ -88,12 +88,12 @@ impl StrictDeserialize for IssueMeta {} #[derive(Clone, Eq, PartialEq, Hash, Debug, Default)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] -struct Allocation(TokenIndex, OwnedFraction); +pub struct Allocation(TokenIndex, OwnedFraction); #[derive(Clone, Eq, PartialEq, Hash, Debug)] #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] -struct EngravingData { +pub struct EngravingData { pub applied_to: TokenIndex, pub content: EmbeddedMedia, } @@ -101,7 +101,7 @@ struct EngravingData { #[derive(Clone, Eq, PartialEq, Hash, Debug)] #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] -struct EmbeddedMedia { +pub struct EmbeddedMedia { pub ty: MediaType, pub data: SmallBlob, } @@ -109,7 +109,7 @@ struct EmbeddedMedia { #[derive(Clone, Eq, PartialEq, Hash, Debug)] #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] -struct Attachment { +pub struct Attachment { #[strict_type(rename = "type")] pub ty: MediaType, pub digest: [u8; 32], @@ -118,7 +118,7 @@ struct Attachment { #[derive(Clone, Eq, PartialEq, Hash, Debug)] #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21, dumb = { AttachmentType::with(0, "dumb") })] -struct AttachmentType { +pub struct AttachmentType { pub id: u8, pub name: AttachmentName, } @@ -141,7 +141,7 @@ impl AttachmentType { derive(Serialize, Deserialize), serde(crate = "serde_crate", transparent) )] -struct AttachmentName(Confined); +pub struct AttachmentName(Confined); impl StrictEncode for AttachmentName { fn strict_encode(&self, writer: W) -> std::io::Result { writer.write_newtype::( @@ -187,7 +187,7 @@ impl Debug for AttachmentName { #[derive(Clone, Eq, PartialEq, Hash, Debug, Default)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] -struct TokenData { +pub struct TokenData { pub index: TokenIndex, pub ticker: Option, pub name: Option, From 8680142ccc9d93badebd117d80a04ceb23e1de98 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 21:16:52 +0200 Subject: [PATCH 32/33] ifaces: fix type field name in RGB21 EmbeddedMedia structure --- std/src/interface/rgb21.rs | 4 +-- std/tests/data/rgb21.rgba | 10 +++---- stl/RGB21@0.1.0.sta | 52 ++++++++++++++++++------------------- stl/RGB21@0.1.0.stl | Bin 1637 -> 1639 bytes stl/RGB21@0.1.0.sty | 6 ++--- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/std/src/interface/rgb21.rs b/std/src/interface/rgb21.rs index 23e7928b..dfe997b3 100644 --- a/std/src/interface/rgb21.rs +++ b/std/src/interface/rgb21.rs @@ -46,8 +46,7 @@ use crate::stl::{ pub const LIB_NAME_RGB21: &str = "RGB21"; /// Strict types id for the library providing data types for RGB21 interface. -pub const LIB_ID_RGB21: &str = - "express_lexicon_penguin_CwXVUoq1fEobWoRsfwdWqEBXRTdWK7BxFpR5dtJtBJrg"; +pub const LIB_ID_RGB21: &str = "logic_radius_anita_HgevHFfoBcfqUMHjouxvGMtgGyvs2UrPwr6PNbyteSNb"; #[derive( Wrapper, WrapperMut, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default, From @@ -102,6 +101,7 @@ pub struct EngravingData { #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] pub struct EmbeddedMedia { + #[strict_type(rename = "type")] pub ty: MediaType, pub data: SmallBlob, } diff --git a/std/tests/data/rgb21.rgba b/std/tests/data/rgb21.rgba index c897ea98..829f9c71 100644 --- a/std/tests/data/rgb21.rgba +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..016db237 100644 --- a/stl/RGB21@0.1.0.sta +++ b/stl/RGB21@0.1.0.sta @@ -1,5 +1,5 @@ -----BEGIN STRICT TYPE LIB----- -Id: express_lexicon_penguin_CwXVUoq1fEobWoRsfwdWqEBXRTdWK7BxFpR5dtJtBJrg +Id: logic_radius_anita_HgevHFfoBcfqUMHjouxvGMtgGyvs2UrPwr6PNbyteSNb Name: RGB21 Dependencies: Std@quota_conan_fashion_3TZmAPf8EkQZnbGS1g8uMGes6jEWPqNkFB6pLUKeoefg, @@ -16,31 +16,31 @@ c/8khH/gDVtC0/gQdUm4zVeqBmRpZ2VzdAAHAABAIAAOQXR0YWNobWVudE5hbWUF AQAIAg5Bc2NpaVByaW50YWJsZQNTdGRVrM0L04UH/5W1FM8zvDuwSzezztFtcHT0 0n7nafhwiwEAAAAAAAAAFAAAAAAAAAAOQXR0YWNobWVudFR5cGUGAgJpZAAAAQRu YW1lAQ5BdHRhY2htZW50TmFtZZgZsPi5LqwPGSBXkbUBbCP3j3hWC7R9dOJmqcJL -DPM+DUVtYmVkZGVkTWVkaWEGAgJ0eQIJTWVkaWFUeXBlC1JHQkNvbnRyYWN0FhSX -nV8VYWQRYYNXAqtz/ySEf+ANW0LT+BB1SbjNV6oEZGF0YQAIAABAAAAAAAAAAAD/ -/wAAAAAAAA1FbmdyYXZpbmdEYXRhBgIJYXBwbGllZFRvAQpUb2tlbkluZGV404Rh -kqTzRJHmQybh3HtGFNddpbB79KJ4RGpi/uYtdmQHY29udGVudAENRW1iZWRkZWRN -ZWRpYc8yN4uoeVSNzHrBzWthtiiBwilIovB1rd5JQzi9XZi3BUVycm9yAwgQZnJh -Y3Rpb25PdmVyZmxvdwEObm9uRXF1YWxWYWx1ZXMCDGludmFsaWRQcm9vZgMUaW5z -dWZmaWNpZW50UmVzZXJ2ZXMEFWlzc3VlRXhjZWVkc0FsbG93YW5jZQYSbm9uRnJh -Y3Rpb25hbFRva2VuBxJub25FbmdyYXZhYmxlVG9rZW4IFWludmFsaWR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6PaOnlC/I6Tz +eXUFoT1U/+CoNtEEaQdwcmV2aWV3AAQCAARub25lAAAAAQRzb21lAAUBAQ1FbWJl +ZGRlZE1lZGlhfNwBp5iftwp+GRK3ncb8nyPwVQWgT4+GNBOv+PWmdVwFbWVkaWEA +BAIABG5vbmUAAAABBHNvbWUABQEBCkF0dGFjaG1lbnTBFmZ43q6OB1JlKpu+4cBQ +s6BzeoArAWIEEJ2tPU4kZAthdHRhY2htZW50cwAKAAEBCkF0dGFjaG1lbnTBFmZ4 +3q6OB1JlKpu+4cBQs6BzeoArAWIEEJ2tPU4kZAAAAAAAAAAAFAAAAAAAAAAIcmVz +ZXJ2ZXMABAIABG5vbmUAAAABBHNvbWUABQECD1Byb29mT2ZSZXNlcnZlcwtSR0JD +b250cmFjdLoDomqUMLTGsiDkcPK9vNhiOgx/uDkaxBWOXd7LdryAClRva2VuSW5k +ZXgFAQAABA== -----END STRICT TYPE LIB----- diff --git a/stl/RGB21@0.1.0.stl b/stl/RGB21@0.1.0.stl index 97d636cf62b62327bd00530503c4595d0eac15d6..2c49398b0af2cf8e70ef25146e61f6b33eb5a098 100644 GIT binary patch delta 99 zcmaFL^PFeHXU2)&Y$oe6l`GWTVO&0A{&uc9Nulj?kNugi{2`Qefq#FSiSYU#Uze4} cY(B!&%%nz06>Dy4N@n8Zi!7p(n^+$M0523SiU0rr delta 93 zcmaFP^OR@9XGUhGlFEs{%_r+Kl`EV#GVfkd8Pa>E>fqVz#BCalhcrDFeJEXf&(qmr UZ|scin~yOyGZ9oZIg|At00luUBme*a diff --git a/stl/RGB21@0.1.0.sty b/stl/RGB21@0.1.0.sty index 83aa2253..d5097d77 100644 --- a/stl/RGB21@0.1.0.sty +++ b/stl/RGB21@0.1.0.sty @@ -1,5 +1,5 @@ {- - Id: express_lexicon_penguin_CwXVUoq1fEobWoRsfwdWqEBXRTdWK7BxFpR5dtJtBJrg + Id: logic_radius_anita_HgevHFfoBcfqUMHjouxvGMtgGyvs2UrPwr6PNbyteSNb Name: RGB21 Version: 0.1.0 Description: Types for RGB21 interface @@ -8,7 +8,7 @@ License: Apache-2.0 -} -typelib RGB21 -- express_lexicon_penguin_CwXVUoq1fEobWoRsfwdWqEBXRTdWK7BxFpR5dtJtBJrg +typelib RGB21 -- logic_radius_anita_HgevHFfoBcfqUMHjouxvGMtgGyvs2UrPwr6PNbyteSNb import quota_conan_fashion_3TZmAPf8EkQZnbGS1g8uMGes6jEWPqNkFB6pLUKeoefg as Std import level_decide_percent_6z2gZQEJsnP4xoNUC94vqYEE9V7gKQbeJhb5521xta5u as RGBContract @@ -19,7 +19,7 @@ data Allocation :: TokenIndex, OwnedFraction data Attachment :: type RGBContract.MediaType, digest [Byte ^ 32] data AttachmentName :: [Std.AsciiPrintable ^ 1..0x14] data AttachmentType :: id U8, name AttachmentName -data EmbeddedMedia :: ty RGBContract.MediaType, data [Byte] +data EmbeddedMedia :: type RGBContract.MediaType, data [Byte] data EngravingData :: appliedTo TokenIndex, content EmbeddedMedia data Error :: fractionOverflow:1 | nonEqualValues:2 | invalidProof:3 | insufficientReserves:4 | issueExceedsAllowance:6 | nonFractionalToken:7 | nonEngravableToken:8 | invalidAttachmentType:9 From da3543ce7134d3d1825fdc487498854b6aba6a0f Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 15 May 2023 21:17:23 +0200 Subject: [PATCH 33/33] ifaces: implement serde for RGB20 and RGB21 types --- std/src/interface/rgb20.rs | 15 ++++++++++++ std/src/interface/rgb21.rs | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/std/src/interface/rgb20.rs b/std/src/interface/rgb20.rs index 708f173f..0da403b4 100644 --- a/std/src/interface/rgb20.rs +++ b/std/src/interface/rgb20.rs @@ -42,11 +42,21 @@ pub const LIB_ID_RGB20: &str = "giant_eagle_capsule_9QCXsi6d26jqNQVszMAYUDffRjwU #[wrapper_mut(AddAssign, SubAssign, MulAssign, DivAssign, RemAssign)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB20)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", transparent) +)] pub struct Amount(u64); #[derive(Clone, Eq, PartialEq, Hash, Debug, Default)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB20)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", rename_all = "camelCase") +)] pub struct IssueMeta { pub reserves: SmallOrdSet, } @@ -56,6 +66,11 @@ impl StrictDeserialize for IssueMeta {} #[derive(Clone, Eq, PartialEq, Hash, Debug, Default)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB20)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", rename_all = "camelCase") +)] pub struct BurnMeta { pub burn_proofs: SmallOrdSet, } diff --git a/std/src/interface/rgb21.rs b/std/src/interface/rgb21.rs index dfe997b3..4241a6e8 100644 --- a/std/src/interface/rgb21.rs +++ b/std/src/interface/rgb21.rs @@ -55,6 +55,11 @@ pub const LIB_ID_RGB21: &str = "logic_radius_anita_HgevHFfoBcfqUMHjouxvGMtgGyvs2 #[wrapper_mut(AddAssign, SubAssign, MulAssign, DivAssign, RemAssign)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", transparent) +)] pub struct ItemsCount(u32); #[derive( @@ -64,6 +69,11 @@ pub struct ItemsCount(u32); #[wrapper_mut(AddAssign, SubAssign, MulAssign, DivAssign, RemAssign)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", transparent) +)] pub struct TokenIndex(u32); #[derive( @@ -73,11 +83,21 @@ pub struct TokenIndex(u32); #[wrapper_mut(AddAssign, SubAssign, MulAssign, DivAssign, RemAssign)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", transparent) +)] pub struct OwnedFraction(u64); #[derive(Clone, Eq, PartialEq, Hash, Debug, Default)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", rename_all = "camelCase") +)] pub struct IssueMeta { pub reserves: SmallOrdSet, } @@ -87,11 +107,17 @@ impl StrictDeserialize for IssueMeta {} #[derive(Clone, Eq, PartialEq, Hash, Debug, Default)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))] pub struct Allocation(TokenIndex, OwnedFraction); #[derive(Clone, Eq, PartialEq, Hash, Debug)] #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", rename_all = "camelCase") +)] pub struct EngravingData { pub applied_to: TokenIndex, pub content: EmbeddedMedia, @@ -100,8 +126,14 @@ pub struct EngravingData { #[derive(Clone, Eq, PartialEq, Hash, Debug)] #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", rename_all = "camelCase") +)] pub struct EmbeddedMedia { #[strict_type(rename = "type")] + #[cfg_attr(feature = "serde", serde(rename = "type"))] pub ty: MediaType, pub data: SmallBlob, } @@ -109,8 +141,14 @@ pub struct EmbeddedMedia { #[derive(Clone, Eq, PartialEq, Hash, Debug)] #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", rename_all = "camelCase") +)] pub struct Attachment { #[strict_type(rename = "type")] + #[cfg_attr(feature = "serde", serde(rename = "type"))] pub ty: MediaType, pub digest: [u8; 32], } @@ -118,6 +156,11 @@ pub struct Attachment { #[derive(Clone, Eq, PartialEq, Hash, Debug)] #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21, dumb = { AttachmentType::with(0, "dumb") })] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", rename_all = "camelCase") +)] pub struct AttachmentType { pub id: u8, pub name: AttachmentName, @@ -187,6 +230,11 @@ impl Debug for AttachmentName { #[derive(Clone, Eq, PartialEq, Hash, Debug, Default)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_RGB21)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", rename_all = "camelCase") +)] pub struct TokenData { pub index: TokenIndex, pub ticker: Option,