11use shinigami_compiler :: compiler :: CompilerImpl ;
22use shinigami_engine :: engine :: {EngineImpl , EngineInternalImpl };
3- use shinigami_engine :: transaction :: {EngineInternalTransactionImpl , EngineInternalTransactionTrait };
3+ use shinigami_engine :: transaction :: {
4+ EngineInternalTransactionImpl , EngineInternalTransactionTrait , UTXO ,
5+ };
46use shinigami_engine :: flags;
57use shinigami_engine :: witness;
68use shinigami_engine :: hash_cache :: HashCacheImpl ;
79use shinigami_utils :: byte_array :: felt252_to_byte_array;
810use shinigami_utils :: bytecode :: hex_to_bytecode;
9- use shinigami_tests :: utxo :: UTXO ;
1011use shinigami_tests :: validate;
1112
1213#[derive(Clone , Drop )]
1314struct InputData {
1415 ScriptSig : ByteArray ,
15- ScriptPubKey : ByteArray
16+ ScriptPubKey : ByteArray ,
17+ txid : u256 ,
1618}
1719
1820#[derive(Clone , Drop )]
1921struct InputDataWithFlags {
2022 ScriptSig : ByteArray ,
2123 ScriptPubKey : ByteArray ,
22- Flags : ByteArray
24+ Flags : ByteArray ,
25+ txid : u256 ,
2326}
2427
2528#[derive(Clone , Drop )]
2629struct InputDataWithWitness {
2730 ScriptSig : ByteArray ,
2831 ScriptPubKey : ByteArray ,
2932 Flags : ByteArray ,
30- Witness : ByteArray
33+ Witness : ByteArray ,
34+ txid : u256 ,
3135}
3236
3337fn run_with_flags (input : InputDataWithFlags ) -> Result <(), felt252 > {
3438 println! (
3539 " Running Bitcoin Script with ScriptSig: '{}', ScriptPubKey: '{}' and Flags: '{}'" ,
3640 input . ScriptSig ,
3741 input . ScriptPubKey ,
38- input . Flags
42+ input . Flags ,
3943 );
4044 let mut compiler = CompilerImpl :: new ();
4145 let script_pubkey = compiler . compile (input . ScriptPubKey )? ;
4246 let compiler = CompilerImpl :: new ();
4347 let script_sig = compiler . compile (input . ScriptSig )? ;
44- let tx = EngineInternalTransactionImpl :: new_signed (script_sig , script_pubkey . clone ());
48+ let tx = EngineInternalTransactionImpl :: new_signed (
49+ script_sig , script_pubkey . clone (), input . txid, array! [],
50+ );
4551 let flags = flags :: parse_flags (input . Flags );
4652 let hash_cache = HashCacheImpl :: new (@ tx );
4753 let mut engine = EngineImpl :: new (@ script_pubkey , @ tx , 0 , flags , 0 , @ hash_cache )? ;
@@ -55,7 +61,7 @@ fn run_with_witness(input: InputDataWithWitness) -> Result<(), felt252> {
5561 input . ScriptSig ,
5662 input . ScriptPubKey ,
5763 input . Flags ,
58- input . Witness
64+ input . Witness ,
5965 );
6066 let mut compiler = CompilerImpl :: new ();
6167 let script_pubkey = compiler . compile (input . ScriptPubKey )? ;
@@ -64,7 +70,7 @@ fn run_with_witness(input: InputDataWithWitness) -> Result<(), felt252> {
6470 let witness = witness :: parse_witness_input (input . Witness );
6571 let value = 1 ; // TODO
6672 let tx = EngineInternalTransactionImpl :: new_signed_witness (
67- script_sig , script_pubkey . clone (), witness , value
73+ script_sig , script_pubkey . clone (), witness , value , input . txid, array! [],
6874 );
6975 let flags = flags :: parse_flags (input . Flags );
7076 let hash_cache = HashCacheImpl :: new (@ tx );
@@ -77,13 +83,15 @@ fn run(input: InputData) -> Result<(), felt252> {
7783 println! (
7884 " Running Bitcoin Script with ScriptSig: '{}' and ScriptPubKey: '{}'" ,
7985 input . ScriptSig ,
80- input . ScriptPubKey
86+ input . ScriptPubKey ,
8187 );
8288 let mut compiler = CompilerImpl :: new ();
8389 let script_pubkey = compiler . compile (input . ScriptPubKey )? ;
8490 let compiler = CompilerImpl :: new ();
8591 let script_sig = compiler . compile (input . ScriptSig )? ;
86- let tx = EngineInternalTransactionImpl :: new_signed (script_sig , script_pubkey . clone ());
92+ let tx = EngineInternalTransactionImpl :: new_signed (
93+ script_sig , script_pubkey . clone (), input . txid, array! [],
94+ );
8795 let hash_cache = HashCacheImpl :: new (@ tx );
8896 let mut engine = EngineImpl :: new (@ script_pubkey , @ tx , 0 , 0 , 0 , @ hash_cache )? ;
8997 let res = engine . execute ();
@@ -95,21 +103,23 @@ fn run(input: InputData) -> Result<(), felt252> {
95103 Result :: Err (e ) => {
96104 println! (" Execution failed: {}" , felt252_to_byte_array (e ));
97105 Result :: Err (e )
98- }
106+ },
99107 }
100108}
101109
102110fn run_with_json (input : InputData ) -> Result <(), felt252 > {
103111 println! (
104112 " Running Bitcoin Script with ScriptSig: '{}' and ScriptPubKey: '{}'" ,
105113 input . ScriptSig ,
106- input . ScriptPubKey
114+ input . ScriptPubKey ,
107115 );
108116 let mut compiler = CompilerImpl :: new ();
109117 let script_pubkey = compiler . compile (input . ScriptPubKey )? ;
110118 let compiler = CompilerImpl :: new ();
111119 let script_sig = compiler . compile (input . ScriptSig )? ;
112- let tx = EngineInternalTransactionImpl :: new_signed (script_sig , script_pubkey . clone ());
120+ let tx = EngineInternalTransactionImpl :: new_signed (
121+ script_sig , script_pubkey . clone (), input . txid, array! [],
122+ );
113123 let hash_cache = HashCacheImpl :: new (@ tx );
114124 let mut engine = EngineImpl :: new (@ script_pubkey , @ tx , 0 , 0 , 0 , @ hash_cache )? ;
115125 let _ = engine . execute ()? ;
@@ -121,13 +131,15 @@ fn debug(input: InputData) -> Result<bool, felt252> {
121131 println! (
122132 " Running Bitcoin Script with ScriptSig: '{}' and ScriptPubKey: '{}'" ,
123133 input . ScriptSig ,
124- input . ScriptPubKey
134+ input . ScriptPubKey ,
125135 );
126136 let mut compiler = CompilerImpl :: new ();
127137 let script_pubkey = compiler . compile (input . ScriptPubKey )? ;
128138 let compiler = CompilerImpl :: new ();
129139 let script_sig = compiler . compile (input . ScriptSig )? ;
130- let tx = EngineInternalTransactionImpl :: new_signed (script_sig , script_pubkey . clone ());
140+ let tx = EngineInternalTransactionImpl :: new_signed (
141+ script_sig , script_pubkey . clone (), input . txid, array! [],
142+ );
131143 let hash_cache = HashCacheImpl :: new (@ tx );
132144 let mut engine = EngineImpl :: new (@ script_pubkey , @ tx , 0 , 0 , 0 , @ hash_cache )? ;
133145 let mut res = Result :: Ok (true );
@@ -154,7 +166,7 @@ fn main(input: InputDataWithFlags) -> u8 {
154166 Result :: Err (e ) => {
155167 println! (" Execution failed: {}" , felt252_to_byte_array (e ));
156168 0
157- }
169+ },
158170 }
159171}
160172
@@ -168,7 +180,7 @@ fn main_with_witness(input: InputDataWithWitness) -> u8 {
168180 Result :: Err (e ) => {
169181 println! (" Execution failed: {}" , felt252_to_byte_array (e ));
170182 0
171- }
183+ },
172184 }
173185}
174186
@@ -182,7 +194,7 @@ fn backend_run(input: InputData) -> u8 {
182194 Result :: Err (e ) => {
183195 println! (" Execution failed: {}" , felt252_to_byte_array (e ));
184196 0
185- }
197+ },
186198 }
187199}
188200
@@ -196,7 +208,7 @@ fn backend_debug(input: InputData) -> u8 {
196208 Result :: Err (e ) => {
197209 println! (" Execution failed: {}" , felt252_to_byte_array (e ));
198210 0
199- }
211+ },
200212 }
201213}
202214
@@ -205,12 +217,12 @@ struct ValidateRawInput {
205217 raw_transaction : ByteArray ,
206218 utxo_hints : Array <UTXO >,
207219 flags : ByteArray ,
220+ txid : u256 // from raito or calculate from raw_transaction in decode ?
208221}
209222
210223fn run_raw_transaction (mut input : ValidateRawInput ) -> u8 {
211224 println! (" Running Bitcoin Script with raw transaction: '{}'" , input . raw_transaction);
212225 let raw_transaction = hex_to_bytecode (@ input . raw_transaction);
213- let transaction = EngineInternalTransactionTrait :: deserialize (raw_transaction );
214226
215227 // Parse the flags
216228 let script_flags = flags :: parse_flags (input . flags);
@@ -223,23 +235,25 @@ fn run_raw_transaction(mut input: ValidateRawInput) -> u8 {
223235 }
224236
225237 let mut utxo_hints = array! [];
238+ for hint in input . utxo_hints. span () {
239+ println! (" UTXO hint: 'amount: {}, script_pubkey: {}'" , hint . amount, hint . pubkey_script);
240+ let pubkey_script = hex_to_bytecode (hint . pubkey_script);
241+ utxo_hints
242+ . append (
243+ UTXO {
244+ amount : * hint . amount,
245+ pubkey_script : pubkey_script ,
246+ block_height : * hint . block_height,
247+ },
248+ );
249+ };
250+
251+ let transaction = EngineInternalTransactionTrait :: deserialize (
252+ raw_transaction , input . txid, utxo_hints ,
253+ );
254+ // transaction.set_utxos(utxo_hints);
226255
227- for hint in input
228- . utxo_hints
229- . span () {
230- println! (" UTXO hint: 'amount: {}, script_pubkey: {}'" , hint . amount, hint . pubkey_script);
231- let pubkey_script = hex_to_bytecode (hint . pubkey_script);
232- utxo_hints
233- . append (
234- UTXO {
235- amount : * hint . amount,
236- pubkey_script : pubkey_script ,
237- block_height : * hint . block_height,
238- }
239- );
240- };
241-
242- let res = validate :: validate_transaction (@ transaction , script_flags , utxo_hints );
256+ let res = validate :: validate_transaction (@ transaction , script_flags );
243257 match res {
244258 Result :: Ok (_ ) => {
245259 println! (" Execution successful" );
@@ -248,6 +262,6 @@ fn run_raw_transaction(mut input: ValidateRawInput) -> u8 {
248262 Result :: Err (e ) => {
249263 println! (" Execution failed: {}" , felt252_to_byte_array (e ));
250264 0
251- }
265+ },
252266 }
253267}
0 commit comments