Skip to content

Commit

Permalink
feat: add udc schema impl
Browse files Browse the repository at this point in the history
  • Loading branch information
crisdut committed Jan 20, 2024
1 parent d0565ee commit 2315c1f
Show file tree
Hide file tree
Showing 17 changed files with 755 additions and 145 deletions.
260 changes: 152 additions & 108 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ serde_yaml = "0.9.27"

[features]
all=[]


[patch.crates-io]
aluvm = { git = "https://github.com/AluVM/rust-aluvm", branch = "master" }
rgb-std = { git = "https://github.com/RGB-WG/rgb-std", branch = "v0.11" }
bp-core = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" }
rgb-core = { git = "https://github.com/crisdut/rgb-core", branch = "feat/udc" }
4 changes: 2 additions & 2 deletions examples/rgb20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ fn main() {
eprintln!("\nThe issued contract data:");
eprintln!("{}", serde_json::to_string(&contract.spec()).unwrap());

for FungibleAllocation { owner, witness, value } in allocations {
eprintln!("amount={value}, owner={owner}, witness={witness}");
for FungibleAllocation { seal, state, witness, .. } in allocations {
eprintln!("amount={}, owner={seal}, witness={witness}", state.value());
}
eprintln!("totalSupply={}", contract.total_supply());
eprintln!("created={}", contract.created().to_local().unwrap());
Expand Down
98 changes: 91 additions & 7 deletions examples/rgb21.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use amplify::confinement::SmallBlob;
use amplify::hex::FromHex;
use amplify::Wrapper;
use bp::Txid;
use rgb_schemata::{uda_rgb21, uda_schema};
use rgb_schemata::{uda_rgb21, uda_schema, udc_schema, udc_rgb21};
use rgbstd::containers::BindleContent;
use rgbstd::interface::rgb21::{Allocation, EmbeddedMedia, OwnedFraction, TokenData, TokenIndex};
use rgbstd::interface::{rgb21, ContractBuilder};
Expand All @@ -32,8 +32,7 @@ impl ResolveHeight for DumbResolver {
}
}

#[rustfmt::skip]
fn main() {
fn uda() {
let spec = DivisibleAssetSpec::new("TEST", "Test uda", Precision::Indivisible);
let terms = RicardianContract::default();
let created = Timestamp::now();
Expand All @@ -42,16 +41,16 @@ fn main() {
let beneficiary = XChain::Bitcoin(GenesisSeal::tapret_first_rand(beneficiary_txid, 1));

let fraction = OwnedFraction::from_inner(1);
let index = TokenIndex::from_inner(2);
let index = TokenIndex::from_inner(1);

let preview = EmbeddedMedia {
ty: stl::MediaType::with("text/*"),
data: SmallBlob::try_from_iter(vec![0, 0]).expect("invalid data"),
};

let token_data = TokenData { index, preview: Some(preview), ..Default::default() };

let allocation = Allocation::with(index, fraction);

let contract = ContractBuilder::testnet(
rgb21(),
uda_schema(),
Expand Down Expand Up @@ -82,8 +81,8 @@ fn main() {

let bindle = contract.bindle();
eprintln!("{bindle}");
bindle.save("examples/rgb21-simplest.contract.rgb").expect("unable to save contract");
fs::write("examples/rgb21-simplest.contract.rgba", bindle.to_string()).expect("unable to save contract");
bindle.save("examples/rgb21-uda.rgb").expect("unable to save contract");
fs::write("examples/rgb21-uda.rgba", bindle.to_string()).expect("unable to save contract");

// Let's create some stock - an in-memory stash and inventory around it:
let mut stock = Stock::default();
Expand All @@ -105,3 +104,88 @@ fn main() {
let nominal = contract.global("spec").unwrap();
eprintln!("{}", nominal[0]);
}

fn udc() {
let spec = DivisibleAssetSpec::new("TEST", "Test udc", Precision::Indivisible);
let terms = RicardianContract::default();
let created = Timestamp::now();
let beneficiary_txid =
Txid::from_hex("14295d5bb1a191cdb6286dc0944df938421e3dfcbf0811353ccac4100c2068c5").unwrap();
let beneficiary = XChain::Bitcoin(GenesisSeal::tapret_first_rand(beneficiary_txid, 1));

let fraction = OwnedFraction::from_inner(1);
let index = TokenIndex::from_inner(1);

let token_data_1 = TokenData { index, ..Default::default() };
let allocation_1 = Allocation::with(index, fraction);

let index = TokenIndex::from_inner(2);
let token_data_2 = TokenData { index, ..Default::default() };
let allocation_2 = Allocation::with(index, fraction);
let beneficiary_2 = XChain::Bitcoin(GenesisSeal::tapret_first_rand(beneficiary_txid, 2));

let contract = ContractBuilder::testnet(
rgb21(),
udc_schema(),
udc_rgb21(),
).expect("schema fails to implement RGB21 interface")

.add_global_state("tokens", token_data_1)
.expect("invalid token data")

.add_global_state("tokens", token_data_2)
.expect("invalid token data")

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

.add_global_state("created", created)
.expect("invalid creation date")

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

.add_data("assetOwner", beneficiary, allocation_1)
.expect("invalid asset blob")

.add_data("assetOwner", beneficiary_2, allocation_2)
.expect("invalid asset blob")

.issue_contract()
.expect("contract doesn't fit schema requirements");
eprintln!("{}", serde_yaml::to_string(&contract.genesis).unwrap());

let contract_id = contract.contract_id();
debug_assert_eq!(contract_id, contract.contract_id());

let bindle = contract.bindle();
eprintln!("{bindle}");
bindle.save("examples/rgb21-udc.rgb").expect("unable to save contract");
fs::write("examples/rgb21-udc.rgba", bindle.to_string()).expect("unable to save contract");

// Let's create some stock - an in-memory stash and inventory around it:
let mut stock = Stock::default();
stock.import_iface(rgb21()).unwrap();
stock.import_schema(udc_schema()).unwrap();
stock.import_iface_impl(udc_rgb21()).unwrap();

// Noe we verify our contract consignment and add it to the stock
let verified_contract = match bindle.unbindle().validate(&mut DumbResolver, true) {
Ok(consignment) => consignment,
Err(consignment) => {
panic!("can't produce valid consignment. Report: {}", consignment.validation_status().expect("status always present upon validation"));
}
};
stock.import_contract(verified_contract, &mut DumbResolver).unwrap();

// Reading contract state through the interface from the stock:
let contract = stock.contract_iface_id(contract_id, rgb21().iface_id()).unwrap();
let nominal = contract.global("spec").unwrap();
eprintln!("{}", nominal[0]);
}

#[rustfmt::skip]
fn main() {
uda();
udc();
}
4 changes: 2 additions & 2 deletions examples/rgb25.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn main() {
let allocations = contract.fungible("assetOwner", &FilterIncludeAll).unwrap();
eprintln!("{}", Name::from_strict_val_unchecked(&name[0]));

for FungibleAllocation { owner, witness, value } in allocations {
eprintln!("(amount={value}, owner={owner}, witness={witness})");
for FungibleAllocation { seal, state, witness, .. } in allocations {
eprintln!("amount={}, owner={seal}, witness={witness}", state.value());
}
}
Binary file modified schemata/UniqueDigitalAsset-RGB21.rgb
Binary file not shown.
8 changes: 4 additions & 4 deletions schemata/UniqueDigitalAsset-RGB21.rgba
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
-----BEGIN RGB INTERFACE IMPLEMENTATION-----
Id: D5v6Zj-Sq5noX3U-Rj6fQU8o-wPAPgGjL-ck8cJA5g-ujn8gA
Mnemonic: point-havana-concert
Id: 7jKhrU-jY1qHdUM-gBqwGbw4-aTXEFR12-sAb65eKG-jvdy4E
Mnemonic: libra-million-gate
IfaceId: 8Q9TfV-aJtgbWFw-entqAA5f-7hYUGjG4-xaAD9eo6-hmcfnU
SchemaId: DU4G7m-JQjmBDzy-tVz6NzSk-WWYExa8N-PrNw4Ygx-Hp79zf
SchemaId: EbgRJB-R2a5Rsdd-EAsAPXnX-DfSfs3hm-1XuNFGGM-Qq2iyK

0J%DxoZ>U2Cd-y;+|F3L;ok;Jvfa(&Cr9r}hw!lhP;KwKhUh!fbn@NR0#zSot#D$
0LltKrx?BkF~5V<ZflNiW_~sj^Png9U6z}^$~C9&j&1L|hUh!fbn@NR0#zSot#D$
;MEUwpQg_}a0fYIF9R$z^1aoj@V*mgE0MiEtV{&C-bY)}!0000r2nBRya&2<}000
0s2nKX-Yh`Y8000000iX{GVRLh3bWe9~WpV%j000015GM#!a$#<BW@T~!0000000
000
Expand Down
Binary file modified schemata/UniqueDigitalAsset.rgb
Binary file not shown.
16 changes: 8 additions & 8 deletions schemata/UniqueDigitalAsset.rgba
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-----BEGIN RGB SCHEMA-----
Id: DU4G7m-JQjmBDzy-tVz6NzSk-WWYExa8N-PrNw4Ygx-Hp79zf
Mnemonic: amade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y-wa5X>Md?cmx0e000000001QcWz~5AZBu5V{~b6ZXjuMA
Z~ATATa;}00000Gq;pqz6L=jI$>WK`Sit;Oo~MTV^2f#G7bc;LUtk*0003HCo{K{
U%m!GCpuwY8Ts_ZlT3<50b@@?^D+(uu0nPq6+-|

-----END RGB SCHEMA-----
Binary file added schemata/UniqueDigitalCollection-RGB21.rgb
Binary file not shown.
12 changes: 12 additions & 0 deletions schemata/UniqueDigitalCollection-RGB21.rgba
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-----BEGIN RGB INTERFACE IMPLEMENTATION-----
Id: ELu7bg-E5Vcg7zv-rHaSFmvq-6oGAcJH2-SjPKacaK-6bDEut
Mnemonic: comedy-store-precise
IfaceId: 8Q9TfV-aJtgbWFw-entqAA5f-7hYUGjG4-xaAD9eo6-hmcfnU
SchemaId: G6NzKm-baasi49K-sYEBUjPh-ZFBxCE9R-6kXa7RGL-hLZPeX

0N_9o`qea_X4JbtmGay0+75K9sLCh1d*SnVXHKdV2yO4XhUh!fbn@NR0#zSot#D$
;MEUwpQg_}a0fYIF9R$z^1aoj@V*mgE0MiEtV{&C-bY)}!0000r2nBRya&2<}000
0s2nKX-Yh`Y8000000iX{GVRLh3bWe9~WpV%j000015GM#!a$#<BW@T~!0000000
000

-----END RGB INTERFACE IMPLEMENTATION-----
Binary file added schemata/UniqueDigitalCollection.rgb
Binary file not shown.
Loading

0 comments on commit 2315c1f

Please sign in to comment.