Skip to content

Commit dbac896

Browse files
committed
deploy: warn user if lock script is not well know
1 parent 1221235 commit dbac896

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/subcommands/deploy/mod.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ use ckb_hash::blake2b_256;
1010
use ckb_jsonrpc_types as json_types;
1111
use ckb_jsonrpc_types::JsonBytes;
1212
use ckb_sdk::{
13+
constants::{MultisigScript, DAO_TYPE_HASH, SIGHASH_TYPE_HASH},
1314
traits::{DefaultTransactionDependencyProvider, Signer},
1415
unlock::MultisigConfig,
1516
Address, HumanCapacity,
1617
};
17-
use ckb_types::{bytes::Bytes, packed, prelude::*, H160, H256};
18+
use ckb_types::{bytes::Bytes, core::ScriptHashType, packed, prelude::*, H160, H256};
1819
use clap::{App, Arg, ArgMatches};
1920

2021
use super::{CliSubCommand, Output, ALLOW_ZERO_LOCK_HELP_MSG};
@@ -168,6 +169,9 @@ impl CliSubCommand for DeploySubCommand<'_> {
168169
load_deployment(&deployment_config).map_err(|err| err.to_string())?;
169170
let lock_script = packed::Script::from(deployment.lock.clone());
170171

172+
// * Validate lock script against known system scripts
173+
validate_lock_script(&lock_script);
174+
171175
// * Load last receipt
172176
let last_recipe =
173177
load_last_snapshot(&migration_dir).map_err(|err| err.to_string())?;
@@ -596,6 +600,34 @@ fn load_deployment(file_path: &Path) -> Result<Deployment> {
596600
Ok(deployment)
597601
}
598602

603+
fn validate_lock_script(lock_script: &packed::Script) {
604+
let code_hash: H256 = lock_script.code_hash().unpack();
605+
let hash_type: ScriptHashType = lock_script
606+
.hash_type()
607+
.try_into()
608+
.unwrap_or(ScriptHashType::Data);
609+
610+
// Check if it matches known system scripts
611+
let is_known =
612+
// Sighash
613+
(code_hash == SIGHASH_TYPE_HASH && hash_type == ScriptHashType::Type)
614+
// Multisig Legacy
615+
|| (code_hash == MultisigScript::Legacy.script_id().code_hash
616+
&& hash_type == MultisigScript::Legacy.script_id().hash_type)
617+
// Multisig V2
618+
|| (code_hash == MultisigScript::V2.script_id().code_hash
619+
&& hash_type == MultisigScript::V2.script_id().hash_type) ;
620+
621+
if !is_known {
622+
eprintln!(
623+
"Warning: The lock script does not match well known scripts (sighash or multisig[legacy, v2]."
624+
);
625+
eprintln!(" code_hash: {:#x}", code_hash);
626+
eprintln!(" hash_type: {:?}", hash_type);
627+
eprintln!(" Please verify this is the correct lock script for your deployment.");
628+
}
629+
}
630+
599631
fn load_snapshot(migration_dir: &Path, snapshot_name: String) -> Result<DeploymentRecipe> {
600632
let mut path = migration_dir.to_path_buf();
601633
path.push(snapshot_name);

0 commit comments

Comments
 (0)