@@ -51,9 +51,8 @@ class CCWallet:
5151 cc_coin_record : WalletCoinRecord
5252 cc_info : CCInfo
5353 standard_wallet : Wallet
54- base_puzzle_program : Optional [Program ]
54+ base_puzzle_program : Optional [bytes ]
5555 base_inner_puzzle_hash : Optional [bytes32 ]
56- sexp_cache : Optional [Dict [str , SExp ]]
5756
5857 @staticmethod
5958 async def create_new_cc (
@@ -62,7 +61,6 @@ async def create_new_cc(
6261 self = CCWallet ()
6362 self .base_puzzle_program = None
6463 self .base_inner_puzzle_hash = None
65- self .sexp_cache = None
6664 self .standard_wallet = wallet
6765 if name :
6866 self .log = logging .getLogger (name )
@@ -143,7 +141,6 @@ async def create_wallet_for_cc(
143141 self = CCWallet ()
144142 self .base_puzzle_program = None
145143 self .base_inner_puzzle_hash = None
146- self .sexp_cache = None
147144 self .standard_wallet = wallet
148145 if name :
149146 self .log = logging .getLogger (name )
@@ -183,7 +180,6 @@ async def create(
183180 self .cc_info = CCInfo .from_bytes (hexstr_to_bytes (self .wallet_info .data ))
184181 self .base_puzzle_program = None
185182 self .base_inner_puzzle_hash = None
186- self .sexp_cache = None
187183 return self
188184
189185 async def get_confirmed_balance (self ) -> uint64 :
@@ -382,49 +378,16 @@ def do_replace(self, sexp, magic, magic_replacement):
382378 return sexp .to (magic_replacement )
383379 return sexp
384380
385- def specific_replace (self , sexp , magic , magic_replacement ):
381+ def specific_replace (self , old , magic , magic_replacement ):
386382 """binutil.assemble is slow, using this hack to swap inner_puzzle_hash. """
387- if self .sexp_cache is None :
388- self .sexp_cache = {}
389- n1 = sexp .first ()
390- n2 = sexp .rest ().rest ()
391- n3 = sexp .rest ().first ().first ()
392- n4 = sexp .rest ().first ().rest ().first ().first ()
393- sexp_to_replace = sexp .rest ().first ().rest ().first ().rest ().first ()
394- n5 = sexp .rest ().first ().rest ().first ().rest ().rest ()
395- n6 = sexp .rest ().first ().rest ().rest ()
396- self .sexp_cache ["n1" ] = n1
397- self .sexp_cache ["n2" ] = n2
398- self .sexp_cache ["n3" ] = n3
399- self .sexp_cache ["n4" ] = n4
400- self .sexp_cache ["sexp_to_replace" ] = sexp_to_replace
401- self .sexp_cache ["n5" ] = n5
402- self .sexp_cache ["n6" ] = n6
403- else :
404- n1 = self .sexp_cache ["n1" ]
405- n2 = self .sexp_cache ["n2" ]
406- n3 = self .sexp_cache ["n3" ]
407- n4 = self .sexp_cache ["n4" ]
408- sexp_to_replace = self .sexp_cache ["sexp_to_replace" ]
409- n5 = self .sexp_cache ["n5" ]
410- n6 = self .sexp_cache ["n6" ]
411-
412- replaced = sexp_to_replace .to (magic_replacement )
413-
414- step0 = replaced .cons (n5 )
415- step1 = n4 .cons (step0 )
416- step2 = step1 .cons (n6 )
417- step3 = n3 .cons (step2 )
418- step5 = step3 .cons (n2 )
419- result = n1 .cons (step5 )
420-
421- return result
383+ new = old .replace (magic , magic_replacement )
384+ return new
422385
423386 def fast_cc_puzzle (self , inner_puzzle_hash ) -> Program :
424387 new_sexp = self .specific_replace (
425388 self .base_puzzle_program , self .base_inner_puzzle_hash , inner_puzzle_hash
426389 )
427- program = Program (new_sexp )
390+ program = Program . from_bytes (new_sexp )
428391 return program
429392
430393 def puzzle_for_pk (self , pubkey ) -> Program :
@@ -435,7 +398,7 @@ def puzzle_for_pk(self, pubkey) -> Program:
435398 cc_puzzle : Program = cc_wallet_puzzles .cc_make_puzzle (
436399 inner_puzzle_hash , self .cc_info .my_core
437400 )
438- self .base_puzzle_program = cc_puzzle
401+ self .base_puzzle_program = bytes ( cc_puzzle )
439402 self .base_inner_puzzle_hash = inner_puzzle_hash
440403 else :
441404 cc_puzzle = self .fast_cc_puzzle (inner_puzzle_hash )
0 commit comments