Skip to content

Commit

Permalink
Merge pull request #7 from RGB-WG/fixes
Browse files Browse the repository at this point in the history
Improvements & fixes for NIA and UDA schemata
  • Loading branch information
dr-orlovsky authored Jun 28, 2023
2 parents 491a241 + c5e5249 commit 134a022
Show file tree
Hide file tree
Showing 18 changed files with 528 additions and 465 deletions.
247 changes: 134 additions & 113 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ serde_json = "1.0.93"
all=[]

[patch.crates-io]
# TODO: Remove after merge and release new version
strict_types = { git = "https://github.com/strict-types/strict-types" }
commit_verify = { git = "https://github.com/LNP-BP/client_side_validation" }
bp-core = { git = "https://github.com/BP-WG/bp-core" }
aluvm = { git = "https://github.com/AluVM/rust-aluvm" }
rgb-core = { git = "https://github.com/RGB-WG/rgb-core" }
rgb-std = { git = "https://github.com/RGB-WG/rgb-wallet" }
strict_encoding = { git = "https://github.com/strict-types/strict-encoding", branch = "ascii-char" }
strict_types = { git = "https://github.com/strict-types/strict-types", branch = "restricted-keys" }
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "develop" }
rgb-std = { git = "https://github.com/RGB-WG/rgb-wallet", branch = "develop" }
Binary file modified examples/rgb20-simplest.contract.rgb
Binary file not shown.
21 changes: 14 additions & 7 deletions examples/rgb20-token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use amplify::hex::FromHex;
use bp::{Chain, Outpoint, Tx, Txid};
use rgb_schemata::{nia_rgb20, nia_schema};
use rgbstd::containers::BindleContent;
use rgbstd::interface::{rgb20, ContractBuilder, FungibleAllocation};
use rgbstd::interface::rgb20::Amount;
use rgbstd::interface::{rgb20, ContractBuilder, FungibleAllocation, Rgb20};
use rgbstd::persistence::{Inventory, Stock};
use rgbstd::resolvers::ResolveHeight;
use rgbstd::stl::{DivisibleAssetSpec, Precision, RicardianContract, Timestamp};
Expand Down Expand Up @@ -32,6 +33,8 @@ fn main() {
0
);

const ISSUE: u64 = 1_000_000_0000_0000;

let contract = ContractBuilder::with(
rgb20(),
nia_schema(),
Expand All @@ -43,12 +46,15 @@ fn main() {
.expect("invalid nominal")

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

.add_global_state("issuedSupply", Amount::from(ISSUE))
.expect("invalid issued supply")

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

.add_fungible_state("beneficiary", beneficiary, 1_000_000_0000_0000)
.add_fungible_state("beneficiary", beneficiary, ISSUE)
.expect("invalid asset amount")

.issue_contract()
Expand Down Expand Up @@ -78,11 +84,12 @@ fn main() {

// Reading contract state through the interface from the stock:
let contract = stock.contract_iface(contract_id, rgb20().iface_id()).unwrap();
let nominal = contract.global("spec").unwrap();
let allocations = contract.fungible("beneficiary").unwrap();
eprintln!("{}", nominal[0]);
let contract = Rgb20::from(contract);
let allocations = contract.fungible("beneficiary", &None).unwrap();
eprintln!("{}", serde_json::to_string(&contract.spec()).unwrap());

for FungibleAllocation { owner, witness, value } in allocations {
eprintln!("(amount={value}, owner={owner}, witness={witness})");
eprintln!("amount={value}, owner={owner}, witness={witness}");
}
eprintln!("totalSupply={}", contract.total_supply());
}
Binary file modified examples/rgb21-simplest.contract.rgb
Binary file not shown.
9 changes: 2 additions & 7 deletions examples/rgb21-token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bp::{Chain, Outpoint, Tx, Txid};
use rgb_schemata::{uda_rgb21, uda_schema};
use rgbstd::containers::BindleContent;
use rgbstd::interface::rgb21::{Allocation, EmbeddedMedia, OwnedFraction, TokenData, TokenIndex};
use rgbstd::interface::{rgb21, ContractBuilder, FungibleAllocation};
use rgbstd::interface::{rgb21, ContractBuilder};
use rgbstd::persistence::{Inventory, Stock};
use rgbstd::resolvers::ResolveHeight;
use rgbstd::stl::{self, DivisibleAssetSpec, Precision, RicardianContract, Timestamp};
Expand All @@ -27,7 +27,7 @@ impl ResolveHeight for DumbResolver {

#[rustfmt::skip]
fn main() {
let spec = DivisibleAssetSpec::new("TEST", "Test uda", Precision::CentiMicro);
let spec = DivisibleAssetSpec::new("TEST", "Test uda", Precision::Indivisible);
let terms = RicardianContract::default();
let created = Timestamp::default();
let beneficiary = Outpoint::new(
Expand Down Expand Up @@ -96,10 +96,5 @@ fn main() {
// Reading contract state through the interface from the stock:
let contract = stock.contract_iface(contract_id, rgb21().iface_id()).unwrap();
let nominal = contract.global("spec").unwrap();
let allocations = contract.fungible("beneficiary").unwrap();
eprintln!("{}", nominal[0]);

for FungibleAllocation { owner, witness, value } in allocations {
eprintln!("(amount={value}, owner={owner}, witness={witness})");
}
}
Binary file modified interfaces/RGB20.rgb
Binary file not shown.
4 changes: 2 additions & 2 deletions interfaces/RGB20.rgba
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-----BEGIN RGB INTERFACE-----
Id: 7Rrqv5iVnTv3DquiK7FJmdVBy1nNYBuSbkXpXRunwZzy
Id: BR2fhPEKPtsjoEz2PDpBV4o24HCjvD1Dk4nHnaRx94fQ
Name: RGB20

AAVSR0IyMAYMYnVybmVkU3VwcGx5AYiMWGVjOvE7lbfNGo2K8trB3BQLl3JR2dTa
88dRHI6EAAEHY3JlYXRlZAFZbno6DqNlnhAw8YtNZaO5E+5YUAf8914Lts3BacHA
OwEADGlzc3VlZFN1cHBseQGIjFhlYzrxO5W3zRqNivLawdwUC5dyUdnU2vPHURyO
hAABDnJlcGxhY2VkU3VwcGx5AYiMWGVjOvE7lbfNGo2K8trB3BQLl3JR2dTa88dR
hAEBDnJlcGxhY2VkU3VwcGx5AYiMWGVjOvE7lbfNGo2K8trB3BQLl3JR2dTa88dR
HI6EAAEEc3BlYwGZYk235CaSmVSTLt/I0melUpcCKTzVq8BWTm8iWzP68QEABXRl
cm1zARjLlG8Sk88YDp143MZbxZtHL//+rfv1jbGYzIMo9ksBAQAFCmFzc2V0T3du
ZXICAAABCWJ1cm5FcG9jaAEBAAAJYnVyblJpZ2h0AQEAARJpbmZsYXRpb25BbGxv
Expand Down
Binary file modified schemata/NonInflatableAssets-RGB20.rgb
Binary file not shown.
12 changes: 6 additions & 6 deletions schemata/NonInflatableAssets-RGB20.rgba
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
-----BEGIN RGB INTERFACE IMPLEMENTATION-----
Id: G6WW3639sopVPm3aYUpT1N7LHni1f4JDqTdeCxWvVz7F
IfaceId: 7Rrqv5iVnTv3DquiK7FJmdVBy1nNYBuSbkXpXRunwZzy
SchemaId: 7X8TPsZnwm8YV4HN6MnGk8iwnk2RKyWeiAy2nXZD3BYu
Id: JCsY3NFh5gQkN6vKiWjCsLELADTuiiZU4MPTrs6AHtSn
IfaceId: BR2fhPEKPtsjoEz2PDpBV4o24HCjvD1Dk4nHnaRx94fQ
SchemaId: E5c1ubMW5L9dDWDHWzeGVeXProKy7g8ADAWnpAtHGcor

AGDd+a3w5kXDkpx/fvjP4QnKKgo90gS4RnWEmfPUQLCyX4RrRsmIbV8iTI+Ttxdn
Y29CeTQOMSlRjxwPHXshHmIDAwAHY3JlYXRlZNAHBHNwZWPRBwV0ZXJtcwHQBwti
ZW5lZmljaWFyeQAB0AcIVHJhbnNmZXIA
AMJV2HgVBTPnCMAD3WjvG9DaQRd9CAgRW+07ugi/8BeBmryxmonD6VW3lv+QRMEH
joGrFCwwnYUkx3QJShg1g48EAwAHY3JlYXRlZNAHBHNwZWPRBwV0ZXJtc9IHDGlz
c3VlZFN1cHBseQGgDwphc3NldE93bmVyAAEQJwhUcmFuc2ZlcgA=

-----END RGB INTERFACE IMPLEMENTATION-----
Binary file modified schemata/NonInflatableAssets.rgb
Binary file not shown.
Loading

0 comments on commit 134a022

Please sign in to comment.