-
Notifications
You must be signed in to change notification settings - Fork 21
/
build.rs
188 lines (153 loc) · 6.48 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
use std::{collections::BTreeMap, env, fs, path};
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_RGB_CONTRACT: IdVersionMap,
LIB_ID_RGB20: IdVersionMap,
LIB_ID_RGB21: IdVersionMap,
LIB_ID_RGB25: IdVersionMap,
LIB_ID_RGB_STD: IdVersionMap,
}
const LIB_IDS_FILE: &str = "RGB_LIB_IDs.toml";
const FILE_COMMENT: &str =
"# Auto-generated semantic IDs for RGB consensus-critical libraries and their corresponding versions of bitmask-core.\n\n";
const LIB_ID_RGB_COMMENT: &str =
"[LIB_ID_RGB]\n# Consensus-breaking: If changed, assets must be reissued";
const LIB_ID_RGB_CONTRACT_COMMENT: &str =
"[LIB_ID_RGB_CONTRACT]\n# Interface-only: If changed, only a new interface implementation is needed. No reiussance or migration necessary.";
const LIB_ID_RGB_STD_COMMENT: &str =
"[LIB_ID_RGB_STD]\n# Not consensus-breaking: If changed, only stash and consignments must be updated. No reiussance or migration necessary.";
type HashNameMap = BTreeMap<String, String>;
#[allow(non_snake_case)]
#[derive(Deserialize, Serialize)]
struct FileHashes {
ASSETS_STOCK: HashNameMap,
ASSETS_WALLETS: HashNameMap,
ASSETS_TRANSFERS: HashNameMap,
ASSETS_OFFERS: HashNameMap,
ASSETS_BIDS: HashNameMap,
MARKETPLACE_OFFERS: HashNameMap,
MARKETPLACE_BIDS: HashNameMap,
}
const FILE_HASHES_FILE: &str = "file_hashes.toml";
const ASSETS_STOCK: &str = "bitmask-fungible_assets_stock.c15";
const ASSETS_WALLETS: &str = "bitmask-fungible_assets_wallets.c15";
const ASSETS_TRANSFERS: &str = "bitmask_assets_transfers.c15";
const ASSETS_OFFERS: &str = "bitmask-asset_offers.c15";
const ASSETS_BIDS: &str = "bitmask-asset_bids.c15";
const MARKETPLACE_OFFERS: &str = "bitmask-marketplace_public_offers.c15";
const MARKETPLACE_BIDS: &str = "bitmask-marketplace_public_bids.c15";
const NETWORK: &str = "bitcoin"; // Only mainnet is tracked, no monetary incentive to upgrade testnet assets
#[derive(Serialize, Deserialize, Default)]
pub struct MetricsData {
bytes: u64,
bytes_by_day: BTreeMap<String, u64>,
bitcoin_wallets_by_day: BTreeMap<String, usize>,
signet_wallets_by_day: BTreeMap<String, usize>,
testnet_wallets_by_day: BTreeMap<String, usize>,
regtest_wallets_by_day: BTreeMap<String, usize>,
wallets_by_network: BTreeMap<String, usize>,
}
pub fn init_fs() -> Result<()> {
let dir = env::var("CARBONADO_DIR").unwrap_or("/tmp/bitmaskd/carbonado".to_owned());
let dir = path::Path::new(&dir);
fs::create_dir_all(dir)?;
fs::write(
dir.join("metrics.json"),
serde_json::to_string_pretty(&MetricsData::default())?,
)?;
Ok(())
}
fn main() -> Result<()> {
// lib ids
const BMC_VERSION: &str = env!("CARGO_PKG_VERSION");
let toml = fs::read_to_string(LIB_IDS_FILE)?;
let mut doc: LibIds = toml::from_str(&toml)?;
doc.LIB_ID_RGB
.entry(LIB_ID_RGB.to_owned())
.or_insert(BMC_VERSION.to_owned());
doc.LIB_ID_RGB_CONTRACT
.entry(LIB_ID_RGB_CONTRACT.to_owned())
.or_insert(BMC_VERSION.to_owned());
doc.LIB_ID_RGB20
.entry(LIB_ID_RGB20.to_owned())
.or_insert(BMC_VERSION.to_owned());
doc.LIB_ID_RGB21
.entry(LIB_ID_RGB21.to_owned())
.or_insert(BMC_VERSION.to_owned());
doc.LIB_ID_RGB25
.entry(LIB_ID_RGB25.to_owned())
.or_insert(BMC_VERSION.to_owned());
doc.LIB_ID_RGB_STD
.entry(LIB_ID_RGB_STD.to_owned())
.or_insert(BMC_VERSION.to_owned());
let toml = toml::to_string(&doc)?;
let toml = toml.replace("[LIB_ID_RGB]", LIB_ID_RGB_COMMENT);
let toml = toml.replace("[LIB_ID_RGB_CONTRACT]", LIB_ID_RGB_CONTRACT_COMMENT);
let toml = toml.replace("[LIB_ID_RGB_STD]", LIB_ID_RGB_STD_COMMENT);
fs::write(LIB_IDS_FILE, format!("{FILE_COMMENT}{toml}"))?;
// file hashes
let toml = fs::read_to_string(FILE_HASHES_FILE)?;
let mut doc: FileHashes = toml::from_str(&toml)?;
let assets_stock_name = format!("{LIB_ID_RGB}-{ASSETS_STOCK}");
let assets_wallets_name = format!("{LIB_ID_RGB}-{ASSETS_WALLETS}");
let assets_transfers_name = format!("{LIB_ID_RGB}-{ASSETS_TRANSFERS}");
let assets_offers_name = format!("{LIB_ID_RGB}-{ASSETS_OFFERS}");
let assets_bids_name = format!("{LIB_ID_RGB}-{ASSETS_BIDS}");
let marketplace_offers_name = format!("{LIB_ID_RGB}-{MARKETPLACE_OFFERS}");
let marketplace_bids_name = format!("{LIB_ID_RGB}-{MARKETPLACE_BIDS}");
let assets_stock_hash = blake3::hash(assets_stock_name.as_bytes())
.to_hex()
.to_ascii_lowercase();
let assets_wallets_hash = blake3::hash(assets_wallets_name.as_bytes())
.to_hex()
.to_ascii_lowercase();
let assets_transfers_hash = blake3::hash(assets_transfers_name.as_bytes())
.to_hex()
.to_ascii_lowercase();
let assets_offers_hash = blake3::hash(assets_offers_name.as_bytes())
.to_hex()
.to_ascii_lowercase();
let assets_bids_hash = blake3::hash(assets_bids_name.as_bytes())
.to_hex()
.to_ascii_lowercase();
let marketplace_offers_hash = blake3::hash(marketplace_offers_name.as_bytes())
.to_hex()
.to_ascii_lowercase();
let marketplace_bids_hash = blake3::hash(marketplace_bids_name.as_bytes())
.to_hex()
.to_ascii_lowercase();
doc.ASSETS_STOCK
.entry(format!("{NETWORK}-{assets_stock_hash}.c15"))
.or_insert(assets_stock_name);
doc.ASSETS_WALLETS
.entry(format!("{NETWORK}-{assets_wallets_hash}.c15"))
.or_insert(assets_wallets_name);
doc.ASSETS_TRANSFERS
.entry(format!("{NETWORK}-{assets_transfers_hash}.c15"))
.or_insert(assets_transfers_name);
doc.ASSETS_OFFERS
.entry(format!("{NETWORK}-{assets_offers_hash}.c15"))
.or_insert(assets_offers_name);
doc.ASSETS_BIDS
.entry(format!("{NETWORK}-{assets_bids_hash}.c15"))
.or_insert(assets_bids_name);
doc.MARKETPLACE_OFFERS
.entry(format!("{NETWORK}-{marketplace_offers_hash}.c15"))
.or_insert(marketplace_offers_name);
doc.MARKETPLACE_BIDS
.entry(format!("{NETWORK}-{marketplace_bids_hash}.c15"))
.or_insert(marketplace_bids_name);
let toml = toml::to_string(&doc)?;
fs::write(FILE_HASHES_FILE, toml)?;
init_fs()?;
Ok(())
}