diff --git a/config/dev.toml b/dev-config.toml
similarity index 100%
rename from config/dev.toml
rename to dev-config.toml
diff --git a/dev-spec.toml b/dev-spec.toml
new file mode 100644
index 0000000..81cd0b1
--- /dev/null
+++ b/dev-spec.toml
@@ -0,0 +1,261 @@
+name = "ckb_dev"
+
+[genesis]
+version = 0
+parent_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
+timestamp = 0
+compact_target = 0x20010000
+uncles_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
+nonce = "0x0"
+
+[genesis.genesis_cell]
+message = "1708649862081"
+
+[genesis.genesis_cell.lock]
+code_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
+args = "0x"
+hash_type = "data"
+
+# An array list paths to system cell files, which is absolute or relative to
+# the directory containing this config file.
+[[genesis.system_cells]]
+file = { bundled = "specs/cells/secp256k1_blake160_sighash_all" }
+create_type_id = true
+capacity = 100_000_0000_0000
+[[genesis.system_cells]]
+file = { bundled = "specs/cells/dao" }
+create_type_id = true
+capacity = 16_000_0000_0000
+[[genesis.system_cells]]
+file = { bundled = "specs/cells/secp256k1_data" }
+create_type_id = false
+capacity = 1_048_617_0000_0000
+[[genesis.system_cells]]
+file = { bundled = "specs/cells/secp256k1_blake160_multisig_all" }
+create_type_id = true
+capacity = 100_000_0000_0000
+# [[genesis.system_cells]]
+# file = { file = "sudt" }
+# create_type_id = true
+# [[genesis.system_cells]]
+# file = { file = "xudt" }
+# create_type_id = true
+# [[genesis.system_cells]]
+# file = { file = "omnilock" }
+# create_type_id = true
+# [[genesis.system_cells]]
+# file = { bundled = "specs/cells/anyone_can_pay" }
+# create_type_id = true
+# [[genesis.system_cells]]
+# file = { file = "always_success" }
+# create_type_id = true
+# [[genesis.system_cells]]
+# file = { file = "spore/spore" }
+# create_type_id = false
+# [[genesis.system_cells]]
+# file = { file = "spore/spore_cluster" }
+# create_type_id = false
+# [[genesis.system_cells]]
+# file = { file = "spore/spore_cluster_agent" }
+# create_type_id = false
+# [[genesis.system_cells]]
+# file = { file = "spore/spore_cluster_proxy" }
+# create_type_id = false
+# [[genesis.system_cells]]
+# file = { file = "spore/spore_extension_lua" }
+# create_type_id = false
+
+[genesis.system_cells_lock]
+code_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
+args = "0x"
+hash_type = "data"
+
+# Dep group cells
+[[genesis.dep_groups]]
+name = "secp256k1_blake160_sighash_all"
+files = [
+ { bundled = "specs/cells/secp256k1_data" },
+ { bundled = "specs/cells/secp256k1_blake160_sighash_all" },
+]
+[[genesis.dep_groups]]
+name = "secp256k1_blake160_multisig_all"
+files = [
+ { bundled = "specs/cells/secp256k1_data" },
+ { bundled = "specs/cells/secp256k1_blake160_multisig_all" },
+]
+
+# For first 11 block
+[genesis.bootstrap_lock]
+code_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
+args = "0x"
+hash_type = "type"
+
+# Burn
+[[genesis.issued_cells]]
+capacity = 8_400_000_000_00000000
+lock.code_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
+lock.args = "0x62e907b15cbf27d5425399ebf6f0fb50ebb88f18"
+lock.hash_type = "data"
+
+#### account-list ####
+# issue for account private key: 0x6109170b275a09ad54877b82f7d9930f88cab5717d484fb4741ae9d1dd078cd6
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0x8e42b1999f265a0078503c4acec4d5e134534297"
+lock.hash_type = "type"
+
+# issue for account private key: 0x9f315d5a9618a39fdc487c7a67a8581d40b045bd7a42d83648ca80ef3b2cb4a1
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0x758d311c8483e0602dfad7b69d9053e3f917457d"
+lock.hash_type = "type"
+
+# issue for account private key: 0x59ddda57ba06d6e9c5fa9040bdb98b4b098c2fce6520d39f51bc5e825364697a
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0x9d1edebedf8f026c0d597c4c5cd3f45dec1f7557"
+lock.hash_type = "type"
+
+# issue for account private key: 0xf4a1fc19468b51ba9d1f0f5441fa3f4d91e625b2af105e1e37cc54bf9b19c0a1
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0xe65f823bc5a48a38515690604e503dba4eb15d61"
+lock.hash_type = "type"
+
+# issue for account private key: 0x0334ddff3b1e19af5c5fddda8dbcfb235416eaaba11cfca8acf63ad46e9f55b2
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0x9665e6bc1966ec2bfcca4f11782d2b906f38438f"
+lock.hash_type = "type"
+
+# issue for account private key: 0x6f358d92f408511707803d292efa148236a2e114d73a472be2a07e0ba49200c7
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0x0df9552f53d51a378aba267bc858dada447e8400"
+lock.hash_type = "type"
+
+# issue for account private key: 0xbde2f19c98dc5ab4cc98f73c573757a9f1782dc44398022a23f77ca752ad8fbe
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0x683188bb29502ba6e702b7c650cc80707c3f8b4b"
+lock.hash_type = "type"
+
+# issue for account private key: 0x7c1280118923ea96529909638dac9bd258251a222783f91dedbf82de15526fd2
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0x532bfb946e4b108d14758ca38e6e3b4af6801996"
+lock.hash_type = "type"
+
+# issue for account private key: 0x1fe1356d47224f34788eb099c4f67ab28a477a5a85d6ff4e54c240c11a0c693c
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0x3982ac2f4893dfcac091ef795bb778cc2a25edd9"
+lock.hash_type = "type"
+
+# issue for account private key: 0xc3255dd2bbc3accc69c82bdb2c927ab4a681146331d5e01990890fb3cd732b47
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0x5aab386e8a9f4f869776674c7181ea76fef75b55"
+lock.hash_type = "type"
+
+# issue for account private key: 0x8c3f8a6a6847a31af93000a31629f0c674e0cbb1b7cb71bdfbf4fb9dd828a518
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0xf6ca1c08a40ab3d00e2299930cf0f8c298a1a90d"
+lock.hash_type = "type"
+
+# issue for account private key: 0x11e34fc1bad213b1ce3071501a18c39e5dbf1ea2e66ac05059c36a5d1e7a56cf
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0x5cb8098824329c3a2e731641ae4e90ba0a3ec396"
+lock.hash_type = "type"
+
+# issue for account private key: 0x0a0ecce6f15c444e6d0013d6eb79c87babff2c76447f3a2f6b28023490170c1f
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0x516932280d5ff3108119fe2361d0868f1998dcc4"
+lock.hash_type = "type"
+
+# issue for account private key: 0x006250e940dbce94ad9329ac16c109acf7de98c7e4738013bdd3105d4f004d8a
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0x7a83042ddabeb27294fe62588df7acc627d4181f"
+lock.hash_type = "type"
+
+# issue for account private key: 0xfc8142dc0a6c1dc9102696e7ca730b8c05e233549ea924fafa477f5086d94ac3
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0x1416fe8e3e1d659a235f5f35b30f7cfbdf9fd77c"
+lock.hash_type = "type"
+
+# issue for account private key: 0x711aa98da3e9643170de94d6b16d3a30edf4bb231aa793aaac0fc7373c0f6322
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0xf246d3f9d94aab2688babb4802879056d9bf5810"
+lock.hash_type = "type"
+
+# issue for account private key: 0x76f51bf03e38b7f4a3c2cd8b088103e746f0e425fb0c5e0f8b22061f41c790cc
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0x4ec295923dde1b522835007f9260e8ba398dc7cb"
+lock.hash_type = "type"
+
+# issue for account private key: 0x1ef1c9cbf031d7bc181c039cebb4f2914dbad689ab268e192fe22ea314d9b4a4
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0xd7ab64e757d1177a955a5c997a6ba7feab49161b"
+lock.hash_type = "type"
+
+# issue for account private key: 0xa5808e79c243d8e026a034273ad7a5ccdcb2f982392fd0230442b1734c98a4c2
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0x9ba28269270223ba366a29dc96401910540894a4"
+lock.hash_type = "type"
+
+# issue for account private key: 0xace08599f3174f4376ae51fdc30950d4f2d731440382bb0aa1b6b0bd3a9728cd
+[[genesis.issued_cells]]
+capacity = 42_000_000_00000000
+lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
+lock.args = "0x4118c8c16749bf126b22468d030bf9de7da3717b"
+lock.hash_type = "type"
+#### account-list ####
+
+
+[params]
+initial_primary_epoch_reward = 1_917_808_21917808
+secondary_epoch_reward = 613_698_63013698
+max_block_cycles = 10_000_000_000
+cellbase_maturity = 0
+primary_epoch_reward_halving_interval = 8760
+epoch_duration_target = 14400
+genesis_epoch_length = 1000
+# For development and testing purposes only.
+# Keep difficulty be permanent if the pow is Dummy. (default: false)
+permanent_difficulty_in_dummy = true
+starting_block_limiting_dao_withdrawing_lock = 0
+
+[params.hardfork]
+ckb2023 = 0
+
+
+[pow]
+func = "Dummy"
diff --git a/index.html b/index.html
index 4ede17b..2b4947a 100644
--- a/index.html
+++ b/index.html
@@ -6,13 +6,23 @@
diff --git a/light-client-js/src/index.ts b/light-client-js/src/index.ts
index 2278e2a..6e2afd3 100644
--- a/light-client-js/src/index.ts
+++ b/light-client-js/src/index.ts
@@ -1,5 +1,5 @@
import { ClientFindCellsResponse, ClientFindTransactionsGroupedResponse, ClientFindTransactionsResponse, ClientIndexerSearchKeyLike, ClientIndexerSearchKeyTransactionLike, ClientTransactionResponse } from "@ckb-ccc/core/client";
-import { FetchResponse, JsonRpcLocalNode, JsonRpcRemoteNode, JsonRpcScriptStatus, LocalNode, localNodeTo, RemoteNode, remoteNodeTo, ScriptStatus, scriptStatusFrom, scriptStatusTo, transformFetchResponse } from "./types";
+import { FetchResponse, JsonRpcLocalNode, JsonRpcRemoteNode, JsonRpcScriptStatus, LocalNode, localNodeTo, NetworkFlag, RemoteNode, remoteNodeTo, ScriptStatus, scriptStatusFrom, scriptStatusTo, transformFetchResponse } from "./types";
import { ClientBlock, ClientBlockHeader, Hex, hexFrom, HexLike, Num, numFrom, NumLike, numToHex, TransactionLike } from "@ckb-ccc/core/barrel";
import { JsonRpcBlockHeader, JsonRpcTransformers } from "@ckb-ccc/core/advancedBarrel";
const DEFAULT_BUFFER_SIZE = 50 * (1 << 20);
@@ -26,8 +26,10 @@ class LightClient {
}
/**
* Start the light client.
+ * @param networkFlag Network flag for light-client-wasm. If you use DevNet, spec and config are necessary.
+ * @param logLevel Log Level for light-client-db-worker and light-client-wasm
*/
- async start(logLevel: "debug" | "info" = "info") {
+ async start(networkFlag: NetworkFlag, logLevel: "debug" | "info" = "info") {
this.dbWorker.postMessage({
inputBuffer: this.inputBuffer,
outputBuffer: this.outputBuffer,
@@ -36,7 +38,7 @@ class LightClient {
this.lightClientWorker.postMessage({
inputBuffer: this.inputBuffer,
outputBuffer: this.outputBuffer,
- netName: "dev",
+ networkFlag,
logLevel: logLevel
});
await new Promise((res, rej) => {
diff --git a/light-client-js/src/lightclient.worker.ts b/light-client-js/src/lightclient.worker.ts
index 09f2463..d980ef4 100644
--- a/light-client-js/src/lightclient.worker.ts
+++ b/light-client-js/src/lightclient.worker.ts
@@ -10,7 +10,7 @@ onmessage = async (evt) => {
const data = evt.data as LightClientWorkerInitializeOptions;
wasmModule.set_shared_array(data.inputBuffer, data.outputBuffer);
- await wasmModule.light_client(data.netName, data.logLevel);
+ await wasmModule.light_client(data.networkFlag, data.logLevel);
self.postMessage({});
loaded = true;
return;
diff --git a/light-client-js/src/types.ts b/light-client-js/src/types.ts
index 18a3888..1a55a45 100644
--- a/light-client-js/src/types.ts
+++ b/light-client-js/src/types.ts
@@ -10,7 +10,7 @@ interface DbWorkerInitializeOptions extends WorkerInitializeOptions {
}
interface LightClientWorkerInitializeOptions extends WorkerInitializeOptions {
- netName: string;
+ networkFlag: NetworkFlag;
};
interface LightClientFunctionCall {
@@ -150,6 +150,7 @@ export function localNodeTo(input: JsonRpcLocalNode): LocalNode {
version: input.version
})
}
+type NetworkFlag = { type: "MainNet" } | { type: "TestNet" } | { type: "DevNet"; spec: string; config: string; };
export type {
LightClientFunctionCall,
@@ -162,5 +163,6 @@ export type {
JsonRpcRemoteNode,
RemoteNode,
LocalNode,
- JsonRpcLocalNode
+ JsonRpcLocalNode,
+ NetworkFlag
}
diff --git a/light-client-wasm/src/lib.rs b/light-client-wasm/src/lib.rs
index ad9d446..9920953 100644
--- a/light-client-wasm/src/lib.rs
+++ b/light-client-wasm/src/lib.rs
@@ -26,7 +26,7 @@ use ckb_light_client_lib::{
types::RunEnv,
verify::verify_tx,
};
-use serde::Serialize;
+use serde::{Deserialize, Serialize};
use serde_wasm_bindgen::Serializer;
use wasm_bindgen::prelude::*;
@@ -47,11 +47,6 @@ static MAINNET_CONFIG: &'static str = include_str!("../../config/mainnet.toml");
static TESTNET_CONFIG: &'static str = include_str!("../../config/testnet.toml");
-static DEV_CONFIG: &'static str = include_str!("../../config/dev.toml");
-
-static DEV_SOURCE: &'static str =
- include_str!("/root/.local/share/offckb-nodejs/devnet/specs/dev.toml");
-
static STORAGE_WITH_DATA: OnceLock = OnceLock::new();
static NET_CONTROL: OnceLock = OnceLock::new();
@@ -74,9 +69,16 @@ fn status(flag: u8) -> bool {
fn change_status(flag: u8) {
START_FLAG.store(flag, Ordering::SeqCst);
}
+#[derive(Deserialize)]
+#[serde(tag = "type")]
+enum NetworkFlag {
+ MainNet,
+ TestNet,
+ DevNet { spec: String, config: String },
+}
#[wasm_bindgen]
-pub async fn light_client(net_flag: String, log_level: String) -> Result<(), JsValue> {
+pub async fn light_client(net_flag: JsValue, log_level: String) -> Result<(), JsValue> {
if !status(0b0) {
return Err(JsValue::from_str("Can't start twice"));
}
@@ -84,20 +86,19 @@ pub async fn light_client(net_flag: String, log_level: String) -> Result<(), JsV
wasm_logger::init(wasm_logger::Config::new(
log::Level::from_str(&log_level).expect("Bad log level"),
));
+ let network_flag: NetworkFlag = serde_wasm_bindgen::from_value(net_flag)?;
- let mut config = match net_flag.as_str() {
- "testnet" => TESTNET_CONFIG.parse::().unwrap(),
- "mainnet" => MAINNET_CONFIG.parse::().unwrap(),
- "dev" => DEV_CONFIG.parse::().unwrap(),
- _ => panic!("unsupport flag"),
+ let mut config = match &network_flag {
+ NetworkFlag::TestNet => TESTNET_CONFIG.parse::().unwrap(),
+ NetworkFlag::MainNet => MAINNET_CONFIG.parse::().unwrap(),
+ NetworkFlag::DevNet { config, .. } => config.parse::().unwrap(),
};
let storage = Storage::new(&config.store.path);
- let chain_spec = ChainSpec::load_from(&match config.chain.as_str() {
- "mainnet" => Resource::bundled("specs/mainnet.toml".to_string()),
- "testnet" => Resource::bundled("specs/testnet.toml".to_string()),
- "dev" => Resource::raw(DEV_SOURCE.to_string()),
- _ => panic!("unsupport flag"),
+ let chain_spec = ChainSpec::load_from(&match network_flag {
+ NetworkFlag::MainNet => Resource::bundled("specs/mainnet.toml".to_string()),
+ NetworkFlag::TestNet => Resource::bundled("specs/testnet.toml".to_string()),
+ NetworkFlag::DevNet { spec, .. } => Resource::raw(spec),
})
.expect("load spec should be OK");