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

Update to Strict-Type 1.4.x #255

Merged
merged 5 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
420 changes: 221 additions & 199 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ bitcoin = { version = "0.29.2", features = ["base64"] }
bitcoin_hashes = "0.12.0"
bitcoin_scripts = "0.10.0-alpha.2"
bitcoin_blockchain = "0.10.0-alpha.2"
bp-core = "0.10.4"
commit_verify = "0.10.3"
bp-core = { version = "0.10.4", features = ["stl"] }
commit_verify = { version = "0.10.3", features = ["stl"] }
bp-seals = "0.10.4"
indexmap = "1.9.3"
carbonado = "0.3.1"
console_error_panic_hook = "0.1.7"
# directories = "4.0.1"
miniscript_crate = { package = "miniscript", version = "9.0.1", features = [
"compiler",
] }
Expand Down Expand Up @@ -72,23 +71,20 @@ psbt = { version = "0.10.0-alpha.2", features = [
"construct",
] }
regex = "1.7.0"
reqwest = { version = "0.11.16", features = ["json"] }
reqwest = { version = "0.11.18", features = ["json"] }
rgb-contracts = { version = "0.10.0-beta.2", default-features = false, features = [
"log",
] }
rgb-wallet = { version = "0.10.2" }
rgb-std = { version = "0.10.2" }

# rgb_wallet_bp = { version = "0.10.2-backport", package = "rgb-wallet", path = "../rgb-wallet" }
# rgb_std_bp = { version = "0.10.2-backport", package = "rgb-std", path = "../rgb-wallet/std" }

rgb-schemata = { version = "0.10.0-beta.1" }
serde = "1.0.152"
serde_json = "1.0.91"
postcard = { version = "1.0.4", features = ["alloc"] }
serde-encrypt = "0.7.0"
strict_types = "1.3.0"
strict_encoding = "2.3.0"
strict_types = "1.4.0"
strict_encoding = "~2.4.0"
tokio = { version = "1.28.2", features = ["macros", "sync"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down Expand Up @@ -137,3 +133,4 @@ rgb-contracts = { git = "https://github.com/crisdut/rgb", branch = "release/bmc-
rgb-schemata = { git = "https://github.com/crisdut/rgbsc", branch = "release/bmc-v0.6" }
rgb-wallet = { git = "https://github.com/crisdut/rgb-wallet", branch = "release/bmc-v0.6" }
rgb-std = { git = "https://github.com/crisdut/rgb-wallet", branch = "release/bmc-v0.6" }
rgb-core = { git = "https://github.com/crisdut/rgb-core" }
22 changes: 15 additions & 7 deletions src/rgb/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ use rgbstd::contract::GenesisSeal;
use rgbstd::interface::rgb21::{Allocation, EmbeddedMedia, OwnedFraction, TokenData, TokenIndex};
use rgbstd::resolvers::ResolveHeight;
use rgbstd::stl::{
DivisibleAssetSpec, MediaType, Name, Precision, RicardianContract, Ticker, Timestamp,
Amount, ContractData, DivisibleAssetSpec, MediaType, Name, Precision, RicardianContract,
Ticker, Timestamp,
};
use rgbstd::validation::ResolveTx;
use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};

use rgbstd::containers::Contract;
use rgbstd::interface::{rgb20, rgb21, BuilderError, ContractBuilder};
Expand Down Expand Up @@ -118,7 +120,8 @@ fn issue_fungible_asset(
let description: &'static str = Box::leak(description.to_string().into_boxed_str());
let precision = Precision::try_from(precision).expect("invalid precision");
let spec = DivisibleAssetSpec::new(ticker, name, precision);
let terms = RicardianContract::new(description);
let terms = RicardianContract::from_str(description).expect("invalid terms");
let contract_data = ContractData { terms, media: None };
let created = Timestamp::default();
// Issuer State
let seal = ExplicitSeal::<Txid>::from_str(seal).expect("invalid seal definition");
Expand All @@ -131,9 +134,11 @@ fn issue_fungible_asset(
.expect("invalid spec")
.add_global_state("created", created)
.expect("invalid created")
.add_global_state("terms", terms)
.add_global_state("data", contract_data)
.expect("invalid contract text")
.add_fungible_state("beneficiary", seal, supply)
.add_global_state("issuedSupply", Amount::from(supply))
.expect("invalid issued supply")
.add_fungible_state("assetOwner", seal, supply)
.expect("invalid asset amount")
.issue_contract()
.expect("contract doesn't fit schema requirements");
Expand Down Expand Up @@ -161,8 +166,11 @@ fn issue_uda_asset(
let description: &'static str = Box::leak(description.to_string().into_boxed_str());
let precision = Precision::try_from(precision).expect("invalid precision");
let spec = DivisibleAssetSpec::new(ticker, name, precision);
let terms = RicardianContract::new(description);
let created = Timestamp::default();
let terms = RicardianContract::from_str(description).expect("invalid terms");
let start = SystemTime::now();
let since_the_epoch = start.duration_since(UNIX_EPOCH).expect("invalid");
let created =
Timestamp::from_str(&since_the_epoch.as_secs_f32().to_string()).expect("invalid timestamp");
let fraction = OwnedFraction::from_inner(supply);

let mut tokens_data = vec![];
Expand Down Expand Up @@ -242,7 +250,7 @@ fn issue_uda_asset(

for allocation in allocations {
contract = contract
.add_data_state("beneficiary", seal, allocation)
.add_data_state("assetOwner", seal, allocation)
.expect("invalid asset blob");
}

Expand Down
10 changes: 1 addition & 9 deletions src/rgb/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use std::{collections::HashMap, str::FromStr};

use bitcoin::Address;
use bitcoin_scripts::address::AddressCompat;
use bp::Outpoint;
use rgb::{interface::OutpointFilter, RgbWallet, TerminalPath};
use rgb::{RgbWallet, TerminalPath};

use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -40,10 +39,3 @@ pub struct AddressTerminal {
pub address: AddressCompat,
pub terminal: TerminalPath,
}

pub struct EmptyFilter {}
impl OutpointFilter for EmptyFilter {
fn include_outpoint(&self, _outpoint: Outpoint) -> bool {
true
}
}
7 changes: 2 additions & 5 deletions src/rgb/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use std::{
};
use strict_encoding::tn;

use crate::rgb::structs::EmptyFilter;
use crate::rgb::{resolvers::ResolveSpent, structs::AddressTerminal};
use crate::structs::{AllocationDetail, AllocationValue, UDAPosition, WatcherDetail};

Expand Down Expand Up @@ -311,14 +310,13 @@ where
};

sync_wallet(iface_index, wallet, resolver);
let empty = EmptyFilter {};
let mut details = vec![];
for contract_id in stock.contract_ids()? {
let iface = stock.iface_by_name(&tn!(iface_name))?;
if let Ok(contract) = stock.contract_iface(contract_id, iface.iface_id()) {
let mut owners = vec![];
for owned in &contract.iface.assignments {
if let Ok(allocations) = contract.fungible(owned.name.clone(), Some(&empty)) {
if let Ok(allocations) = contract.fungible(owned.name.clone(), &None) {
for allocation in allocations {
let txid = bitcoin::Txid::from_str(&allocation.owner.txid.to_hex())
.expect("invalid txid");
Expand Down Expand Up @@ -400,7 +398,6 @@ pub fn allocations_by_contract<T>(
where
T: ResolveSpent + Resolver,
{
let empty = EmptyFilter {};
let iface_name = match iface_index {
20 => "RGB20",
21 => "RGB21",
Expand All @@ -412,7 +409,7 @@ where
if let Ok(contract) = stock.contract_iface(contract_id, iface.iface_id()) {
sync_wallet(iface_index, wallet, resolver);
for owned in &contract.iface.assignments {
if let Ok(allocations) = contract.fungible(owned.name.clone(), Some(&empty)) {
if let Ok(allocations) = contract.fungible(owned.name.clone(), &None) {
for allocation in allocations {
let txid = bitcoin::Txid::from_str(&allocation.owner.txid.to_hex())
.expect("invalid txid");
Expand Down
1 change: 1 addition & 0 deletions src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ impl UDAPosition {
pub fn with(uda: AllocationUDA) -> Self {
UDAPosition {
token_index: uda
.clone()
.token_id()
.to_string()
.parse()
Expand Down
16 changes: 9 additions & 7 deletions tests/rgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ mod rgb {
// TODO: Review after support multi-token transfer
// mod collectibles;
mod collectibles;
mod fungibles;

mod import;
mod issue;
mod states;
mod stress;
mod transfers;
mod udas;
// TODO: Uncomment after fixing slow encoding/decoding of strict type
// mod fungibles;
// mod states;
// mod stress;
// mod transfers;
// mod udas;
pub mod utils;
mod watcher;
}
Expand All @@ -30,7 +32,7 @@ mod rgb {
}

mod sre {
mod st130;
mod st130_web;
mod st140;
mod st140_web;
}
}
2 changes: 1 addition & 1 deletion tests/rgb/integration/import.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/rgb/integration/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(dead_code)]
#![cfg(not(target_arch = "wasm32"))]
use std::{collections::HashMap, env, process::Stdio};

Expand Down
2 changes: 1 addition & 1 deletion tests/rgb/sre/st130.rs → tests/rgb/sre/st140.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use percent_encoding::utf8_percent_encode;
use reqwest::Client;

#[tokio::test]
#[ignore = "No longer necessary running always, only to check re-issue operation (strict-type 1.3.0)"]
#[ignore = "No longer necessary running always, only to check re-issue operation (strict-type 1.4.0)"]
async fn allow_re_issue_rgb_contracts() -> anyhow::Result<()> {
let bitmask_endpoint = BITMASK_ENDPOINT.read().await.to_string();
let issuer_keys = save_mnemonic(
Expand Down
2 changes: 1 addition & 1 deletion tests/rgb/sre/st130_web.rs → tests/rgb/sre/st140_web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use wasm_bindgen_test::*;
wasm_bindgen_test_configure!(run_in_browser);

// #[wasm_bindgen_test]
#[ignore = "No longer necessary running always, only to check re-issue operation (strict-type 1.3.0)"]
#[ignore = "No longer necessary running always, only to check re-issue operation (strict-type 1.4.0)"]
async fn allow_re_issue_rgb_contracts() -> anyhow::Result<()> {
set_panic_hook();
let mnemonic = env!("TEST_WALLET_SEED", "TEST_WALLET_SEED variable not set");
Expand Down
2 changes: 1 addition & 1 deletion tests/rgb/web/imports.rs

Large diffs are not rendered by default.