forked from LBRYCommunity/lbry-sdk
fix sqlite coin chooser floor
This commit is contained in:
parent
0aa7fd47d5
commit
8c695e42ca
2 changed files with 6 additions and 6 deletions
|
@ -529,13 +529,14 @@ def _get_spendable_utxos(transaction: sqlite3.Connection, accounts: List, decode
|
||||||
|
|
||||||
|
|
||||||
def get_and_reserve_spendable_utxos(transaction: sqlite3.Connection, accounts: List, amount_to_reserve: int, floor: int,
|
def get_and_reserve_spendable_utxos(transaction: sqlite3.Connection, accounts: List, amount_to_reserve: int, floor: int,
|
||||||
fee_per_byte: int, set_reserved: bool, return_insufficient_funds: bool):
|
fee_per_byte: int, set_reserved: bool, return_insufficient_funds: bool,
|
||||||
|
base_multiplier: int = 100):
|
||||||
txs = defaultdict(list)
|
txs = defaultdict(list)
|
||||||
decoded_transactions = {}
|
decoded_transactions = {}
|
||||||
reserved = []
|
reserved = []
|
||||||
|
|
||||||
reserved_dewies = 0
|
reserved_dewies = 0
|
||||||
multiplier = 10
|
multiplier = base_multiplier
|
||||||
gap_count = 0
|
gap_count = 0
|
||||||
|
|
||||||
while reserved_dewies < amount_to_reserve and gap_count < 5 and floor * multiplier < SQLITE_MAX_INTEGER:
|
while reserved_dewies < amount_to_reserve and gap_count < 5 and floor * multiplier < SQLITE_MAX_INTEGER:
|
||||||
|
@ -550,7 +551,7 @@ def get_and_reserve_spendable_utxos(transaction: sqlite3.Connection, accounts: L
|
||||||
multiplier **= 2
|
multiplier **= 2
|
||||||
else:
|
else:
|
||||||
gap_count = 0
|
gap_count = 0
|
||||||
multiplier = 10
|
multiplier = base_multiplier
|
||||||
|
|
||||||
# reserve the accumulated txos if enough were found
|
# reserve the accumulated txos if enough were found
|
||||||
if reserved_dewies >= amount_to_reserve:
|
if reserved_dewies >= amount_to_reserve:
|
||||||
|
@ -762,7 +763,7 @@ class Database(SQLiteMixin):
|
||||||
# 2. update address histories removing deleted TXs
|
# 2. update address histories removing deleted TXs
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def get_spendable_utxos(self, ledger, reserve_amount, accounts: Optional[Iterable], min_amount: int = 100000,
|
async def get_spendable_utxos(self, ledger, reserve_amount, accounts: Optional[Iterable], min_amount: int = 1,
|
||||||
fee_per_byte: int = 50, set_reserved: bool = True,
|
fee_per_byte: int = 50, set_reserved: bool = True,
|
||||||
return_insufficient_funds: bool = False) -> List:
|
return_insufficient_funds: bool = False) -> List:
|
||||||
to_spend = await self.db.run(
|
to_spend = await self.db.run(
|
||||||
|
|
|
@ -244,8 +244,7 @@ class Ledger(metaclass=LedgerRegistry):
|
||||||
def get_address_count(self, **constraints):
|
def get_address_count(self, **constraints):
|
||||||
return self.db.get_address_count(**constraints)
|
return self.db.get_address_count(**constraints)
|
||||||
|
|
||||||
async def get_spendable_utxos(self, amount: int, funding_accounts: Optional[Iterable['Account']],
|
async def get_spendable_utxos(self, amount: int, funding_accounts: Optional[Iterable['Account']], min_amount=1):
|
||||||
min_amount=100000):
|
|
||||||
min_amount = min(amount // 10, min_amount)
|
min_amount = min(amount // 10, min_amount)
|
||||||
fee = Output.pay_pubkey_hash(COIN, NULL_HASH32).get_fee(self)
|
fee = Output.pay_pubkey_hash(COIN, NULL_HASH32).get_fee(self)
|
||||||
selector = CoinSelector(amount, fee)
|
selector = CoinSelector(amount, fee)
|
||||||
|
|
Loading…
Add table
Reference in a new issue