@@ -542,7 +542,7 @@ def _build_signable_transaction(self, outputs, inputs_meta, prefill_funding: boo
542542 # Defensive: ensure satoshis is int, ls_hex is hex string
543543 assert isinstance (satoshis , int ), f"satoshis must be int, got { type (satoshis )} "
544544 assert isinstance (ls_hex , str ), f"lockingScript must be hex string, got { type (ls_hex )} "
545- s = Script (bytes . fromhex ( ls_hex ))
545+ s = Script (ls_hex ) # Script constructor accepts hex string directly
546546 to = TransactionOutput (s , int (satoshis ))
547547 t .add_output (to )
548548 # Map to track which inputs are funding (P2PKH) to optionally pre-sign
@@ -585,11 +585,11 @@ def _build_signable_transaction(self, outputs, inputs_meta, prefill_funding: boo
585585 else :
586586 # Fallback: set generic P2PKH lock with our address
587587 addr = self .public_key .address ()
588- ls_fund = P2PKH ().lock (addr ). serialize ()
588+ ls_fund = P2PKH ().lock (addr ) # Script object
589589 for idx in funding_indices :
590590 tin = t .inputs [idx ]
591591 tin .satoshis = 0
592- tin .locking_script = Script ( ls_fund )
592+ tin .locking_script = ls_fund # Script objectを直接使用
593593 # Now produce signatures for those inputs
594594 for idx in funding_indices :
595595 meta = inputs_meta [idx ] if idx < len (inputs_meta ) else {}
@@ -944,8 +944,8 @@ def _build_beef_for_outputs(self, outputs_desc: List[Dict[str, Any]]) -> bytes:
944944 print (f"[TRACE] [_build_beef_for_outputs] out sat={ o .get ('satoshis' )} ls_hex={ ls_hex if isinstance (ls_hex , str ) else (ls_hex .hex () if isinstance (ls_hex , (bytes , bytearray )) else ls_hex )} " )
945945 except Exception :
946946 pass
947- ls_bytes = bytes . fromhex (ls_hex ) if isinstance (ls_hex , str ) else (ls_hex or b"\x51 " )
948- to = TransactionOutput (Script ( ls_bytes ) , int (o .get ("satoshis" , 0 )))
947+ ls_script = Script (ls_hex ) if isinstance (ls_hex , str ) else Script (ls_hex or b"\x51 " )
948+ to = TransactionOutput (ls_script , int (o .get ("satoshis" , 0 )))
949949 tx .add_output (to )
950950 beef = tx .to_beef ()
951951 try :
@@ -1138,9 +1138,9 @@ def sign_action(self, ctx: Any, args: Dict, originator: str) -> Dict:
11381138 return {"error" : f"sign_action: unlockingScript too short at input { idx } " }
11391139 # Record SIGHASH flag (last byte)
11401140 sighash_flag = unlocking_script [- 1 ]
1141- input .unlocking_script = Script (unlocking_script )
1141+ input .unlocking_script = Script (unlocking_script ) # bytesからScriptオブジェクトを作成
11421142 else :
1143- input .unlocking_script = unlocking_script
1143+ input .unlocking_script = unlocking_script # 既にScriptオブジェクトの場合
11441144 # Serialize signed transaction
11451145 signed_tx_bytes = tx .serialize ()
11461146 txid = tx .txid () if hasattr (tx , "txid" ) else hashlib .sha256 (signed_tx_bytes ).hexdigest ()
@@ -1182,8 +1182,8 @@ def _get_utxos_from_woc(self, address: str, api_key: Optional[str] = None, timeo
11821182 for u in data :
11831183 # WOC unspent API does not include the locking script; derive P2PKH from address as fallback
11841184 try :
1185- derived_ls = P2PKH ().lock (address ). serialize ()
1186- derived_ls_hex = derived_ls .hex () if isinstance ( derived_ls , bytes ) else derived_ls
1185+ derived_ls = P2PKH ().lock (address ) # Script object
1186+ derived_ls_hex = derived_ls .hex () # Script objectからHEX文字列を取得
11871187 except Exception :
11881188 derived_ls_hex = ""
11891189 utxos .append ({
@@ -1301,12 +1301,12 @@ def _estimate_fee(self, outs: List[Dict], unlocking_lens: List[int], fee_model:
13011301 t = _Tx ()
13021302 for o in outs :
13031303 ls = o .get ("lockingScript" , b"" )
1304- ls_b = bytes . fromhex (ls ) if isinstance (ls , str ) else ls
1305- t .add_output (_TxOut (_Script ( ls_b ) , int (o .get ("satoshis" , 0 ))))
1304+ ls_script = _Script (ls ) if isinstance (ls , str ) else _Script ( ls ) # Scriptオブジェクトを直接作成
1305+ t .add_output (_TxOut (ls_script , int (o .get ("satoshis" , 0 ))))
13061306 for est_len in unlocking_lens :
13071307 ti = _TxIn (source_txid = "00" * 32 , source_output_index = 0 )
13081308 fake = encode_pushdata (b"x" * max (0 , est_len - 1 )) if est_len > 0 else b"\x00 "
1309- ti .unlocking_script = _Script (fake )
1309+ ti .unlocking_script = _Script (fake ) # bytesからScriptオブジェクトを作成
13101310 t .add_input (ti )
13111311 return int (fee_model .compute_fee (t ))
13121312 except Exception :
@@ -1399,10 +1399,10 @@ def read_push(pos: int):
13991399 print (f"[TRACE] [sign_check] scriptSig structure check skipped: { _dbg_e2 } " )
14001400
14011401 def _build_change_output_dict (self , basket_addr : str , satoshis : int ) -> Dict [str , Any ]:
1402- ls = P2PKH ().lock (basket_addr ). serialize ()
1402+ ls = P2PKH ().lock (basket_addr ) # Script object
14031403 return {
14041404 "satoshis" : int (satoshis ),
1405- "lockingScript" : ls .hex () if isinstance ( ls , bytes ) else ls ,
1405+ "lockingScript" : ls .hex (), # Script objectからHEX文字列を取得
14061406 "outputDescription" : "Change" ,
14071407 "basket" : basket_addr ,
14081408 "tags" : [],
@@ -1434,8 +1434,8 @@ def estimate_with_optional_change(sel_count: int, include_change: bool) -> int:
14341434 try :
14351435 addr = self ._self_address ()
14361436 print (f"[TRACE] [estimate_with_optional_change] addr: { addr } " )
1437- ch_ls = P2PKH ().lock (addr ). serialize ()
1438- base_outs = base_outs + [{"satoshis" : 1 , "lockingScript" : ch_ls }]
1437+ ch_ls = P2PKH ().lock (addr ) # Script object
1438+ base_outs = base_outs + [{"satoshis" : 1 , "lockingScript" : ch_ls . hex ()}] # HEX文字列に変換
14391439 except Exception :
14401440 pass
14411441 unlocking_lens = list (existing_unlock_lens ) + [107 ] * sel_count
0 commit comments