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 6 commits into
base: master
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
6 changes: 2 additions & 4 deletions examples/rgb20.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use amplify::hex::FromHex;
use bp::dbc::Method;
use bp::{Outpoint, Txid};
use ifaces::Rgb20;
use rgbstd::containers::{ConsignmentExt, FileContent};
use rgbstd::interface::{FilterIncludeAll, FungibleAllocation};
use rgbstd::invoice::Precision;
use rgbstd::persistence::Stock;
use rgbstd::XWitnessId;
use schemata::dumb::NoResolver;
use schemata::NonInflatableAsset;

Expand All @@ -17,7 +15,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("ssi:anonymous","TEST", "Test asset", None, Precision::CentiMicro, [(beneficiary, 1_000_000_000_00u64)])
.expect("invalid contract data");

let contract_id = contract.contract_id();
Expand All @@ -37,7 +35,7 @@ fn main() {
eprintln!("{}", serde_json::to_string(&contract.spec()).unwrap());

for FungibleAllocation { seal, state, witness, .. } in allocations {
let witness = witness.as_ref().map(XWitnessId::to_string).unwrap_or("~".to_owned());
let witness = witness.as_ref().map(Txid::to_string).unwrap_or("~".to_owned());
eprintln!("amount={state}, owner={seal}, witness={witness}");
}
eprintln!("totalSupply={}", contract.total_supply());
Expand Down
8 changes: 5 additions & 3 deletions examples/rgb21.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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, ChainNet, GenesisSeal, TokenIndex};
use schemata::dumb::NoResolver;
use schemata::UniqueDigitalAsset;
use sha2::{Digest, Sha256};
Expand All @@ -20,7 +20,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 = GenesisSeal::new_random(beneficiary_txid, 1);

let index = TokenIndex::from_inner(2);

Expand Down Expand Up @@ -48,9 +48,11 @@ 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(
"ssi:anonymous",
UniqueDigitalAsset::schema().schema_id(),
"RGB21Unique",
ChainNet::BitcoinTestnet4,
).expect("schema fails to implement RGB21 interface")

.add_global_state("tokens", token_data)
Expand Down
6 changes: 2 additions & 4 deletions examples/rgb25.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use amplify::hex::FromHex;
use bp::dbc::Method;
use bp::{Outpoint, Txid};
use ifaces::{Rgb25, Rgb25Wrapper};
use rgbstd::containers::{ConsignmentExt, FileContent, Kit};
use rgbstd::interface::{FilterIncludeAll, FungibleAllocation};
use rgbstd::invoice::Precision;
use rgbstd::persistence::{MemContract, Stock};
use rgbstd::XWitnessId;
use schemata::dumb::NoResolver;
use schemata::CollectibleFungibleAsset;

Expand All @@ -25,7 +23,7 @@ fn main() {
#[allow(clippy::inconsistent_digit_grouping)]
let contract = Rgb25Wrapper::<MemContract>::testnet::<CollectibleFungibleAsset>("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");
Expand All @@ -45,7 +43,7 @@ fn main() {
eprintln!("{}", contract.name());

for FungibleAllocation { seal, state, witness, .. } in allocations {
let witness = witness.as_ref().map(XWitnessId::to_string).unwrap_or("~".to_owned());
let witness = witness.as_ref().map(Txid::to_string).unwrap_or("~".to_owned());
eprintln!("amount={state}, owner={seal}, witness={witness}");
}
eprintln!("totalSupply={}", contract.total_issued_supply());
Expand Down
16 changes: 9 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,23 @@ pub const ERRNO_ISSUED_MISMATCH: u8 = 1;
pub const ERRNO_NON_FRACTIONAL: u8 = 10;

pub mod dumb {
use bp::Tx;
use rgbstd::validation::{ResolveWitness, WitnessResolverError};
use rgbstd::vm::{WitnessOrd, XWitnessTx};
use rgbstd::XWitnessId;
use rgbstd::vm::WitnessOrd;
use rgbstd::{ChainNet, Txid};

pub struct NoResolver;

impl ResolveWitness for NoResolver {
fn resolve_pub_witness(&self, _: XWitnessId) -> Result<XWitnessTx, WitnessResolverError> {
fn resolve_pub_witness(&self, _: Txid) -> Result<Tx, WitnessResolverError> {
unreachable!()
}

fn resolve_pub_witness_ord(
&self,
_: XWitnessId,
) -> Result<WitnessOrd, WitnessResolverError> {
fn resolve_pub_witness_ord(&self, _: Txid) -> Result<WitnessOrd, WitnessResolverError> {
unreachable!()
}

fn check_chain_net(&self, _: ChainNet) -> Result<(), WitnessResolverError> {
unreachable!()
}
}
Expand Down
66 changes: 23 additions & 43 deletions src/nia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ 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::Outpoint;
use ifaces::{IssuerWrapper, Rgb20, Rgb20Wrapper, LNPBP_IDENTITY};
use rgbstd::containers::ValidContract;
use rgbstd::interface::{IfaceClass, IfaceImpl, NamedField, NamedVariant, TxOutpoint, VerNo};
use rgbstd::interface::{IfaceClass, IfaceImpl, NamedField, NamedVariant, VerNo};
use rgbstd::persistence::MemContract;
use rgbstd::schema::{
FungibleType, GenesisSchema, GlobalStateSchema, Occurrences, OwnedStateSchema, Schema,
TransitionSchema,
};
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;
Expand All @@ -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;
Expand All @@ -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;
};
Expand All @@ -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);
Expand Down Expand Up @@ -193,13 +193,13 @@ impl NonInflatableAsset {
name: &str,
details: Option<&str>,
precision: Precision,
allocations: impl IntoIterator<Item = (Method, impl TxOutpoint, impl Into<Amount>)>,
allocations: impl IntoIterator<Item = (Outpoint, impl Into<Amount>)>,
) -> Result<ValidContract, InvalidRString> {
let mut issuer =
Rgb20Wrapper::<MemContract>::testnet::<Self>(issuer, ticker, name, details, precision)?;
for (method, beneficiary, amount) in allocations {
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"))
Expand All @@ -210,9 +210,8 @@ impl NonInflatableAsset {
mod test {
use std::str::FromStr;

use bp::seals::txout::{BlindSeal, CloseMethod};
use bp::seals::txout::BlindSeal;
use bp::Txid;
use chrono::DateTime;
use rgbstd::containers::{BuilderSeal, ConsignmentExt};
use rgbstd::interface::*;
use rgbstd::invoice::Precision;
Expand Down Expand Up @@ -246,22 +245,12 @@ mod test {
precision: Precision::try_from(2).unwrap(),
};
let issued_supply = 999u64;
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 seal: BlindSeal<Txid> = GenesisSeal::from(BlindSeal::with_blinding(
Txid::from_str("8d54c98d4c29a1ec4fd90635f543f0f7a871a78eb6a6e706342f831d92e3ba19")
.unwrap(),
0,
654321,
));

let builder = ContractBuilder::deterministic(
Identity::default(),
Expand All @@ -270,31 +259,22 @@ mod test {
NonInflatableAsset::issue_impl(),
NonInflatableAsset::types(),
NonInflatableAsset::scripts(),
ChainNet::BitcoinTestnet4,
)
.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:QRmoA2Ly-vpemU23-gVV4oFj-NDtLJzH-BUmHok3-YaABLnQ")
);
}
}
Binary file modified test/rgb20-example.rgb
Binary file not shown.
Loading
Loading