Skip to content

Commit

Permalink
fix: resolve ChainSpec script deserialize issue
Browse files Browse the repository at this point in the history
  • Loading branch information
quake committed Jun 20, 2019
1 parent 7a932ce commit d52fad3
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 21 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions docs/hashes.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Generated by: ckb cli hashes -b
[ckb_dev]
genesis = "0xf7a3090f495fa55d235e2101027ac9316b8bbf82c27224ca54451f5fc8bae83a"
cellbase = "0x5ec37b1f09b5c90a6d654edc02763b8d7a7f2b9af1d1fe470fa0c44f9ad547d9"
genesis = "0xd6686c89355859038a1b4e9352f9d383f8f9bdc2a05080971a6c06a93828e91f"
cellbase = "0xea25833fb17c621e230893b39ac56cd21290d69e56f7333734777c7d810f6ff1"

[[ckb_dev.system_cells]]
path = "Bundled(specs/cells/secp256k1_blake160_sighash_all)"
index = 1
code_hash = "0x94334bdda40b69bae067d84937aa6bbccf8acd0df6626d4b9ac70d4612a11933"

[ckb_testnet]
genesis = "0x9c2fa0c8404de808d13e3c46ef5646a706052c799481250b041db886757e221b"
cellbase = "0xa3d8adbbae7f67835efe29672a78bd7c7926321a891d48a0530dc792421e8620"
genesis = "0x81299410cc1609d40ed98777d6d0f3febea432b5c3f058b539bf35c4950fea9c"
cellbase = "0x7707b6270e04ababc465373f72096e3b5a2df071bb3924b57530dad32a98c1a5"

[[ckb_testnet.system_cells]]
path = "Bundled(specs/cells/secp256k1_blake160_sighash_all)"
Expand Down
2 changes: 1 addition & 1 deletion resource/specs/dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ timestamp = 0
difficulty = "0x100"
uncles_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
# run `cargo run cli hashes -b` to get the genesis hash
hash = "0xf7a3090f495fa55d235e2101027ac9316b8bbf82c27224ca54451f5fc8bae83a"
hash = "0xd6686c89355859038a1b4e9352f9d383f8f9bdc2a05080971a6c06a93828e91f"
issued_cells = []

[genesis.seal]
Expand Down
2 changes: 1 addition & 1 deletion resource/specs/testnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ timestamp = 1560578400858
difficulty = "0x9292"
uncles_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
# run `cargo run cli hashes -b` to get the genesis hash
hash = "0x9c2fa0c8404de808d13e3c46ef5646a706052c799481250b041db886757e221b"
hash = "0x81299410cc1609d40ed98777d6d0f3febea432b5c3f058b539bf35c4950fea9c"
issued_cells = []

[genesis.seal]
Expand Down
1 change: 1 addition & 0 deletions spec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ ckb-pow = { path = "../pow" }
ckb-resource = { path = "../resource" }
occupied-capacity = { path = "../util/occupied-capacity" }
dao = { path = "../util/dao" }
jsonrpc-types = { path = "../util/jsonrpc-types" }
12 changes: 6 additions & 6 deletions spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ use ckb_core::block::Block;
use ckb_core::block::BlockBuilder;
use ckb_core::extras::EpochExt;
use ckb_core::header::HeaderBuilder;
use ckb_core::script::Script;
use ckb_core::transaction::{CellInput, CellOutput, Transaction, TransactionBuilder};
use ckb_core::{BlockNumber, Bytes, Capacity, Cycle};
use ckb_pow::{Pow, PowEngine};
use ckb_resource::Resource;
use jsonrpc_types::Script;
use numext_fixed_hash::H256;
use numext_fixed_uint::U256;
use serde_derive::{Deserialize, Serialize};
Expand Down Expand Up @@ -189,7 +189,7 @@ impl ChainSpec {
.set_epoch_reward(self.params.epoch_reward)
.set_secondary_epoch_reward(self.params.secondary_epoch_reward)
.set_max_block_cycles(self.params.max_block_cycles)
.set_bootstrap_lock(self.genesis.bootstrap_lock.clone())
.set_bootstrap_lock(self.genesis.bootstrap_lock.clone().into())
.set_pow(self.pow.clone());

Ok(consensus)
Expand Down Expand Up @@ -237,23 +237,23 @@ impl GenesisCell {
fn build_output(&self) -> Result<CellOutput, Box<dyn Error>> {
let mut cell = CellOutput::default();
cell.data = self.message.as_bytes().into();
cell.lock.clone_from(&self.lock);
cell.lock = self.lock.clone().into();
cell.capacity = cell.occupied_capacity()?;
Ok(cell)
}
}

fn build_bootstrap_output(lock: &Script) -> Result<CellOutput, Box<dyn Error>> {
let mut cell = CellOutput::default();
cell.lock.clone_from(lock);
cell.lock = lock.clone().into();
cell.capacity = cell.occupied_capacity()?;
Ok(cell)
}

impl IssuedCell {
fn build_output(&self) -> CellOutput {
let mut cell = CellOutput::default();
cell.lock = self.lock.clone();
cell.lock = self.lock.clone().into();
cell.capacity = self.capacity;
cell
}
Expand All @@ -269,7 +269,7 @@ impl SystemCells {
let data = res.get()?;
let mut cell = CellOutput::default();
cell.data = data.into_owned().into();
cell.lock.clone_from(&self.lock);
cell.lock = self.lock.clone().into();
cell.capacity = cell.occupied_capacity()?;
outputs.push(cell);
}
Expand Down
22 changes: 13 additions & 9 deletions test/src/specs/mining/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{Net, Spec, DEFAULT_TX_PROPOSAL_WINDOW};
use ckb_app_config::{BlockAssemblerConfig, CKBAppConfig};
use ckb_chain_spec::ChainSpec;
use ckb_core::block::Block;
use ckb_core::script::Script;
use ckb_core::script::Script as CoreScript;
use ckb_core::Bytes;
use jsonrpc_types::JsonBytes;
use log::info;
Expand All @@ -19,13 +19,13 @@ impl Spec for BootstrapCellbase {
.map(|_| node.generate_block())
.collect();

let bootstrap_lock = Script {
args: vec![],
let bootstrap_lock = CoreScript {
args: vec![Bytes::from(vec![1]), Bytes::from(vec![2])],
code_hash: h256!("0xa1"),
};

let miner = Script {
args: vec![],
let miner = CoreScript {
args: vec![Bytes::from(vec![2]), Bytes::from(vec![1])],
code_hash: h256!("0xa2"),
};

Expand Down Expand Up @@ -57,18 +57,22 @@ impl Spec for BootstrapCellbase {

fn modify_chain_spec(&self) -> Box<dyn Fn(&mut ChainSpec) -> ()> {
Box::new(|spec_config| {
spec_config.genesis.bootstrap_lock = Script {
args: vec![],
spec_config.genesis.bootstrap_lock = CoreScript {
args: vec![Bytes::from(vec![1]), Bytes::from(vec![2])],
code_hash: h256!("0xa1"),
};
}
.into();
})
}

fn modify_ckb_config(&self) -> Box<dyn Fn(&mut CKBAppConfig) -> ()> {
Box::new(|config| {
config.block_assembler = Some(BlockAssemblerConfig {
code_hash: h256!("0xa2"),
args: vec![],
args: vec![
JsonBytes::from_bytes(Bytes::from(vec![2])),
JsonBytes::from_bytes(Bytes::from(vec![1])),
],
data: JsonBytes::from_bytes(Bytes::from(vec![1; 30])),
});
})
Expand Down

0 comments on commit d52fad3

Please sign in to comment.