Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

State unification #50

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
256 changes: 117 additions & 139 deletions Cargo.lock

Large diffs are not rendered by default.

37 changes: 27 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,31 @@ readme = "README.md"

[[bin]]
name = "rgb-schemata"
required-features = ["fs"]
required-features = ["fs", "log"]

[[example]]
name = "rgb20"
required-features = ["fs", "log"]

[[example]]
name = "rgb21"
required-features = ["fs", "log"]

[[example]]
name = "rgb25"
required-features = ["fs", "log"]

[lib]
name = "schemata"

[dependencies]
amplify = "4.7.0"
strict_encoding = "2.7.0"
strict_types = "2.7.0"
aluvm = "0.11.0-beta.8"
bp-core = "0.11.0-beta.8"
rgb-std = { version = "0.11.0-beta.8", features = ["serde", "fs"] }
rgb-interfaces = "0.11.0-beta.8"
strict_types = "2.7.1"
aluvm = "0.11.0-beta.9"
bp-core = "0.11.0-beta.9"
rgb-std = { version = "0.11.0-beta.9", features = ["serde", "fs"] }
rgb-interfaces = { version = "0.11.0-beta.8", features = ["serde", "rand", "fs"] }
chrono = "0.4.38"
serde = "1.0"
serde_json = "1.0"
Expand All @@ -43,11 +55,16 @@ log = ["aluvm/log"]
fs = ["rgb-std/fs"]

[patch.crates-io]
commit_verify = { git = "https://github.com/LNP-BP/client_side_validation", branch = "develop" }
single_use_seals = { git = "https://github.com/LNP-BP/client_side_validation", branch = "develop" }
strict_types = { git = "https://github.com/strict-types/strict-types", branch = "develop" }
aluvm = { git = "https://github.com/AluVM/rust-aluvm", branch = "develop" }
bp-consensus = { git = "https://github.com/BP-WG/bp-core", branch = "develop" }
bp-dbc = { git = "https://github.com/BP-WG/bp-core", branch = "develop" }
bp-seals = { git = "https://github.com/BP-WG/bp-core", branch = "develop" }
bp-core = { git = "https://github.com/BP-WG/bp-core", branch = "develop" }
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "develop" }
rgb-invoice = { git = "https://github.com/RGB-WG/rgb-std", branch = "develop" }
rgb-std = { git = "https://github.com/RGB-WG/rgb-std", branch = "develop" }
rgb-interfaces = { git = "https://github.com/RGB-WG/rgb-interfaces", branch = "develop" }
bp-invoice = { git = "https://github.com/BP-WG/bp-std", branch = "develop" }
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "feat/asm" }
rgb-invoice = { git = "https://github.com/RGB-WG/rgb-std", branch = "feat/fungible-nonconf" }
rgb-std = { git = "https://github.com/RGB-WG/rgb-std", branch = "feat/fungible-nonconf" }
rgb-interfaces = { git = "https://github.com/RGB-WG/rgb-interfaces", branch = "feat/fungible-nonconf" }
17 changes: 8 additions & 9 deletions examples/rgb20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use amplify::hex::FromHex;
use bp::dbc::Method;
use bp::{Outpoint, Txid};
use ifaces::Rgb20;
use ifaces::stl::Precision;
use rgbstd::XWitnessId;
use rgbstd::containers::{ConsignmentExt, FileContent};
use rgbstd::interface::{FilterIncludeAll, FungibleAllocation};
use rgbstd::invoice::Precision;
use rgbstd::interface::{FilterIncludeAll, Output};
use rgbstd::persistence::Stock;
use rgbstd::XWitnessId;
use schemata::dumb::NoResolver;
use schemata::NonInflatableAsset;
use schemata::dumb::NoResolver;

#[rustfmt::skip]
fn main() {
Expand All @@ -33,12 +33,11 @@ fn main() {
// Reading contract state through the interface from the stock:
let contract = stock.contract_iface_class::<Rgb20>(contract_id).unwrap();
let allocations = contract.allocations(&FilterIncludeAll);
eprintln!("\nThe issued contract data:");
eprintln!("{}", serde_json::to_string(&contract.spec()).unwrap());
eprintln!("{}", contract.spec());

for FungibleAllocation { seal, state, witness, .. } in allocations {
for Output { seal, state, witness, .. } in allocations {
let witness = witness.as_ref().map(XWitnessId::to_string).unwrap_or("~".to_owned());
eprintln!("amount={state}, owner={seal}, witness={witness}");
eprintln!("state {state}, owner {seal}, witness {witness}");
}
eprintln!("totalSupply={}", contract.total_supply());
eprintln!("totalSupply {}", contract.total_supply());
}
28 changes: 17 additions & 11 deletions examples/rgb21.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use amplify::confinement::SmallBlob;
use amplify::hex::FromHex;
use amplify::{Bytes, Wrapper};
use bp::Txid;
use ifaces::rgb21::{EmbeddedMedia, TokenData};
use ifaces::rgb21::{EmbeddedMedia, NftAllocation, TokenData, TokenIndex};
use ifaces::stl::*;
use ifaces::{IssuerWrapper, Rgb21};
use rgbstd::containers::{ConsignmentExt, FileContent, Kit};
use rgbstd::invoice::Precision;
use rgbstd::interface::{FilterIncludeAll, Output};
use rgbstd::persistence::Stock;
use rgbstd::stl::{AssetSpec, Attachment, ContractTerms, MediaType, RicardianContract};
use rgbstd::{Allocation, GenesisSeal, TokenIndex, XChain};
use schemata::dumb::NoResolver;
use rgbstd::{GenesisSeal, XChain, XWitnessId};
use schemata::UniqueDigitalAsset;
use schemata::dumb::NoResolver;
use sha2::{Digest, Sha256};

#[rustfmt::skip]
Expand Down Expand Up @@ -41,7 +41,7 @@ fn main() {
};

let token_data = TokenData { index, preview: Some(preview), ..Default::default() };
let allocation = Allocation::with(index, 1);
let allocation = NftAllocation::with(index, 1);

// Let's create some stock - an in-memory stash and inventory around it:
let kit = Kit::load_file("schemata/UniqueDigitalAsset.rgb").unwrap().validate().unwrap();
Expand All @@ -53,16 +53,16 @@ fn main() {
"RGB21Unique",
).expect("schema fails to implement RGB21 interface")

.add_global_state("tokens", token_data)
.serialize_global_state("tokens", &token_data)
.expect("invalid token data")

.add_global_state("spec", spec)
.serialize_global_state("spec", &spec)
.expect("invalid nominal")

.add_global_state("terms", terms)
.serialize_global_state("terms", &terms)
.expect("invalid contract text")

.add_data("assetOwner", beneficiary, allocation)
.serialize_owned_state("assetOwner", beneficiary, &allocation, None)
.expect("invalid asset blob")

.issue_contract()
Expand All @@ -78,5 +78,11 @@ fn main() {

// Reading contract state through the interface from the stock:
let contract = stock.contract_iface_class::<Rgb21>(contract_id).unwrap();
eprintln!("{}", serde_json::to_string(&contract.spec()).unwrap());
let allocations = contract.allocations(&FilterIncludeAll);

eprintln!("{}", contract.spec());
for Output { seal, state, witness, .. } in allocations {
let witness = witness.as_ref().map(XWitnessId::to_string).unwrap_or("~".to_owned());
eprintln!("state ({state}), owner {seal}, witness {witness}");
}
}
23 changes: 14 additions & 9 deletions examples/rgb25.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use amplify::hex::FromHex;
use bp::dbc::Method;
use bp::{Outpoint, Txid};
use ifaces::stl::Precision;
use ifaces::{Rgb25, Rgb25Wrapper};
use rgbstd::XWitnessId;
use rgbstd::containers::{ConsignmentExt, FileContent, Kit};
use rgbstd::interface::{FilterIncludeAll, FungibleAllocation};
use rgbstd::invoice::Precision;
use rgbstd::interface::{FilterIncludeAll, Output};
use rgbstd::persistence::{MemContract, Stock};
use rgbstd::XWitnessId;
use schemata::dumb::NoResolver;
use schemata::CollectibleFungibleAsset;
use schemata::dumb::NoResolver;

#[rustfmt::skip]
fn main() {
Expand Down Expand Up @@ -41,12 +41,17 @@ fn main() {
// Reading contract state through the interface from the stock:
let contract = stock.contract_iface_class::<Rgb25>(contract_id).unwrap();
let allocations = contract.allocations(&FilterIncludeAll);
eprintln!("\nThe issued contract data:");
eprintln!("{}", contract.name());
eprint!("name {}, details ", contract.name());
if let Some(details) = contract.details() {
eprint!("{details}");
} else {
eprint!("~");
}
eprintln!(", precision {}", contract.precision());

for FungibleAllocation { seal, state, witness, .. } in allocations {
for Output { seal, state, witness, .. } in allocations {
let witness = witness.as_ref().map(XWitnessId::to_string).unwrap_or("~".to_owned());
eprintln!("amount={state}, owner={seal}, witness={witness}");
eprintln!("state {state}, owner {seal}, witness {witness}");
}
eprintln!("totalSupply={}", contract.total_issued_supply());
eprintln!("totalSupply {}", contract.total_issued_supply());
}
Binary file modified schemata/CollectibleFungibleAsset.rgb
Binary file not shown.
Loading
Loading