@@ -122,7 +122,7 @@ async def get_keys(
122122 hash
123123 )
124124 if index_for_puzzlehash == - 1 :
125- raise
125+ raise ValueError ( f"No key for this puzzlehash { hash } )" )
126126 pubkey = self .private_key .public_child (index_for_puzzlehash ).get_public_key ()
127127 private = self .private_key .private_child (index_for_puzzlehash ).get_private_key ()
128128 return pubkey , private
@@ -136,8 +136,10 @@ async def select_coins(self, amount) -> Optional[Set[Coin]]:
136136 self .wallet_info .id
137137 )
138138 ):
139+ self .log .warning (f"Can't select amount higher than our spendable balance { amount } " )
139140 return None
140141
142+ self .log .info (f"About to select coins for amount { amount } " )
141143 unspent : Set [
142144 WalletCoinRecord
143145 ] = await self .wallet_state_manager .get_spendable_coins_for_wallet (
@@ -160,9 +162,11 @@ async def select_coins(self, amount) -> Optional[Set[Coin]]:
160162 continue
161163 sum += coinrecord .coin .amount
162164 used_coins .add (coinrecord .coin )
165+ self .log .info (f"Selected coin: { coinrecord .coin .name ()} " )
163166
164167 # This happens when we couldn't use one of the coins because it's already used
165168 # but unconfirmed, and we are waiting for the change. (unconfirmed_additions)
169+ unconfirmed_additions = None
166170 if sum < amount :
167171 unconfirmed_additions = await self .wallet_state_manager .unconfirmed_additions_for_wallet (
168172 self .wallet_info .id
@@ -175,11 +179,17 @@ async def select_coins(self, amount) -> Optional[Set[Coin]]:
175179
176180 sum += coin .amount
177181 used_coins .add (coin )
182+ self .log .info (f"Selected used coin: { coin .name ()} " )
178183
179184 if sum >= amount :
185+ self .log .info (f"Successfully selected coins: { used_coins } " )
180186 return used_coins
181187 else :
182188 # This shouldn't happen because of: if amount > self.get_unconfirmed_balance_spendable():
189+ self .log .error (f"Wasn't able to select coins for amount: { amount } "
190+ f"unspent: { unspent } "
191+ f"unconfirmed_removals: { unconfirmed_removals } "
192+ f"unconfirmed_additions: { unconfirmed_additions } " )
183193 return None
184194
185195 async def generate_unsigned_transaction (
@@ -196,19 +206,23 @@ async def generate_unsigned_transaction(
196206 if coins is None :
197207 coins = await self .select_coins (amount + fee )
198208 if coins is None :
209+ self .log .info (f"coins is None" )
199210 return []
200211
212+ self .log .info (f"coins is not None { coins } " )
201213 spend_value = sum ([coin .amount for coin in coins ])
202214 change = spend_value - amount - fee
203215
204216 spends : List [Tuple [Program , CoinSolution ]] = []
205217 output_created = False
206218
207219 for coin in coins :
220+ self .log .info (f"coin from coins { coin } " )
208221 # Get keys for puzzle_hash
209222 puzzle_hash = coin .puzzle_hash
210223 maybe = await self .get_keys (puzzle_hash )
211224 if not maybe :
225+ self .log .error (f"Wallet couldn't find keys for puzzle_hash { puzzle_hash } " )
212226 return []
213227
214228 # Get puzzle for pubkey
@@ -237,6 +251,8 @@ async def generate_unsigned_transaction(
237251 solution = self .make_solution (consumed = [coin .name ()])
238252
239253 spends .append ((puzzle , CoinSolution (coin , solution )))
254+
255+ self .log .info (f"Spends is { spends } " )
240256 return spends
241257
242258 async def sign_transaction (
@@ -247,17 +263,20 @@ async def sign_transaction(
247263 # Get keys
248264 keys = await self .get_keys (solution .coin .puzzle_hash )
249265 if not keys :
266+ self .log .error (f"Sign transaction failed, No Keys for puzzlehash { solution .coin .puzzle_hash } " )
250267 return None
268+
251269 pubkey , secretkey = keys
252270 secretkey = BLSPrivateKey (secretkey )
253-
254271 code_ = [puzzle , solution .solution ]
255272 sexp = clvm .to_sexp_f (code_ )
256273
257274 # Get AGGSIG conditions
258275 err , con , cost = conditions_for_solution (sexp )
259276 if err or not con :
277+ self .log .error (f"Sign transcation failed, con:{ con } , error: { err } " )
260278 return None
279+
261280 conditions_dict = conditions_by_opcode (con )
262281
263282 # Create signature
@@ -311,7 +330,10 @@ async def generate_signed_transaction(
311330 amount , puzzle_hash , fee , origin_id , coins
312331 )
313332 if len (transaction ) == 0 :
333+ self .log .info ("Unsigned transaction not generated" )
314334 return None
335+
336+ self .log .error ("About to sign a transaction" )
315337 return await self .sign_transaction (transaction )
316338
317339 async def get_transaction_status (
0 commit comments