Skip to content

Commit

Permalink
Wallet RPC client and server not following standard contract (Chia-Ne…
Browse files Browse the repository at this point in the history
…twork#351)

* follow standard contract of rpc server

* use new var instead of re-assigning to existing one

* display warning message when balances cannot be displayed

* remove type from summaries

* appease the lint gods

* handle non success case

* better approach to handling None which linter will allow
  • Loading branch information
freddiecoleman authored and hoffmang9 committed Aug 18, 2020
1 parent eb2b2cd commit 94eb0c9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 49 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ for setuptools_scm/PEP 440 reasons.
- Improvements to coloured coin wallet.

### Fixed

- `chia show -w` now displays a message when balances cannot be displayed instead of throwing an error

## [1.0beta9] aka Beta 1.9 - 2020-07-27

Expand Down
89 changes: 48 additions & 41 deletions src/cmds/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
from time import struct_time, localtime

from typing import List, Optional, Dict
from typing import List, Optional

from src.server.connection import NodeType
from src.types.header_block import HeaderBlock
Expand Down Expand Up @@ -317,46 +317,53 @@ async def show_async(args, parser):
else:
wallet_rpc_port = args.wallet_rpc_port
wallet_client = await WalletRpcClient.create(self_hostname, wallet_rpc_port)
summaries: Dict = await wallet_client.get_wallet_summaries()
print("Balances")
for wallet_id, summary in summaries.items():
balances = await wallet_client.get_wallet_balance(wallet_id)
if "name" in summary:
print(
f"Wallet ID {wallet_id} type {summary['type']} {summary['name']}"
)
print(
f" -Confirmed: {balances['confirmed_wallet_balance']/units['colouredcoin']}"
)
print(
f" -Unconfirmed: {balances['unconfirmed_wallet_balance']/units['colouredcoin']}"
)
print(
f" -Spendable: {balances['spendable_balance']/units['colouredcoin']}"
)
print(
f" -Frozen: {balances['frozen_balance']/units['colouredcoin']}"
)
print(
f" -Pending change: {balances['pending_change']/units['colouredcoin']}"
)
else:
print(f"Wallet ID {wallet_id} type {summary['type']}")
print(
f" -Confirmed: {balances['confirmed_wallet_balance']/units['chia']} TXCH"
)
print(
f" -Unconfirmed: {balances['unconfirmed_wallet_balance']/units['chia']} TXCH"
)
print(
f" -Spendable: {balances['spendable_balance']/units['chia']} TXCH"
)
print(
f" -Frozen: {balances['frozen_balance']/units['chia']} TXCH"
)
print(
f" -Pending change: {balances['pending_change']/units['chia']} TXCH"
)
summaries_response = await wallet_client.get_wallet_summaries()
if "wallet_summaries" not in summaries_response:
print("Wallet summary cannot be displayed")
else:
print("Balances")
for wallet_id, summary in summaries_response["wallet_summaries"].items():
balances_response = await wallet_client.get_wallet_balance(wallet_id)
if "balances" not in balances_response:
print("Balances cannot be displayed")
continue
balances = balances_response["balances"]
if "name" in summary:
print(
f"Wallet ID {wallet_id} type {summary['type']} {summary['name']}"
)
print(
f" -Confirmed: {balances['confirmed_wallet_balance']/units['colouredcoin']}"
)
print(
f" -Unconfirmed: {balances['unconfirmed_wallet_balance']/units['colouredcoin']}"
)
print(
f" -Spendable: {balances['spendable_balance']/units['colouredcoin']}"
)
print(
f" -Frozen: {balances['frozen_balance']/units['colouredcoin']}"
)
print(
f" -Pending change: {balances['pending_change']/units['colouredcoin']}"
)
else:
print(f"Wallet ID {wallet_id} type {summary['type']}")
print(
f" -Confirmed: {balances['confirmed_wallet_balance']/units['chia']} TXCH"
)
print(
f" -Unconfirmed: {balances['unconfirmed_wallet_balance']/units['chia']} TXCH"
)
print(
f" -Spendable: {balances['spendable_balance']/units['chia']} TXCH"
)
print(
f" -Frozen: {balances['frozen_balance']/units['chia']} TXCH"
)
print(
f" -Pending change: {balances['pending_change']/units['chia']} TXCH"
)
wallet_client.close()
await wallet_client.await_closed()

Expand Down
13 changes: 6 additions & 7 deletions src/rpc/wallet_rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,16 @@ async def get_wallet_balance(self, request: Dict):
else:
frozen_balance = await wallet.get_frozen_amount()

response = {
wallet_balance = {
"wallet_id": wallet_id,
"success": True,
"confirmed_wallet_balance": balance,
"unconfirmed_wallet_balance": pending_balance,
"spendable_balance": spendable_balance,
"frozen_balance": frozen_balance,
"pending_change": pending_change,
}

return response
return {"success": True, "wallet_balance": wallet_balance}

async def get_sync_status(self, request: Dict):
if self.service.wallet_state_manager is None:
Expand Down Expand Up @@ -470,23 +469,23 @@ async def cc_get_colour(self, request):
async def get_wallet_summaries(self, request: Dict):
if self.service.wallet_state_manager is None:
return {"success": False}
response = {}
wallet_summaries = {}
for wallet_id in self.service.wallet_state_manager.wallets:
wallet = self.service.wallet_state_manager.wallets[wallet_id]
balance = await wallet.get_confirmed_balance()
type = wallet.wallet_info.type
if type == WalletType.COLOURED_COIN.value:
name = wallet.cc_info.my_colour_name
colour = wallet.get_colour()
response[wallet_id] = {
wallet_summaries[wallet_id] = {
"type": type,
"balance": balance,
"name": name,
"colour": colour,
}
else:
response[wallet_id] = {"type": type, "balance": balance}
return response
wallet_summaries[wallet_id] = {"type": type, "balance": balance}
return {"success": True, "wallet_summaries": wallet_summaries}

async def get_discrepancies_for_offer(self, request):
file_name = request["filename"]
Expand Down

0 comments on commit 94eb0c9

Please sign in to comment.