Fix wallet balance overflow

This commit is contained in:
Mariano Sorgente 2021-02-11 12:53:38 +09:00 committed by Gene Hoffman
parent 6450653bb6
commit e1a3f66cee
4 changed files with 21 additions and 21 deletions

View File

@ -19,7 +19,7 @@ from src.util.condition_tools import (
pkm_pairs_for_conditions_dict,
)
from src.util.json_util import dict_to_json_str
from src.util.ints import uint8, uint64, uint32
from src.util.ints import uint8, uint64, uint32, uint128
from src.wallet.block_record import HeaderBlockRecord
from src.wallet.cc_wallet.cc_info import CCInfo
from src.wallet.puzzles.p2_delegated_puzzle_or_hidden_puzzle import (
@ -208,7 +208,7 @@ class CCWallet:
self.log.info(f"Confirmed balance for cc wallet {self.id()} is {amount}")
return uint64(amount)
async def get_unconfirmed_balance(self, unspent_records=None) -> uint64:
async def get_unconfirmed_balance(self, unspent_records=None) -> uint128:
confirmed = await self.get_confirmed_balance(unspent_records)
unconfirmed_tx: List[TransactionRecord] = await self.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(
self.id()
@ -225,7 +225,7 @@ class CCWallet:
result = confirmed - removal_amount + addition_amount
self.log.info(f"Unconfirmed balance for cc wallet {self.id()} is {result}")
return uint64(result)
return uint128(result)
async def get_name(self):
return self.wallet_info.name

View File

@ -12,7 +12,7 @@ from src.types.program import Program
from src.types.spend_bundle import SpendBundle
from src.types.sized_bytes import bytes32
from src.util.byte_types import hexstr_to_bytes
from src.util.ints import uint8, uint64, uint32
from src.util.ints import uint8, uint64, uint32, uint128
from src.util.streamable import streamable, Streamable
from src.wallet.rl_wallet.rl_wallet_puzzles import (
rl_puzzle_for_pk,
@ -336,13 +336,13 @@ class RLWallet:
available_amount = min(unlocked, total_amount)
return uint64(available_amount)
async def get_confirmed_balance(self, unspent_records=None) -> uint64:
async def get_confirmed_balance(self, unspent_records=None) -> uint128:
return await self.wallet_state_manager.get_confirmed_balance_for_wallet(self.id(), unspent_records)
async def get_unconfirmed_balance(self, unspent_records=None) -> uint64:
async def get_unconfirmed_balance(self, unspent_records=None) -> uint128:
return await self.wallet_state_manager.get_unconfirmed_balance(self.id(), unspent_records)
async def get_spendable_balance(self, unspent_records=None) -> uint64:
async def get_spendable_balance(self, unspent_records=None) -> uint128:
spendable_am = await self.wallet_state_manager.get_confirmed_spendable_balance_for_wallet(self.id())
return spendable_am

View File

@ -9,7 +9,7 @@ from src.types.coin_solution import CoinSolution
from src.types.program import Program
from src.types.sized_bytes import bytes32
from src.types.spend_bundle import SpendBundle
from src.util.ints import uint8, uint64, uint32
from src.util.ints import uint8, uint64, uint32, uint128
from src.wallet.puzzles.p2_delegated_puzzle_or_hidden_puzzle import (
puzzle_for_pk,
DEFAULT_HIDDEN_PUZZLE_HASH,
@ -63,13 +63,13 @@ class Wallet:
def id(self):
return self.wallet_id
async def get_confirmed_balance(self, unspent_records=None) -> uint64:
async def get_confirmed_balance(self, unspent_records=None) -> uint128:
return await self.wallet_state_manager.get_confirmed_balance_for_wallet(self.id(), unspent_records)
async def get_unconfirmed_balance(self, unspent_records=None) -> uint64:
async def get_unconfirmed_balance(self, unspent_records=None) -> uint128:
return await self.wallet_state_manager.get_unconfirmed_balance(self.id(), unspent_records)
async def get_spendable_balance(self, unspent_records=None) -> uint64:
async def get_spendable_balance(self, unspent_records=None) -> uint128:
spendable = await self.wallet_state_manager.get_confirmed_spendable_balance_for_wallet(
self.id(), unspent_records
)

View File

@ -22,7 +22,7 @@ from src.types.header_block import HeaderBlock
from src.types.sized_bytes import bytes32
from src.types.full_block import FullBlock
from src.util.byte_types import hexstr_to_bytes
from src.util.ints import uint32, uint64
from src.util.ints import uint32, uint64, uint128
from src.util.hash import std_hash
from src.wallet.block_record import HeaderBlockRecord
from src.wallet.cc_wallet.cc_wallet import CCWallet
@ -379,16 +379,16 @@ class WalletStateManager:
self.sync_mode = mode
self.state_changed("sync_changed")
async def get_confirmed_spendable_balance_for_wallet(self, wallet_id: int, unspent_records=None) -> uint64:
async def get_confirmed_spendable_balance_for_wallet(self, wallet_id: int, unspent_records=None) -> uint128:
"""
Returns the balance amount of all coins that are spendable.
"""
spendable: Set[WalletCoinRecord] = await self.get_spendable_coins_for_wallet(wallet_id, unspent_records)
spendable_amount: uint64 = uint64(0)
spendable_amount: uint128 = uint128(0)
for record in spendable:
spendable_amount = uint64(spendable_amount + record.coin.amount)
spendable_amount = uint128(spendable_amount + record.coin.amount)
return spendable_amount
@ -409,21 +409,21 @@ class WalletStateManager:
async def get_confirmed_balance_for_wallet(
self, wallet_id: int, unspent_coin_records: Optional[Set[WalletCoinRecord]] = None
) -> uint64:
) -> uint128:
"""
Returns the confirmed balance, including coinbase rewards that are not spendable.
"""
if unspent_coin_records is None:
unspent_coin_records = await self.coin_store.get_unspent_coins_for_wallet(wallet_id)
amount: uint64 = uint64(0)
amount: uint128 = uint128(0)
for record in unspent_coin_records:
amount = uint64(amount + record.coin.amount)
amount = uint128(amount + record.coin.amount)
self.log.info(f"Confirmed balance amount is {amount}")
return uint64(amount)
return uint128(amount)
async def get_unconfirmed_balance(
self, wallet_id, unspent_coin_records: Optional[Set[WalletCoinRecord]] = None
) -> uint64:
) -> uint128:
"""
Returns the balance, including coinbase rewards that are not spendable, and unconfirmed
transactions.
@ -438,7 +438,7 @@ class WalletStateManager:
removal_amount += record.fee_amount
result = confirmed - removal_amount
return uint64(result)
return uint128(result)
async def unconfirmed_additions_for_wallet(self, wallet_id: int) -> Dict[bytes32, Coin]:
"""