Browse Source

Add status, label and extradata to RPC display

Fixes #1118.
Before this commit, the json serializtion of a
WalletEntry object was incorrect and missing some
fields. This is now fixed, and the WalletDisplayResponse
in the RPC spec .yaml file correctly reflects the
fields that are returned by the JMWalletDaemon in response
to the /display request.
master
Adam Gibson 4 years ago
parent
commit
393971446e
No known key found for this signature in database
GPG Key ID: 141001A1AF77F20B
  1. 6
      jmclient/jmclient/wallet-rpc-api.yaml
  2. 4
      jmclient/jmclient/wallet_utils.py
  3. 15
      jmclient/test/test_wallet_rpc.py

6
jmclient/jmclient/wallet-rpc-api.yaml

@ -613,7 +613,11 @@ components:
type: string type: string
amount: amount:
type: string type: string
labels: status:
type: string
label:
type: string
extradata:
type: string type: string
CreateWalletResponse: CreateWalletResponse:

4
jmclient/jmclient/wallet_utils.py

@ -187,7 +187,9 @@ class WalletViewEntry(WalletViewBase):
return {"hd_path": self.wallet_path_repr, return {"hd_path": self.wallet_path_repr,
"address": self.serialize_address(), "address": self.serialize_address(),
"amount": self.serialize_amounts(), "amount": self.serialize_amounts(),
"labels": self.serialize_extra_data()} "status": self.serialize_status(),
"label": self.serialize_label(),
"extradata": self.serialize_extra_data()}
def serialize_wallet_position(self): def serialize_wallet_position(self):
return self.wallet_path_repr.ljust(20) return self.wallet_path_repr.ljust(20)

15
jmclient/test/test_wallet_rpc.py

@ -267,6 +267,10 @@ class TrialTestWRPC_DisplayWallet(WalletRPCTestBase, unittest.TestCase):
"destination": "2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br"}).encode()) "destination": "2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br"}).encode())
yield self.do_request(agent, b"POST", addr, body, yield self.do_request(agent, b"POST", addr, body,
self.process_direct_send_response) self.process_direct_send_response)
# before querying the wallet display, set a label to check:
labeladdr = self.daemon.wallet_service.get_addr(0,0,0)
self.daemon.wallet_service.set_address_label(labeladdr,
"test-wallet-rpc-label")
# force the wallet service txmonitor to wake up, to see the new # force the wallet service txmonitor to wake up, to see the new
# tx before querying /display: # tx before querying /display:
self.daemon.wallet_service.transaction_monitor() self.daemon.wallet_service.transaction_monitor()
@ -288,11 +292,20 @@ class TrialTestWRPC_DisplayWallet(WalletRPCTestBase, unittest.TestCase):
def process_wallet_display_response(self, response, code): def process_wallet_display_response(self, response, code):
assert code == 200 assert code == 200
json_body = json.loads(response.decode("utf-8")) json_body = json.loads(response.decode("utf-8"))
latest_balance = float(json_body["walletinfo"]["total_balance"]) wi = json_body["walletinfo"]
latest_balance = float(wi["total_balance"])
jlog.info("Wallet display currently shows balance: {}".format( jlog.info("Wallet display currently shows balance: {}".format(
latest_balance)) latest_balance))
assert latest_balance > self.mean_amt * 4.0 - 1.1 assert latest_balance > self.mean_amt * 4.0 - 1.1
assert latest_balance <= self.mean_amt * 4.0 - 1.0 assert latest_balance <= self.mean_amt * 4.0 - 1.0
# these samplings are an attempt to ensure object structure:
wia = wi["accounts"]
# note that only certain indices are present, based on funding
# and the direct-send tx above:
assert wia[0]["branches"][0]["entries"][0]["label"] == "test-wallet-rpc-label"
assert wia[0]["branches"][0]["entries"][0]["hd_path"] == "m/84'/1'/0'/0/0"
assert wia[1]["branches"][0]["entries"][1]["status"] == "used"
assert wia[1]["branches"][0]["entries"][1]["extradata"] == ""
@defer.inlineCallbacks @defer.inlineCallbacks
def test_getaddress(self): def test_getaddress(self):

Loading…
Cancel
Save