Skip to content

Commit

Permalink
Add an RGB_LIB_IDs.toml file, and build script to auto-generate it (#270
Browse files Browse the repository at this point in the history
)

* Add an RGB_LIB_IDs.toml file, and build script to auto-generate it.

* Add LIB_ID_RGB to build.rs.

* bump: update dependencies

---------

Co-authored-by: Armando Dutra <[email protected]>
  • Loading branch information
cryptoquick and crisdut authored Jul 14, 2023
1 parent b3a82ad commit 23da169
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 28 deletions.
14 changes: 8 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ miniscript_crate = { package = "miniscript", version = "9.0.1", features = [
] }
nostr-sdk = "0.22.0"
once_cell = "1.17.1"
payjoin = { version = "0.7.0", features = ["sender"] }
payjoin = { version = "0.8.0", features = ["send"] }
percent-encoding = "2.2.0"
postcard = { version = "1.0.4", features = ["alloc"] }
pretty_env_logger = "0.5.0"
Expand Down Expand Up @@ -120,6 +120,12 @@ tokio = { version = "1.28.2", features = ["full"] }
[dev-dependencies]
wasm-bindgen-test = "0.3.36"

[build-dependencies]
anyhow = "1.0.71"
rgb-std = { version = "0.10.2" }
serde = "1.0.164"
toml = { version = "0.7.5", features = ["preserve_order"] }

[patch.crates-io]
# TODO: Remove this after support amplify 4.x (custom)
bitcoin_scripts = { git = "https://github.com/crisdut/bp-foundation", branch = "release/0.10.0-alpha.2" }
Expand Down
19 changes: 19 additions & 0 deletions RGB_LIB_IDs.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Auto-generated semantic IDs for RGB consensus-critical libraries and their corresponding versions of bitmask-core.

[LIB_ID_RGB]
memphis_asia_crash_4fGZWR5mH5zZzRZ1r7CSRe776zm3hLBUngfXc4s3vm3V = "0.6.0-rc.6"

[LIB_ID_RGB20]
dragon_table_game_GVz4mvYE94aQ9q2HPtV9VuoppcDdduP54BMKffF7YoFH = "0.6.0-rc.6"

[LIB_ID_RGB21]
benny_horse_salad_E3AsDKsHSqAPQLvJke3DcPrkErbS2Jxf8pQ8jYBQYJPA = "0.6.0-rc.6"

[LIB_ID_RGB25]
ritual_mask_next_4JmGrg7oTgwuCQtyC4ezC38ToHMzgMCVS5kMSDPwo2ee = "0.6.0-rc.6"

[LIB_ID_RGB_CONTRACT]
price_canvas_oliver_9Te5P6nq3oaDHMgttLEbkojbeQPTqqZLhjxZ3my1F8aJ = "0.6.0-rc.6"

[LIB_ID_RGB_STD]
patent_iris_torch_Firwvn75qng8cm4n7iHXXiFDsG1V476vYGqdfwwFRT1b = "0.6.0-rc.6"
67 changes: 67 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use std::{collections::BTreeMap, fs};

use anyhow::Result;
use rgbstd::{
interface::{LIB_ID_RGB20, LIB_ID_RGB21, LIB_ID_RGB25},
stl::{LIB_ID_RGB, LIB_ID_RGB_CONTRACT, LIB_ID_RGB_STD},
};
use serde::{Deserialize, Serialize};

type IdVersionMap = BTreeMap<String, String>;

#[allow(non_snake_case)]
#[derive(Deserialize, Serialize)]
struct LibIds {
LIB_ID_RGB: IdVersionMap,
LIB_ID_RGB20: IdVersionMap,
LIB_ID_RGB21: IdVersionMap,
LIB_ID_RGB25: IdVersionMap,
LIB_ID_RGB_CONTRACT: IdVersionMap,
LIB_ID_RGB_STD: IdVersionMap,
}

const LIB_IDS_FILE: &str = "RGB_LIB_IDs.toml";
const NOTE_COMMENT: &str =
"# Auto-generated semantic IDs for RGB consensus-critical libraries and their corresponding versions of bitmask-core.\n\n";

fn main() -> Result<()> {
const BMC_VERSION: &str = env!("CARGO_PKG_VERSION");

let lib_ids_file = fs::read_to_string(LIB_IDS_FILE)?;
let mut lib_ids: LibIds = toml::from_str(&lib_ids_file)?;

lib_ids
.LIB_ID_RGB
.entry(LIB_ID_RGB.to_owned())
.or_insert(BMC_VERSION.to_owned());

lib_ids
.LIB_ID_RGB20
.entry(LIB_ID_RGB20.to_owned())
.or_insert(BMC_VERSION.to_owned());

lib_ids
.LIB_ID_RGB21
.entry(LIB_ID_RGB21.to_owned())
.or_insert(BMC_VERSION.to_owned());

lib_ids
.LIB_ID_RGB25
.entry(LIB_ID_RGB25.to_owned())
.or_insert(BMC_VERSION.to_owned());

lib_ids
.LIB_ID_RGB_CONTRACT
.entry(LIB_ID_RGB_CONTRACT.to_owned())
.or_insert(BMC_VERSION.to_owned());

lib_ids
.LIB_ID_RGB_STD
.entry(LIB_ID_RGB_STD.to_owned())
.or_insert(BMC_VERSION.to_owned());

let toml = toml::to_string(&lib_ids)?;
fs::write(LIB_IDS_FILE, format!("{NOTE_COMMENT}{toml}"))?;

Ok(())
}
3 changes: 2 additions & 1 deletion src/bitcoin/payment.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::{anyhow, Result};
use bdk::{wallet::tx_builder::TxOrdering, FeeRate, TransactionDetails};
use bitcoin::consensus::serialize;
use payjoin::send::Configuration;
use payjoin::{PjUri, PjUriExt};

use crate::{
Expand Down Expand Up @@ -58,7 +59,7 @@ pub async fn create_payjoin(
info!("Original PSBT successfully signed");

// TODO use fee_rate
let pj_params = payjoin::sender::Configuration::non_incentivizing();
let pj_params = Configuration::non_incentivizing();
let (req, ctx) = pj_uri.create_pj_request(original_psbt, pj_params)?;
info!("Built PayJoin request");
let response = reqwest::Client::new()
Expand Down
20 changes: 10 additions & 10 deletions tests/rgb/unit/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@ use rgbstd::{

#[tokio::test]
async fn check_rgb20_stl() -> Result<()> {
let shema = rgb20_stl();
assert_eq!(LIB_ID_RGB20, shema.id().to_string());
let schema = rgb20_stl();
assert_eq!(LIB_ID_RGB20, schema.id().to_string());
Ok(())
}

#[tokio::test]
async fn check_rgb21_stl() -> Result<()> {
let shema = rgb21_stl();
assert_eq!(LIB_ID_RGB21, shema.id().to_string());
let schema = rgb21_stl();
assert_eq!(LIB_ID_RGB21, schema.id().to_string());
Ok(())
}

#[tokio::test]
async fn check_rgb25_stl() -> Result<()> {
let shema = rgb25_stl();
assert_eq!(LIB_ID_RGB25, shema.id().to_string());
let schema = rgb25_stl();
assert_eq!(LIB_ID_RGB25, schema.id().to_string());
Ok(())
}

#[tokio::test]
async fn check_rgbstd_stl() -> Result<()> {
let shema = rgb_std_stl();
assert_eq!(LIB_ID_RGB_STD, shema.id().to_string());
let schema = rgb_std_stl();
assert_eq!(LIB_ID_RGB_STD, schema.id().to_string());
Ok(())
}

#[tokio::test]
async fn check_rgbcontract_stl() -> Result<()> {
let shema = rgb_contract_stl();
assert_eq!(LIB_ID_RGB_CONTRACT, shema.id().to_string());
let schema = rgb_contract_stl();
assert_eq!(LIB_ID_RGB_CONTRACT, schema.id().to_string());
Ok(())
}
20 changes: 10 additions & 10 deletions tests/rgb/web/stl_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ wasm_bindgen_test_configure!(run_in_browser);

#[wasm_bindgen_test]
async fn check_rgb20_stl() {
let shema = rgb20_stl();
assert_eq!(LIB_ID_RGB20, shema.id().to_string());
let schema = rgb20_stl();
assert_eq!(LIB_ID_RGB20, schema.id().to_string());
}

#[wasm_bindgen_test]
async fn check_rgb21_stl() {
let shema = rgb21_stl();
assert_eq!(LIB_ID_RGB21, shema.id().to_string());
let schema = rgb21_stl();
assert_eq!(LIB_ID_RGB21, schema.id().to_string());
}

#[wasm_bindgen_test]
async fn check_rgb25_stl() {
let shema = rgb25_stl();
assert_eq!(LIB_ID_RGB25, shema.id().to_string());
let schema = rgb25_stl();
assert_eq!(LIB_ID_RGB25, schema.id().to_string());
}

#[wasm_bindgen_test]
async fn check_rgbstd_stl() {
let shema = rgb_std_stl();
assert_eq!(LIB_ID_RGB_STD, shema.id().to_string());
let schema = rgb_std_stl();
assert_eq!(LIB_ID_RGB_STD, schema.id().to_string());
}

#[wasm_bindgen_test]
async fn check_rgbcontract_stl() {
let shema = rgb_contract_stl();
assert_eq!(LIB_ID_RGB_CONTRACT, shema.id().to_string());
let schema = rgb_contract_stl();
assert_eq!(LIB_ID_RGB_CONTRACT, schema.id().to_string());
}

0 comments on commit 23da169

Please sign in to comment.