Skip to content

[BREAKING CHANGE] Add MultisigVersion::Legacy and MultisigVersion::V2 #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ tokio = { version = "1" }
bytes = "1"
futures = "0.3"
jsonrpc-core = "18"
parking_lot = "0.12"
lru = "0.7.1"
dashmap = "5.4"
dyn-clone = "1.0"
Expand All @@ -39,11 +38,14 @@ ckb-traits = "0.200.0"
ckb-jsonrpc-types = "0.200.0"
ckb-hash = "0.200.0"
ckb-resource = "0.200.0"
ckb-system-scripts-v0_5_4 = { package="ckb-system-scripts", version="=0.5.4" }
ckb-system-scripts-v0_6_0 = { package="ckb-system-scripts", version="=0.6.0" }
ckb-crypto = { version = "=0.200.0", features = ["secp"] }
ckb-script = "0.200.0"
bitflags = "1.3.2"
sha3 = "0.10.1"
enum-repr-derive = "0.2.0"
hex = "0.4"

# for feature test
rand = { version = "0.7.3", optional = true }
Expand All @@ -62,5 +64,4 @@ test = []
[dev-dependencies]
clap = { version = "4.4.18", features = ["derive"] }
httpmock = "0.6"
async-global-executor = "2.3.1"
hex = "0.4"
tempfile = "3.19.1"
4 changes: 3 additions & 1 deletion check-cargotoml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function check_dependencies_for() {
fi
if [ "${depcnt}" -eq 0 ]; then
case "${dependency}" in
phf)
phf | async_trait)
# We cann't handle these crates.
printf "Warn: [%s::%s] in <%s>\n" \
"${deptype}" "${dependency}" "${pkgroot}"
Expand All @@ -178,7 +178,9 @@ function check_dependencies_for() {
}

function check_dependencies() {
echo "Checking dependencies..."
check_dependencies_for "dependencies"
echo "Checking build-dependencies..."
check_dependencies_for "build-dependencies"
# TODO: uncomment this line when `async-global-executor` updated to >= v2.2.0
# check_dependencies_for "dev-dependencies"
Expand Down
1 change: 0 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ allow = [
"CC0-1.0",
"ISC",
"MIT",
"Unicode-DFS-2016",
"BSL-1.0", # xxhash-rust 0.8.10
"Unicode-3.0",
#"MIT",
Expand Down
8 changes: 6 additions & 2 deletions examples/send_ckb_multisig_example.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ckb_sdk::{
constants::MultisigScript,
transaction::{
builder::{CkbTransactionBuilder, SimpleTransactionBuilder},
handler::HandlerContexts,
Expand All @@ -17,22 +18,25 @@ fn main() -> Result<(), Box<dyn StdErr>> {
let configuration = TransactionBuilderConfiguration::new_with_network(network_info.clone())?;

let multisig_config = MultisigConfig::new_with(
MultisigScript::V2,
vec![
h160!("0x7336b0ba900684cb3cb00f0d46d4f64c0994a562"),
h160!("0x5724c1e3925a5206944d753a6f3edaedf977d77f"),
],
0,
2,
)?;
let sender = multisig_config.to_address(network_info.network_type, None);
let sender = multisig_config.to_address(network_info.network_type, MultisigScript::V2, None);
println!("sender: {}", sender);
let receiver = Address::from_str("ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsq2qf8keemy2p5uu0g0gn8cd4ju23s5269qk8rg4r")?;

let iterator = InputIterator::new_with_address(&[sender], &network_info);
let mut builder = SimpleTransactionBuilder::new(configuration, iterator);
builder.add_output(&receiver, Capacity::shannons(510_0000_0000u64));
builder.add_output(&receiver, Capacity::shannons(6100000000u64));

let mut tx_with_groups =
builder.build(&HandlerContexts::new_multisig(multisig_config.clone()))?;
println!("tx_with_groups:{:?}", &tx_with_groups);

let json_tx = ckb_jsonrpc_types::TransactionView::from(tx_with_groups.get_tx_view().clone());
println!("tx: {}", serde_json::to_string_pretty(&json_tx).unwrap());
Expand Down
15 changes: 10 additions & 5 deletions examples/transfer_from_multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::path::PathBuf;
use ckb_hash::blake2b_256;
use ckb_jsonrpc_types as json_types;
use ckb_sdk::{
constants::{MULTISIG_TYPE_HASH, SIGHASH_TYPE_HASH},
constants::{MultisigScript, SIGHASH_TYPE_HASH},
rpc::CkbRpcClient,
traits::{
DefaultCellCollector, DefaultCellDepResolver, DefaultHeaderDepResolver,
Expand Down Expand Up @@ -144,7 +144,12 @@ fn main() -> Result<(), Box<dyn StdErr>> {
}
sighash_addresses.push(H160::from_slice(lock_args.as_ref()).unwrap());
}
MultisigConfig::new_with(sighash_addresses, args.require_first_n, args.threshold)?
MultisigConfig::new_with(
ckb_sdk::constants::MultisigScript::V2,
sighash_addresses,
args.require_first_n,
args.threshold,
)?
};
let tx = build_transfer_tx(&args, &multisig_config)?;
let tx_info = TxInfo {
Expand Down Expand Up @@ -222,8 +227,8 @@ fn build_transfer_tx(
) -> Result<TransactionView, Box<dyn StdErr>> {
// Build CapacityBalancer
let sender = Script::new_builder()
.code_hash(MULTISIG_TYPE_HASH.pack())
.hash_type(ScriptHashType::Type.into())
.code_hash(MultisigScript::V2.script_id().code_hash.pack())
.hash_type(MultisigScript::V2.script_id().hash_type.into())
.args(Bytes::from(multisig_config.hash160().as_bytes().to_vec()).pack())
.build();
let sender_addr = Address::new(args.receiver.network(), sender.clone().into(), true);
Expand Down Expand Up @@ -289,7 +294,7 @@ fn build_multisig_unlockers(
let signer = SecpCkbRawKeySigner::new_with_secret_keys(keys);
let multisig_signer = SecpMultisigScriptSigner::new(Box::new(signer), config);
let multisig_unlocker = SecpMultisigUnlocker::new(multisig_signer);
let multisig_script_id = ScriptId::new_type(MULTISIG_TYPE_HASH.clone());
let multisig_script_id = MultisigScript::V2.script_id();
let mut unlockers = HashMap::default();
unlockers.insert(
multisig_script_id,
Expand Down
9 changes: 6 additions & 3 deletions examples/transfer_from_omnilock_multisig.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ckb_jsonrpc_types as json_types;
use ckb_sdk::{
constants::SIGHASH_TYPE_HASH,
constants::{MultisigScript, SIGHASH_TYPE_HASH},
rpc::CkbRpcClient,
traits::{
DefaultCellCollector, DefaultCellDepResolver, DefaultHeaderDepResolver,
Expand All @@ -11,8 +11,10 @@ use ckb_sdk::{
unlock_tx, CapacityBalancer, TxBuilder,
},
types::NetworkType,
unlock::{MultisigConfig, OmniLockUnlocker, ScriptUnlocker},
unlock::{OmniLockConfig, OmniLockScriptSigner, OmniUnlockMode},
unlock::{
MultisigConfig, OmniLockConfig, OmniLockScriptSigner, OmniLockUnlocker, OmniUnlockMode,
ScriptUnlocker,
},
Address, HumanCapacity, ScriptGroup, ScriptId,
};
use ckb_types::{
Expand Down Expand Up @@ -272,6 +274,7 @@ fn build_multisig_config(
sighash_addresses.push(H160::from_slice(lock_args.as_ref()).unwrap());
}
Ok(MultisigConfig::new_with(
MultisigScript::V2,
sighash_addresses,
require_first_n,
threshold,
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.81.0
1.85.0
Loading