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

v0.11 fixes #51

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion examples/rgb20.rs
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ fn main() {
let beneficiary = Outpoint::new(beneficiary_txid, 1);

#[allow(clippy::inconsistent_digit_grouping)]
let contract = NonInflatableAsset::testnet("ssi:anonymous","TEST", "Test asset", None, Precision::CentiMicro, [(Method::TapretFirst, beneficiary, 1_000_000_000_00u64)])
let contract = NonInflatableAsset::testnet(Method::TapretFirst, "ssi:anonymous","TEST", "Test asset", None, Precision::CentiMicro, [(beneficiary, 1_000_000_000_00u64)])
.expect("invalid contract data");

let contract_id = contract.contract_id();
10 changes: 7 additions & 3 deletions examples/rgb21.rs
Original file line number Diff line number Diff line change
@@ -3,14 +3,15 @@ use std::fs;
use amplify::confinement::SmallBlob;
use amplify::hex::FromHex;
use amplify::{Bytes, Wrapper};
use bp::dbc::Method;
use bp::Txid;
use ifaces::rgb21::{EmbeddedMedia, TokenData};
use ifaces::{IssuerWrapper, Rgb21};
use rgbstd::containers::{ConsignmentExt, FileContent, Kit};
use rgbstd::invoice::Precision;
use rgbstd::persistence::Stock;
use rgbstd::stl::{AssetSpec, Attachment, ContractTerms, MediaType, RicardianContract};
use rgbstd::{Allocation, GenesisSeal, TokenIndex, XChain};
use rgbstd::{Allocation, GenesisSeal, Layer1, TokenIndex, XChain};
use schemata::dumb::NoResolver;
use schemata::UniqueDigitalAsset;
use sha2::{Digest, Sha256};
@@ -20,7 +21,7 @@ fn main() {
let spec = AssetSpec::new("TEST", "Test uda", Precision::Indivisible);
let beneficiary_txid =
Txid::from_hex("14295d5bb1a191cdb6286dc0944df938421e3dfcbf0811353ccac4100c2068c5").unwrap();
let beneficiary = XChain::Bitcoin(GenesisSeal::tapret_first_rand(beneficiary_txid, 1));
let beneficiary = XChain::Bitcoin(GenesisSeal::new_random(beneficiary_txid, 1));

let index = TokenIndex::from_inner(2);

@@ -48,9 +49,12 @@ fn main() {
let mut stock = Stock::in_memory();
stock.import_kit(kit).expect("invalid issuer kit");

let contract = stock.contract_builder("ssi:anonymous",
let contract = stock.contract_builder(
Method::OpretFirst,
"ssi:anonymous",
UniqueDigitalAsset::schema().schema_id(),
"RGB21Unique",
Layer1::Bitcoin,
).expect("schema fails to implement RGB21 interface")

.add_global_state("tokens", token_data)
4 changes: 2 additions & 2 deletions examples/rgb25.rs
Original file line number Diff line number Diff line change
@@ -23,9 +23,9 @@ fn main() {
stock.import_kit(kit).expect("invalid issuer kit");

#[allow(clippy::inconsistent_digit_grouping)]
let contract = Rgb25Wrapper::<MemContract>::testnet::<CollectibleFungibleAsset>("ssi:anonymous", "Test asset", Precision::CentiMicro)
let contract = Rgb25Wrapper::<MemContract>::testnet::<CollectibleFungibleAsset>(Method::TapretFirst, "ssi:anonymous", "Test asset", Precision::CentiMicro)
.expect("invalid contract data")
.allocate(Method::TapretFirst, beneficiary, 1_000_000_000_00u64.into())
.allocate(beneficiary, 1_000_000_000_00u64.into())
.expect("invalid allocations")
.issue_contract()
.expect("invalid contract data");
59 changes: 25 additions & 34 deletions src/nia.rs
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ use aluvm::isa::opcodes::INSTR_PUTA;
use aluvm::isa::Instr;
use aluvm::library::{Lib, LibSite};
use amplify::confinement::Confined;
use bp::dbc::Method;
use bp::seals::txout::CloseMethod;
use ifaces::{IssuerWrapper, Rgb20, Rgb20Wrapper, LNPBP_IDENTITY};
use rgbstd::containers::ValidContract;
use rgbstd::interface::{IfaceClass, IfaceImpl, NamedField, NamedVariant, TxOutpoint, VerNo};
@@ -37,7 +37,7 @@ use rgbstd::schema::{
};
use rgbstd::stl::StandardTypes;
use rgbstd::validation::Scripts;
use rgbstd::vm::opcodes::INSTR_PCVS;
use rgbstd::vm::opcodes::INSTR_SVS;
use rgbstd::vm::RgbIsa;
use rgbstd::{rgbasm, Amount, Identity, Precision};
use strict_encoding::InvalidRString;
@@ -53,14 +53,14 @@ pub(crate) fn nia_lib() -> Lib {
// SUBROUTINE Transfer validation
// Set errno
put a8[0],ERRNO_NON_EQUAL_IN_OUT;
// Checking that the sum of pedersen commitments in inputs is equal to the sum in outputs.
pcvs OS_ASSET;
// Checking that the sum of inputs is equal to the sum of outputs.
svs OS_ASSET;
test;
ret;

// SUBROUTINE Genesis validation
// Checking pedersen commitments against reported amount of issued assets present in the
// global state.
// Checking genesis assignments amount against reported amount of issued assets present in
// the global state.
put a8[0],ERRNO_ISSUED_MISMATCH;
put a8[1],0;
put a16[0],0;
@@ -69,8 +69,8 @@ pub(crate) fn nia_lib() -> Lib {
// Extract 64 bits from the beginning of s16[0] into a64[1]
// NB: if the global state is invalid, we will fail here and fail the validation
extr s16[0],a64[0],a16[0];
// verify sum of pedersen commitments for assignments against a64[0] value
pcas OS_ASSET;
// verify sum of outputs against a64[0] value
sas OS_ASSET;
test;
ret;
};
@@ -84,7 +84,7 @@ fn nia_schema() -> Schema {

let alu_lib = nia_lib();
let alu_id = alu_lib.id();
assert_eq!(alu_lib.code.as_ref()[FN_NIA_TRANSFER_OFFSET as usize + 4], INSTR_PCVS);
assert_eq!(alu_lib.code.as_ref()[FN_NIA_TRANSFER_OFFSET as usize + 4], INSTR_SVS);
assert_eq!(alu_lib.code.as_ref()[FN_NIA_GENESIS_OFFSET as usize], INSTR_PUTA);
assert_eq!(alu_lib.code.as_ref()[FN_NIA_GENESIS_OFFSET as usize + 4], INSTR_PUTA);
assert_eq!(alu_lib.code.as_ref()[FN_NIA_GENESIS_OFFSET as usize + 8], INSTR_PUTA);
@@ -188,18 +188,25 @@ impl IssuerWrapper for NonInflatableAsset {

impl NonInflatableAsset {
pub fn testnet(
close_method: CloseMethod,
issuer: &str,
ticker: &str,
name: &str,
details: Option<&str>,
precision: Precision,
allocations: impl IntoIterator<Item = (Method, impl TxOutpoint, impl Into<Amount>)>,
allocations: impl IntoIterator<Item = (impl TxOutpoint, impl Into<Amount>)>,
) -> Result<ValidContract, InvalidRString> {
let mut issuer =
Rgb20Wrapper::<MemContract>::testnet::<Self>(issuer, ticker, name, details, precision)?;
for (method, beneficiary, amount) in allocations {
let mut issuer = Rgb20Wrapper::<MemContract>::testnet::<Self>(
close_method,
issuer,
ticker,
name,
details,
precision,
)?;
for (beneficiary, amount) in allocations {
issuer = issuer
.allocate(method, beneficiary, amount)
.allocate(beneficiary, amount)
.expect("invalid contract data");
}
Ok(issuer.issue_contract().expect("invalid contract data"))
@@ -212,7 +219,6 @@ mod test {

use bp::seals::txout::{BlindSeal, CloseMethod};
use bp::Txid;
use chrono::DateTime;
use rgbstd::containers::{BuilderSeal, ConsignmentExt};
use rgbstd::interface::*;
use rgbstd::invoice::Precision;
@@ -249,52 +255,37 @@ mod test {
let seal: XChain<BlindSeal<Txid>> = XChain::with(
Layer1::Bitcoin,
GenesisSeal::from(BlindSeal::with_blinding(
CloseMethod::OpretFirst,
Txid::from_str("8d54c98d4c29a1ec4fd90635f543f0f7a871a78eb6a6e706342f831d92e3ba19")
.unwrap(),
0,
654321,
)),
);
let asset_tag = AssetTag::new_deterministic(
"contract_domain",
AssignmentType::with(0),
DateTime::from_timestamp(created_at, 0).unwrap(),
123456,
);

let builder = ContractBuilder::deterministic(
CloseMethod::OpretFirst,
Identity::default(),
NonInflatableAsset::FEATURES.iface(),
NonInflatableAsset::schema(),
NonInflatableAsset::issue_impl(),
NonInflatableAsset::types(),
NonInflatableAsset::scripts(),
Layer1::Bitcoin,
)
.add_global_state("spec", spec)
.unwrap()
.add_global_state("terms", terms)
.unwrap()
.add_global_state("issuedSupply", Amount::from(issued_supply))
.unwrap()
.add_asset_tag("assetOwner", asset_tag)
.unwrap()
.add_fungible_state_det(
"assetOwner",
BuilderSeal::from(seal),
issued_supply,
BlindingFactor::from_str(
"a3401bcceb26201b55978ff705fecf7d8a0a03598ebeccf2a947030b91a0ff53",
)
.unwrap(),
)
.add_fungible_state("assetOwner", BuilderSeal::from(seal), issued_supply)
.unwrap();

let contract = builder.issue_contract_det(created_at).unwrap();

assert_eq!(
contract.contract_id().to_string(),
s!("rgb:pOIzGFyQ-mA!yQq2-QH8vB5!-5fAplY!-x2lW!vz-JHDbYPg")
s!("rgb:YOuqECXu-dD83k1O-anQpcFl-JiArTWz-rxmrARH-uSuhdLE")
);
}
}
Binary file modified test/rgb20-example.rgb
Binary file not shown.
Loading
Loading