mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2026-09-13 02:24:38 -05:00
get all transactions
This commit is contained in:
@@ -82,17 +82,22 @@ class RpcWalletApiHandler:
|
||||
return obj_to_response(response)
|
||||
|
||||
async def get_transactions(self, request) -> web.Response:
|
||||
transactions = await self.wallet_node.wallet_state_manager.get_all_transactions()
|
||||
|
||||
response = {"success": True}
|
||||
response = {"success": True, "txs": transactions}
|
||||
return obj_to_response(response)
|
||||
|
||||
async def get_wallet_balance(self, request) -> web.Response:
|
||||
|
||||
balance = await self.wallet_node.wallet.get_confirmed_balance()
|
||||
pending_balance = await self.wallet_node.wallet.get_unconfirmed_balance()
|
||||
|
||||
response = {
|
||||
"success": True,
|
||||
"confirmed_wallet_balance": 0,
|
||||
"unconfirmed_wallet_balance": 0,
|
||||
"confirmed_wallet_balance": balance,
|
||||
"unconfirmed_wallet_balance": pending_balance,
|
||||
}
|
||||
|
||||
return obj_to_response(response)
|
||||
|
||||
|
||||
|
||||
@@ -203,6 +203,7 @@ class Wallet:
|
||||
async def generate_signed_transaction(
|
||||
self, amount, newpuzzlehash, fee: int = 0
|
||||
) -> Optional[SpendBundle]:
|
||||
""" Use this to generate transaction. """
|
||||
transaction = await self.generate_unsigned_transaction(
|
||||
amount, newpuzzlehash, fee
|
||||
)
|
||||
@@ -211,7 +212,7 @@ class Wallet:
|
||||
return self.sign_transaction(transaction)
|
||||
|
||||
async def push_transaction(self, spend_bundle: SpendBundle):
|
||||
""" Use this API to make transactions. """
|
||||
""" Use this API to send transactions. """
|
||||
await self.wallet_state_manager.add_pending_transaction(spend_bundle)
|
||||
await self._send_transaction(spend_bundle)
|
||||
|
||||
|
||||
@@ -180,3 +180,10 @@ class WalletStateManager:
|
||||
"""
|
||||
records = await self.tx_store.get_not_sent()
|
||||
return records
|
||||
|
||||
async def get_all_transactions(self) -> List[TransactionRecord]:
|
||||
"""
|
||||
Retrieves all confirmed and pending transactions
|
||||
"""
|
||||
records = await self.tx_store.get_all_transactions()
|
||||
return records
|
||||
|
||||
+13
-13
@@ -17,7 +17,7 @@ class WalletStore:
|
||||
# Whether or not we are syncing
|
||||
sync_mode: bool = False
|
||||
lock: asyncio.Lock
|
||||
lca_coin_records: Dict[str, CoinRecord]
|
||||
coin_record_cache: Dict[str, CoinRecord]
|
||||
cache_size: uint32
|
||||
|
||||
@classmethod
|
||||
@@ -61,7 +61,7 @@ class WalletStore:
|
||||
await self.coin_record_db.commit()
|
||||
# Lock
|
||||
self.lock = asyncio.Lock() # external
|
||||
self.lca_coin_records = dict()
|
||||
self.coin_record_cache = dict()
|
||||
return self
|
||||
|
||||
async def close(self):
|
||||
@@ -89,11 +89,11 @@ class WalletStore:
|
||||
)
|
||||
await cursor.close()
|
||||
await self.coin_record_db.commit()
|
||||
self.lca_coin_records[record.coin.name().hex()] = record
|
||||
if len(self.lca_coin_records) > self.cache_size:
|
||||
while len(self.lca_coin_records) > self.cache_size:
|
||||
first_in = list(self.lca_coin_records.keys())[0]
|
||||
del self.lca_coin_records[first_in]
|
||||
self.coin_record_cache[record.coin.name().hex()] = record
|
||||
if len(self.coin_record_cache) > self.cache_size:
|
||||
while len(self.coin_record_cache) > self.cache_size:
|
||||
first_in = list(self.coin_record_cache.keys())[0]
|
||||
del self.coin_record_cache[first_in]
|
||||
|
||||
# Update coin_record to be spent in DB
|
||||
async def set_spent(self, coin_name: bytes32, index: uint32):
|
||||
@@ -102,13 +102,13 @@ class WalletStore:
|
||||
return
|
||||
spent: CoinRecord = CoinRecord(
|
||||
current.coin, current.confirmed_block_index, index, True, current.coinbase,
|
||||
) # type: ignore # noqa
|
||||
)
|
||||
await self.add_coin_record(spent)
|
||||
|
||||
# Checks DB and DiffStores for CoinRecord with coin_name and returns it
|
||||
async def get_coin_record(self, coin_name: bytes32) -> Optional[CoinRecord]:
|
||||
if coin_name.hex() in self.lca_coin_records:
|
||||
return self.lca_coin_records[coin_name.hex()]
|
||||
if coin_name.hex() in self.coin_record_cache:
|
||||
return self.coin_record_cache[coin_name.hex()]
|
||||
cursor = await self.coin_record_db.execute(
|
||||
"SELECT * from coin_record WHERE coin_name=?", (coin_name.hex(),)
|
||||
)
|
||||
@@ -157,7 +157,7 @@ class WalletStore:
|
||||
async def rollback_lca_to_block(self, block_index):
|
||||
# Update memory cache
|
||||
delete_queue: bytes32 = []
|
||||
for coin_name, coin_record in self.lca_coin_records.items():
|
||||
for coin_name, coin_record in self.coin_record_cache.items():
|
||||
if coin_record.spent_block_index > block_index:
|
||||
new_record = CoinRecord(
|
||||
coin_record.coin,
|
||||
@@ -166,12 +166,12 @@ class WalletStore:
|
||||
False,
|
||||
coin_record.coinbase,
|
||||
)
|
||||
self.lca_coin_records[coin_record.coin.name().hex()] = new_record
|
||||
self.coin_record_cache[coin_record.coin.name().hex()] = new_record
|
||||
if coin_record.confirmed_block_index > block_index:
|
||||
delete_queue.append(coin_name)
|
||||
|
||||
for coin_name in delete_queue:
|
||||
del self.lca_coin_records[coin_name]
|
||||
del self.coin_record_cache[coin_name]
|
||||
|
||||
# Delete from storage
|
||||
c1 = await self.coin_record_db.execute(
|
||||
|
||||
@@ -172,3 +172,16 @@ class WalletTransactionStore:
|
||||
records.append(record)
|
||||
|
||||
return records
|
||||
|
||||
async def get_all_transactions(self) -> List[TransactionRecord]:
|
||||
cursor = await self.transaction_db.execute(
|
||||
"SELECT * from transaction_record"
|
||||
)
|
||||
rows = await cursor.fetchall()
|
||||
await cursor.close()
|
||||
records = []
|
||||
for row in rows:
|
||||
record = TransactionRecord.from_bytes(row[6])
|
||||
records.append(record)
|
||||
|
||||
return records
|
||||
|
||||
Reference in New Issue
Block a user