@@ -45,7 +45,7 @@ async def create(
4545
4646 async def create_offer_for_ids (
4747 self , offer : Dict [int , int ]
48- ) -> Tuple [bool , Optional [SpendBundle ]]:
48+ ) -> Tuple [bool , Optional [SpendBundle ], Optional [ str ] ]:
4949 """
5050 Offer is dictionary of wallet ids and amount
5151 """
@@ -57,7 +57,9 @@ async def create_offer_for_ids(
5757 wallet = self .wallet_state_manager .wallets [wallet_id ]
5858 if isinstance (wallet , CCWallet ):
5959 balance = await wallet .get_confirmed_balance ()
60- if balance == 0 :
60+ if balance < abs (amount ) and amount < 0 :
61+ raise Exception (f"insufficient funds in wallet { wallet_id } " )
62+ if balance == 0 and amount > 0 :
6163 if spend_bundle is None :
6264 to_exclude : List [Coin ] = []
6365 else :
@@ -67,7 +69,7 @@ async def create_offer_for_ids(
6769 ] = await wallet .generate_zero_val_coin (False , to_exclude )
6870
6971 if zero_spend_bundle is None :
70- raise ValueError (
72+ raise Exception (
7173 "Failed to generate offer. Zero value coin not created."
7274 )
7375 if spend_bundle is None :
@@ -100,22 +102,23 @@ async def create_offer_for_ids(
100102 amount , to_exclude
101103 )
102104 else :
103- return False , None
105+ return False , None , "unssuported wallet type"
104106 if new_spend_bundle .removals () == [] or new_spend_bundle is None :
105- return False , None
107+ raise Exception ( f"Wallet { id } was unable to create offer." )
106108 if spend_bundle is None :
107109 spend_bundle = new_spend_bundle
108110 else :
109111 spend_bundle = SpendBundle .aggregate (
110112 [spend_bundle , new_spend_bundle ]
111113 )
112114
113- return True , spend_bundle
114- except Exception :
115- return False , None
115+ return True , spend_bundle , None
116+ except Exception as e :
117+ return False , None , str ( e )
116118
117119 def write_offer_to_disk (self , file_path : Path , offer : SpendBundle ):
118- file_path .write_text (bytes (offer ).hex ())
120+ if offer is not None :
121+ file_path .write_text (bytes (offer ).hex ())
119122
120123 async def get_discrepancies_for_offer (
121124 self , file_path : Path
@@ -228,7 +231,8 @@ async def respond_to_offer(self, file_path: Path) -> Tuple[bool, Optional[str]]:
228231 colour
229232 )
230233 unspent = await self .wallet_state_manager .get_spendable_coins_for_wallet (
231- wallets [colour ].wallet_info .id )
234+ wallets [colour ].wallet_info .id
235+ )
232236 if coinsol .coin in [record .coin for record in unspent ]:
233237 return False , "can't respond to own offer"
234238 innerpuzzlereveal = solution .rest ().rest ().rest ().first ()
@@ -270,7 +274,9 @@ async def respond_to_offer(self, file_path: Path) -> Tuple[bool, Optional[str]]:
270274 coinsols .append (coinsol )
271275 else :
272276 # standard chia coin
273- unspent = await self .wallet_state_manager .get_spendable_coins_for_wallet (1 )
277+ unspent = await self .wallet_state_manager .get_spendable_coins_for_wallet (
278+ 1
279+ )
274280 if coinsol .coin in [record .coin for record in unspent ]:
275281 return False , "can't respond to own offer"
276282 if chia_discrepancy is None :
0 commit comments