Skip to content

Commit

Permalink
Merge #344
Browse files Browse the repository at this point in the history
344: refactor: Revise script structure r=doitian a=xxuejie

* [x] rfc changes: nervosnetwork/rfcs#91
* [x] ckb-system-scripts: nervosnetwork/ckb-system-scripts#2
* [x] mruby-contracts: nervosnetwork/mruby-contracts#7
* [x] ruby sdk: nervosnetwork/ckb-demo-ruby#76
* [x] ruby scripts: nervosnetwork/ckb-ruby-scripts#9
* [ ] swift sdk
* [ ] java sdk
* [ ] js sdk

---

This is a **BREAKING CHANGE**.

Co-authored-by: Xuejie Xiao <[email protected]>
  • Loading branch information
bors[bot] and xxuejie committed Mar 27, 2019
2 parents fdb3dfb + 6fe7668 commit af3ffe7
Show file tree
Hide file tree
Showing 42 changed files with 641 additions and 659 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ numext-fixed-uint = { version = "0.1", features = ["support_rand", "support_heap
rand = "0.6"
tempfile = "3.0"
ckb-traits = { path = "../traits" }
hash = {path = "../util/hash"}

[[bench]]
name = "cuckoo"
Expand Down
24 changes: 14 additions & 10 deletions benches/benches/process_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use ckb_shared::shared::{Shared, SharedBuilder};
use ckb_shared::store::ChainKVStore;
use ckb_traits::ChainProvider;
use criterion::{criterion_group, criterion_main, Criterion};
use hash::blake2b_256;
use numext_fixed_hash::H256;
use numext_fixed_uint::U256;
use rand::random;
Expand Down Expand Up @@ -139,17 +140,18 @@ fn new_chain() -> (
) {
let cellbase = TransactionBuilder::default()
.input(CellInput::new_cellbase_input(0))
.output(CellOutput::new(0, vec![], H256::zero(), None))
.output(CellOutput::new(0, vec![], Script::default(), None))
.build();

let script = create_script();
let (script, binary) = create_script();

// create genesis block with 100 tx
let commit_transactions: Vec<Transaction> = (0..100)
.map(|i| {
TransactionBuilder::default()
.input(CellInput::new(OutPoint::null(), script.clone()))
.output(CellOutput::new(50000, vec![i], script.type_hash(), None))
.input(CellInput::new(OutPoint::null(), vec![]))
.output(CellOutput::new(50000, vec![i], script.clone(), None))
.embed(binary.clone())
.build()
})
.collect();
Expand Down Expand Up @@ -185,7 +187,7 @@ fn gen_block(blocks: &mut Vec<Block>, parent_index: usize) {

let cellbase = TransactionBuilder::default()
.input(CellInput::new_cellbase_input(number))
.output(CellOutput::new(0, vec![], H256::zero(), None))
.output(CellOutput::new(0, vec![], Script::default(), None))
.build();

// spent n-2 block's tx and proposal n-1 block's tx
Expand Down Expand Up @@ -225,20 +227,22 @@ fn gen_block(blocks: &mut Vec<Block>, parent_index: usize) {
}

fn create_transaction(hash: H256) -> Transaction {
let script = create_script();
let (script, binary) = create_script();
TransactionBuilder::default()
.output(CellOutput::new(50000, vec![], script.type_hash(), None))
.input(CellInput::new(OutPoint::new(hash, 0), script))
.output(CellOutput::new(50000, vec![], script, None))
.input(CellInput::new(OutPoint::new(hash, 0), vec![]))
.embed(binary)
.build()
}

fn create_script() -> Script {
fn create_script() -> (Script, Vec<u8>) {
let mut file = File::open(
Path::new(env!("CARGO_MANIFEST_DIR")).join("../nodes_template/spec/cells/always_success"),
)
.unwrap();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).unwrap();

Script::new(0, Vec::new(), None, Some(buffer), Vec::new())
let script = Script::new(0, vec![], (&blake2b_256(&buffer)).into());
(script, buffer)
}
1 change: 1 addition & 0 deletions chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ lru-cache = { git = "https://github.com/nervosnetwork/lru-cache" }
serde = "1.0"
ckb-traits = { path = "../traits" }
failure = "0.1.5"
hash = {path = "../util/hash"}

[dev-dependencies]
env_logger = "0.6"
Expand Down
6 changes: 3 additions & 3 deletions chain/src/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use ckb_core::block::Block;
use ckb_core::block::BlockBuilder;
use ckb_core::cell::{CellProvider, CellStatus};
use ckb_core::header::HeaderBuilder;
use ckb_core::script::Script;
use ckb_core::transaction::{CellInput, CellOutput, OutPoint, TransactionBuilder};
use ckb_shared::error::SharedError;
use ckb_traits::ChainProvider;
use numext_fixed_hash::H256;
use numext_fixed_uint::U256;
use std::sync::Arc;

Expand All @@ -19,7 +19,7 @@ fn test_genesis_transaction_spend() {
CellOutput::new(
100_000_000,
vec![],
H256::default(),
Script::default(),
None
);
100
Expand Down Expand Up @@ -349,7 +349,7 @@ fn test_genesis_transaction_fetch() {
CellOutput::new(
100_000_000,
vec![],
H256::default(),
Script::default(),
None
);
100
Expand Down
28 changes: 12 additions & 16 deletions chain/src/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use ckb_shared::shared::Shared;
use ckb_shared::shared::SharedBuilder;
use ckb_shared::store::ChainKVStore;
use faketime::unix_time_as_millis;
use hash::blake2b_256;
use numext_fixed_hash::H256;
use numext_fixed_uint::U256;
use std::fs::File;
Expand All @@ -37,14 +38,11 @@ pub(crate) fn start_chain(
}

fn create_cellbase(number: BlockNumber) -> Transaction {
let (script, binary) = create_script();
TransactionBuilder::default()
.input(CellInput::new_cellbase_input(number))
.output(CellOutput::new(
5000,
vec![],
create_script().type_hash(),
None,
))
.output(CellOutput::new(5000, vec![], script, None))
.embed(binary)
.build()
}

Expand Down Expand Up @@ -78,24 +76,22 @@ pub(crate) fn gen_block(
}

pub(crate) fn create_transaction(parent: H256, unique_data: u8) -> Transaction {
let script = create_script();
let (script, binary) = create_script();
TransactionBuilder::default()
.output(CellOutput::new(
5000,
vec![unique_data],
script.type_hash(),
None,
))
.input(CellInput::new(OutPoint::new(parent, 0), script))
.output(CellOutput::new(5000, vec![unique_data], script, None))
.input(CellInput::new(OutPoint::new(parent, 0), vec![]))
.embed(binary)
.build()
}

fn create_script() -> Script {
fn create_script() -> (Script, Vec<u8>) {
let mut file = File::open(
Path::new(env!("CARGO_MANIFEST_DIR")).join("../nodes_template/spec/cells/always_success"),
)
.unwrap();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).unwrap();
Script::new(0, Vec::new(), None, Some(buffer), Vec::new())

let script = Script::new(0, Vec::new(), (&blake2b_256(&buffer)).into());
(script, buffer)
}
3 changes: 2 additions & 1 deletion core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ impl ResolvedTransaction {

#[cfg(test)]
mod tests {
use super::super::script::Script;
use super::*;
use numext_fixed_hash::H256;
use std::collections::HashMap;
Expand Down Expand Up @@ -241,7 +242,7 @@ mod tests {
let o = CellOutput {
capacity: 2,
data: vec![],
lock: H256::default(),
lock: Script::default(),
type_: None,
};

Expand Down
Loading

0 comments on commit af3ffe7

Please sign in to comment.