@@ -6,7 +6,6 @@ use kaspa_txscript::caches::Cache;
66use kaspa_txscript:: covenants:: CovenantsContext ;
77use kaspa_txscript:: script_builder:: ScriptBuilder ;
88use kaspa_txscript:: { DynOpcodeImplementation , EngineCtx , EngineFlags , TxScriptEngine , parse_script} ;
9- use serde:: { Deserialize , Serialize } ;
109
1110use silverscript_lang:: ast:: { Expr , ExprKind } ;
1211use silverscript_lang:: compiler:: compile_debug_expr;
@@ -16,6 +15,7 @@ use silverscript_lang::debug_info::{
1615
1716pub use crate :: presentation:: { SourceContext , SourceContextLine } ;
1817use crate :: presentation:: { build_source_context, format_value as format_debug_value} ;
18+ use crate :: util:: { decode_i64, encode_hex} ;
1919
2020pub type DebugTx < ' a > = PopulatedTransaction < ' a > ;
2121pub type DebugReused = SigHashReusedValuesUnsync ;
@@ -76,20 +76,6 @@ pub struct SessionState {
7676 pub stack : Vec < String > ,
7777}
7878
79- #[ derive( Debug , Clone , Serialize , Deserialize ) ]
80- pub struct StackSnapshot {
81- pub dstack : Vec < String > ,
82- pub astack : Vec < String > ,
83- }
84-
85- #[ derive( Debug , Clone , Serialize , Deserialize ) ]
86- pub struct OpcodeMeta {
87- pub index : usize ,
88- pub byte_offset : usize ,
89- pub display : String ,
90- pub mapping : Option < DebugMapping > ,
91- }
92-
9379pub struct DebugSession < ' a , ' i > {
9480 engine : DebugEngine < ' a > ,
9581 shadow_tx_context : Option < ShadowTxContext < ' a > > ,
@@ -124,17 +110,6 @@ struct VariableContext<'a> {
124110impl < ' a , ' i > DebugSession < ' a , ' i > {
125111 // --- Session construction + stepping ---
126112
127- /// Creates a debug session for lockscript-only execution.
128- /// Use this when debugging pure contract logic without sigscript setup.
129- pub fn lockscript_only (
130- script : & [ u8 ] ,
131- source : & str ,
132- debug_info : Option < DebugInfo < ' i > > ,
133- engine : DebugEngine < ' a > ,
134- ) -> Result < Self , kaspa_txscript_errors:: TxScriptError > {
135- Self :: from_scripts ( script, source, debug_info, engine)
136- }
137-
138113 /// Creates a debug session simulating a full transaction spend.
139114 /// Executes sigscript first to seed the stack, then debugs lockscript execution.
140115 pub fn full (
@@ -239,11 +214,6 @@ impl<'a, 'i> DebugSession<'a, 'i> {
239214 self . step_with_depth_predicate ( |candidate, current| candidate < current)
240215 }
241216
242- /// Backward-compatible statement stepping alias.
243- pub fn step_statement ( & mut self ) -> Result < Option < SessionState > , kaspa_txscript_errors:: TxScriptError > {
244- self . step_over ( )
245- }
246-
247217 /// Shared stepping loop for `step_into`, `step_over`, and `step_out`.
248218 /// Picks the next steppable mapping whose call depth satisfies `predicate`,
249219 /// executes opcodes until that mapping becomes active, and skips candidates
@@ -354,35 +324,6 @@ impl<'a, 'i> DebugSession<'a, 'i> {
354324 self . engine . is_executing ( )
355325 }
356326
357- /// Returns the current data and alt stack contents.
358- pub fn stacks_snapshot ( & self ) -> StackSnapshot {
359- let stacks = self . engine . stacks ( ) ;
360- StackSnapshot {
361- dstack : stacks. dstack . iter ( ) . map ( |item| encode_hex ( item) ) . collect ( ) ,
362- astack : stacks. astack . iter ( ) . map ( |item| encode_hex ( item) ) . collect ( ) ,
363- }
364- }
365-
366- /// Returns metadata for all opcodes (executed/pending status, byte offset).
367- pub fn opcode_metas ( & self ) -> Vec < OpcodeMeta > {
368- ( 0 ..self . op_displays . len ( ) )
369- . map ( |index| {
370- let byte_offset = self . opcode_offsets . get ( index) . copied ( ) . unwrap_or ( self . script_len ) ;
371- OpcodeMeta {
372- index,
373- byte_offset,
374- display : self . op_displays . get ( index) . cloned ( ) . unwrap_or_default ( ) ,
375- mapping : self . mapping_for_offset ( byte_offset) . cloned ( ) ,
376- }
377- } )
378- . collect ( )
379- }
380-
381- /// Returns the total number of opcodes in the script.
382- pub fn opcode_count ( & self ) -> usize {
383- self . op_displays . len ( )
384- }
385-
386327 pub fn debug_info ( & self ) -> & DebugInfo < ' i > {
387328 & self . debug_info
388329 }
@@ -807,26 +748,6 @@ fn decode_value_by_type(type_name: &str, bytes: Vec<u8>) -> Result<DebugValue, S
807748 }
808749}
809750
810- /// Decodes a txscript script number (little-endian sign-magnitude, max 8 bytes).
811- /// Mirrors txscript's internal numeric decode logic; kept local because txscript
812- /// exposes this helper only as crate-private internals today.
813- fn decode_i64 ( bytes : & [ u8 ] ) -> Result < i64 , String > {
814- if bytes. is_empty ( ) {
815- return Ok ( 0 ) ;
816- }
817- if bytes. len ( ) > 8 {
818- return Err ( "numeric value is longer than 8 bytes" . to_string ( ) ) ;
819- }
820- let msb = bytes[ bytes. len ( ) - 1 ] ;
821- let sign = 1 - 2 * ( ( msb >> 7 ) as i64 ) ;
822- let first_byte = ( msb & 0x7f ) as i64 ;
823- let mut value = first_byte;
824- for byte in bytes[ ..bytes. len ( ) - 1 ] . iter ( ) . rev ( ) {
825- value = ( value << 8 ) + ( * byte as i64 ) ;
826- }
827- Ok ( value * sign)
828- }
829-
830751/// Executes sigscript to seed the stack before debugging lockscript.
831752fn seed_engine_with_sigscript ( engine : & mut DebugEngine < ' _ > , sigscript : & [ u8 ] ) -> Result < ( ) , kaspa_txscript_errors:: TxScriptError > {
832753 for opcode in parse_script :: < DebugTx < ' _ > , DebugReused > ( sigscript) {
@@ -853,7 +774,6 @@ fn mapping_kind_order(kind: &MappingKind) -> u8 {
853774 MappingKind :: Virtual { } => 1 ,
854775 MappingKind :: Statement { } => 2 ,
855776 MappingKind :: InlineCallExit { .. } => 3 ,
856- MappingKind :: Synthetic { .. } => 4 ,
857777 }
858778}
859779
@@ -865,14 +785,6 @@ fn mapping_matches_offset(mapping: &DebugMapping, offset: usize) -> bool {
865785 }
866786}
867787
868- fn encode_hex ( bytes : & [ u8 ] ) -> String {
869- let mut out = vec ! [ 0u8 ; bytes. len( ) * 2 ] ;
870- if faster_hex:: hex_encode ( bytes, & mut out) . is_err ( ) {
871- return String :: new ( ) ;
872- }
873- String :: from_utf8 ( out) . unwrap_or_default ( )
874- }
875-
876788#[ cfg( test) ]
877789mod tests {
878790 use super :: * ;
0 commit comments