Skip to content

Commit

Permalink
Add status, label and extradata to RPC display
Browse files Browse the repository at this point in the history
Fixes JoinMarket-Org#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.
  • Loading branch information
AdamISZ committed Jan 7, 2022
1 parent d98cb36 commit 3939714
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 5 additions & 1 deletion jmclient/jmclient/wallet-rpc-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,11 @@ components:
type: string
amount:
type: string
labels:
status:
type: string
label:
type: string
extradata:
type: string

CreateWalletResponse:
Expand Down
4 changes: 3 additions & 1 deletion jmclient/jmclient/wallet_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ def serialize_json(self):
return {"hd_path": self.wallet_path_repr,
"address": self.serialize_address(),
"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):
return self.wallet_path_repr.ljust(20)
Expand Down
15 changes: 14 additions & 1 deletion jmclient/test/test_wallet_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ def test_direct_send_and_display_wallet(self):
"destination": "2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br"}).encode())
yield self.do_request(agent, b"POST", addr, body,
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
# tx before querying /display:
self.daemon.wallet_service.transaction_monitor()
Expand All @@ -288,11 +292,20 @@ def process_direct_send_response(self, response, code):
def process_wallet_display_response(self, response, code):
assert code == 200
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(
latest_balance))
assert latest_balance > self.mean_amt * 4.0 - 1.1
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
def test_getaddress(self):
Expand Down

0 comments on commit 3939714

Please sign in to comment.