Skip to content

Commit 8fee8bc

Browse files
committed
Rpc: allow multisg_v2 for WellKnownScriptsOnlyValidator
Signed-off-by: Eval EXEC <[email protected]>
1 parent a769752 commit 8fee8bc

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

rpc/src/module/pool.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use ckb_jsonrpc_types::{
88
use ckb_logger::error;
99
use ckb_shared::shared::Shared;
1010
use ckb_types::core::TransactionView;
11-
use ckb_types::{H256, core, packed, prelude::*};
11+
use ckb_types::{H256, core, h256, packed, prelude::*};
1212
use ckb_verification::{Since, SinceMetric};
1313
use jsonrpc_core::Result;
1414
use jsonrpc_utils::rpc;
@@ -771,7 +771,8 @@ impl<'a> WellKnownScriptsOnlyValidator<'a> {
771771
output: &packed::CellOutput,
772772
) -> std::result::Result<(), DefaultOutputsValidatorError> {
773773
self.validate_secp256k1_blake160_sighash_all(output)
774-
.or_else(|_| self.validate_secp256k1_blake160_multisig_all(output))
774+
.or_else(|_| self.validate_secp256k1_blake160_multisig_all_legacy(output))
775+
.or_else(|_| self.validate_secp256k1_blake160_multisig_all_v2(output))
775776
.or_else(|_| self.validate_well_known_lock_scripts(output))
776777
}
777778

@@ -804,7 +805,7 @@ impl<'a> WellKnownScriptsOnlyValidator<'a> {
804805
}
805806
}
806807

807-
fn validate_secp256k1_blake160_multisig_all(
808+
fn validate_secp256k1_blake160_multisig_all_legacy(
808809
&self,
809810
output: &packed::CellOutput,
810811
) -> std::result::Result<(), DefaultOutputsValidatorError> {
@@ -834,6 +835,33 @@ impl<'a> WellKnownScriptsOnlyValidator<'a> {
834835
}
835836
}
836837

838+
fn validate_secp256k1_blake160_multisig_all_v2(
839+
&self,
840+
output: &packed::CellOutput,
841+
) -> std::result::Result<(), DefaultOutputsValidatorError> {
842+
let script = output.lock();
843+
if !script.is_hash_type_data1() {
844+
Err(DefaultOutputsValidatorError::HashType)
845+
} else if script.code_hash()
846+
!= h256!("0x36c971b8d41fbd94aabca77dc75e826729ac98447b46f91e00796155dddb0d29").pack()
847+
{
848+
Err(DefaultOutputsValidatorError::CodeHash)
849+
} else if script.args().len() != BLAKE160_LEN {
850+
if script.args().len() == BLAKE160_LEN + SINCE_LEN {
851+
if extract_since_from_secp256k1_blake160_multisig_all_args(&script).flags_is_valid()
852+
{
853+
Ok(())
854+
} else {
855+
Err(DefaultOutputsValidatorError::ArgsSince)
856+
}
857+
} else {
858+
Err(DefaultOutputsValidatorError::ArgsLen)
859+
}
860+
} else {
861+
Ok(())
862+
}
863+
}
864+
837865
fn validate_well_known_lock_scripts(
838866
&self,
839867
output: &packed::CellOutput,

util/gen-types/src/extension/shortcut.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ impl packed::Script {
125125
pub fn is_hash_type_type(&self) -> bool {
126126
Into::<u8>::into(self.hash_type()) == Into::<u8>::into(core::ScriptHashType::Type)
127127
}
128+
129+
/// Checks whether the own [`hash_type`](#method.hash_type) is
130+
/// [`Data`](../core/enum.ScriptHashType.html#variant.Data1).
131+
pub fn is_hash_type_data(&self) -> bool {
132+
Into::<u8>::into(self.hash_type()) == Into::<u8>::into(core::ScriptHashType::Data)
133+
}
134+
135+
/// Checks whether the own [`hash_type`](#method.hash_type) is
136+
/// [`Data1`](../core/enum.ScriptHashType.html#variant.Data1).
137+
pub fn is_hash_type_data1(&self) -> bool {
138+
Into::<u8>::into(self.hash_type()) == Into::<u8>::into(core::ScriptHashType::Data1)
139+
}
128140
}
129141

130142
impl packed::Transaction {

0 commit comments

Comments
 (0)