-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2164: refactor: Improve script error r=quake,zhangsoledad a=doitian * Add information to help locating which script produces the error, including the first input or output index, whether it is lock or type script. * Add extra info: * Add the upper limit in ExceededMaximumCycles * Add a link to the system script exit codes table for ValidationFailure Co-authored-by: ian <ian@nervos.org>
- Loading branch information
Showing
6 changed files
with
207 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use ckb_types::packed::Script; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt; | ||
|
||
// A script group is defined as scripts that share the same hash. | ||
// A script group will only be executed once per transaction, the | ||
// script itself should check against all inputs/outputs in its group | ||
// if needed. | ||
pub struct ScriptGroup { | ||
pub script: Script, | ||
pub group_type: ScriptGroupType, | ||
pub input_indices: Vec<usize>, | ||
pub output_indices: Vec<usize>, | ||
} | ||
|
||
impl ScriptGroup { | ||
pub fn new(script: &Script, group_type: ScriptGroupType) -> Self { | ||
Self { | ||
group_type, | ||
script: script.to_owned(), | ||
input_indices: vec![], | ||
output_indices: vec![], | ||
} | ||
} | ||
|
||
pub fn from_lock_script(script: &Script) -> Self { | ||
Self::new(script, ScriptGroupType::Lock) | ||
} | ||
|
||
pub fn from_type_script(script: &Script) -> Self { | ||
Self::new(script, ScriptGroupType::Type) | ||
} | ||
} | ||
|
||
#[derive(Copy, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug)] | ||
#[serde(rename_all = "snake_case")] | ||
pub enum ScriptGroupType { | ||
Lock, | ||
Type, | ||
} | ||
|
||
impl fmt::Display for ScriptGroupType { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match self { | ||
ScriptGroupType::Lock => write!(f, "Lock"), | ||
ScriptGroupType::Type => write!(f, "Type"), | ||
} | ||
} | ||
} |
Oops, something went wrong.