This commit is contained in:
Yostra 2020-04-23 22:30:37 -07:00
parent f2b8c2ec62
commit 156b959f86
4 changed files with 36 additions and 16 deletions

View File

@ -154,13 +154,17 @@ class CCWallet:
async def get_unconfirmed_balance(self) -> uint64:
confirmed = await self.get_confirmed_balance()
unconfirmed_tx = await self.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(self.wallet_info.id)
unconfirmed_tx = await self.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(
self.wallet_info.id
)
addition_amount = 0
removal_amount = 0
for record in unconfirmed_tx:
for coin in record.additions:
if await self.wallet_state_manager.puzzle_store.puzzle_hash_exists(coin.puzzle_hash):
if await self.wallet_state_manager.puzzle_store.puzzle_hash_exists(
coin.puzzle_hash
):
addition_amount += coin.amount
for coin in record.removals:
removal_amount += coin.amount
@ -734,7 +738,9 @@ class CCWallet:
full_spend = SpendBundle.aggregate([spend_bundle, eve_spend])
return full_spend
async def create_spend_bundle_relative_amount(self, cc_amount, zero_coin: Coin = None):
async def create_spend_bundle_relative_amount(
self, cc_amount, zero_coin: Coin = None
):
# If we're losing value then get coloured coins with at least that much value
# If we're gaining value then our amount doesn't matter
if cc_amount < 0:
@ -755,7 +761,7 @@ class CCWallet:
# Loop through coins and create solution for innerpuzzle
list_of_solutions = []
output_created = None
sigs = []
sigs: List[BLSSignature] = []
for coin in cc_spends:
if output_created is None:
newinnerpuzhash = await self.get_new_inner_hash()
@ -769,7 +775,7 @@ class CCWallet:
parent_info = await self.get_parent_for_coin(coin)
assert parent_info is not None
assert self.cc_info.my_core is not None
# Use coin info to create solution and add coin and solution to list of CoinSolutions
solution = cc_wallet_puzzles.cc_make_solution(
self.cc_info.my_core,

View File

@ -56,17 +56,23 @@ class TradeManager:
balance = await wallet.get_confirmed_balance()
if balance == 0:
if spend_bundle is None:
to_exclude = []
to_exclude: List[Coin] = []
else:
to_exclude = spend_bundle.removals()
zero_spend_bundle: SpendBundle = await wallet.generate_zero_val_coin(False, to_exclude)
zero_spend_bundle: Optional[SpendBundle] = await wallet.generate_zero_val_coin(
False, to_exclude
)
if zero_spend_bundle is None:
raise ValueError("Failed to generate offer. Zero value coin not created.")
raise ValueError(
"Failed to generate offer. Zero value coin not created."
)
if spend_bundle is None:
spend_bundle = zero_spend_bundle
else:
spend_bundle = SpendBundle.aggregate([spend_bundle, zero_spend_bundle])
spend_bundle = SpendBundle.aggregate(
[spend_bundle, zero_spend_bundle]
)
additions = zero_spend_bundle.additions()
removals = zero_spend_bundle.removals()
@ -145,8 +151,8 @@ class TradeManager:
else: # standard chia coin
coin_amount = coinsol.coin.amount
out_amount = cc_wallet_puzzles.get_output_amount_for_puzzle_and_solution(
puzzle, solution
)
puzzle, solution
)
diff = coin_amount - out_amount
if "chia" in cc_discrepancies:
cc_discrepancies["chia"] = cc_discrepancies["chia"] + diff
@ -167,7 +173,7 @@ class TradeManager:
async def maybe_create_wallets_for_offer(self, file_path: Path) -> bool:
success, result, error = await self.get_discrepancies_for_offer(file_path)
if not success:
if not success or result is None:
return False
for key, value in result.items():

View File

@ -362,7 +362,9 @@ class Wallet:
# Create an offer spend bundle for chia given an amount of relative change (i.e -400 or 1000)
# This is to be aggregated together with a coloured coin offer to ensure that the trade happens
async def create_spend_bundle_relative_chia(self, chia_amount: int, exclude: List[Coin]):
async def create_spend_bundle_relative_chia(
self, chia_amount: int, exclude: List[Coin]
):
list_of_solutions = []
utxos = None

View File

@ -343,7 +343,9 @@ class TestWalletSimulator:
assert spend_bundle is not None
trade_manager_1.write_offer_to_disk(file_path, spend_bundle)
success, offer, error = await trade_manager_2.get_discrepancies_for_offer(file_path)
success, offer, error = await trade_manager_2.get_discrepancies_for_offer(
file_path
)
assert error is None
assert success is True
@ -548,7 +550,9 @@ class TestWalletSimulator:
assert spend_bundle is not None
trade_manager_1.write_offer_to_disk(file_path, spend_bundle)
success, offer, error = await trade_manager_2.get_discrepancies_for_offer(file_path)
success, offer, error = await trade_manager_2.get_discrepancies_for_offer(
file_path
)
assert error is None
assert success is True
assert offer is not None
@ -655,7 +659,9 @@ class TestWalletSimulator:
assert spend_bundle is not None
trade_manager_2.write_offer_to_disk(file_path, spend_bundle)
success, offer, error = await trade_manager_1.get_discrepancies_for_offer(file_path)
success, offer, error = await trade_manager_1.get_discrepancies_for_offer(
file_path
)
assert error is None
assert success is True