Skip to content

Commit

Permalink
Merge pull request #4 from ckb-cell/feature/reorg
Browse files Browse the repository at this point in the history
feat: reorg local storage and reorg onchain SPV instance
  • Loading branch information
yangby-cryptape authored Mar 21, 2024
2 parents db41f4f + 6b4f9e7 commit 1871f11
Show file tree
Hide file tree
Showing 11 changed files with 581 additions and 158 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ckb-hash = "0.114"
[dependencies.ckb-bitcoin-spv-verifier]
version = "0.1.0"
git = "https://github.com/ckb-cell/ckb-bitcoin-spv"
rev = "837a307"
rev = "a6fce4b"

[features]
default = ["default-tls"]
Expand Down
10 changes: 5 additions & 5 deletions src/cli/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ pub struct Args {
impl Args {
// TODO Deploy the Bitcoin SPV contract as type script.
pub fn execute(&self) -> Result<()> {
log::info!("Try to deploy a contract on CKB.");
log::info!("Try to deploy a contract on CKB");

if self.contract_owner.network() != self.ckb.network {
let msg = "The input addresses and the selected network are not matched.";
let msg = "The input addresses and the selected network are not matched";
return Err(Error::Cli(msg.to_owned()));
}

Expand All @@ -74,7 +74,7 @@ impl Args {
Error::other(msg)
})?;
log::info!(
"The contract requires {} CKBytes for its data.",
"The contract requires {} CKBytes for its data",
HumanCapacity::from(contract_data_capacity.as_u64())
);

Expand All @@ -101,13 +101,13 @@ impl Args {
let address = CkbAddress::new(self.ckb.network, payload, true);
(address, sk)
})?;
log::info!("The contract deployer is {deployer}.");
log::info!("The contract deployer is {deployer}");

let iterator = InputIterator::new_with_address(&[deployer], &network_info);
let mut builder = SimpleTransactionBuilder::new(configuration, iterator);
builder.add_output_and_data(output, self.contract_data.pack());
let data_hash = packed::CellOutput::calc_data_hash(&self.contract_data);
log::info!("The contract data hash is {data_hash:#x}.");
log::info!("The contract data hash is {data_hash:#x}");

let mut tx_with_groups = builder.build(&Default::default())?;

Expand Down
18 changes: 10 additions & 8 deletions src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pub struct Args {
/// The start height of the new Bitcoin SPV instance.
///
/// This height should be multiples of number 2016.
///
// TODO Input hash rather than height.
#[arg(long, required = true)]
pub(crate) bitcoin_start_height: u32,

Expand Down Expand Up @@ -103,7 +105,7 @@ pub struct Args {
impl Args {
// TODO Split this method into several smaller methods.
pub fn execute(&self) -> Result<()> {
log::info!("Try to initialize a Bitcoin SPV instance on CKB.");
log::info!("Try to initialize a Bitcoin SPV instance on CKB");

self.check_inputs()?;
log::info!("The bitcoin start height is {}", self.bitcoin_start_height);
Expand Down Expand Up @@ -132,7 +134,7 @@ impl Args {
let address = CkbAddress::new(self.ckb.network, payload, true);
(address, sk)
})?;
log::info!("The contract deployer is {deployer}.");
log::info!("The contract deployer is {deployer}");

let spv_outputs_data = {
let spv_info = packed::SpvInfo::new_builder().build();
Expand All @@ -159,7 +161,7 @@ impl Args {
.build();
tx_builder.cell_dep(spv_contract_cell_dep.clone());

log::debug!("Try to find the first live cell for {deployer}.");
log::debug!("Try to find the first live cell for {deployer}");
let input0 = iterator
.next()
.transpose()
Expand All @@ -168,7 +170,7 @@ impl Args {
Error::other(msg)
})?
.ok_or_else(|| {
let msg = format!("{deployer} has no live cell.");
let msg = format!("{deployer} has no live cell");
Error::other(msg)
})?;

Expand Down Expand Up @@ -311,7 +313,7 @@ impl Args {
let mut check_result = None;
for (mut input_index, input) in iterator.enumerate() {
input_index += 1; // The first input has been handled.
log::debug!("Try to find the {input_index}-th live cell for {deployer}.");
log::debug!("Try to find the {input_index}-th live cell for {deployer}");
let input = input.map_err(|err| {
let msg = format!(
"failed to find {input_index}-th live cell for {deployer} since {err}"
Expand Down Expand Up @@ -356,7 +358,7 @@ impl Args {
check_result
}
.ok_or_else(|| {
let msg = format!("{deployer}'s live cells are not enough.");
let msg = format!("{deployer}'s live cells are not enough");
Error::other(msg)
})?;

Expand All @@ -375,7 +377,7 @@ impl Args {

fn check_inputs(&self) -> Result<()> {
if self.spv_owner.network() != self.ckb.network {
let msg = "The input addresses and the selected network are not matched.";
let msg = "The input addresses and the selected network are not matched";
return Err(Error::cli(msg));
}

Expand All @@ -401,7 +403,7 @@ impl Args {

fn check_remotes(&self) -> Result<()> {
if self.spv_owner.network() != self.ckb.network {
let msg = "The input addresses and the selected network are not matched.";
let msg = "The input addresses and the selected network are not matched";
return Err(Error::cli(msg));
}

Expand Down
Loading

0 comments on commit 1871f11

Please sign in to comment.