Skip to content

Commit 66a2ec7

Browse files
committed
Port get_current_derivation_index
1 parent 1116561 commit 66a2ec7

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

chia/cmds/wallet_funcs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ async def delete_unconfirmed_transactions(
433433
async def get_derivation_index(root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int]) -> None:
434434
async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _):
435435
res = await wallet_client.get_current_derivation_index()
436-
print(f"Last derivation index: {res}")
436+
print(f"Last derivation index: {res.index}")
437437

438438

439439
async def update_derivation_index(

chia/wallet/wallet_request_types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,12 @@ class DeleteUnconfirmedTransactions(Streamable):
433433
wallet_id: uint32
434434

435435

436+
@streamable
437+
@dataclass(frozen=True)
438+
class GetCurrentDerivationIndexResponse(Streamable):
439+
index: Optional[uint32]
440+
441+
436442
@streamable
437443
@dataclass(frozen=True)
438444
class GetOffersCountResponse(Streamable):

chia/wallet/wallet_rpc_api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
GatherSigningInfo,
170170
GatherSigningInfoResponse,
171171
GenerateMnemonicResponse,
172+
GetCurrentDerivationIndexResponse,
172173
GetHeightInfoResponse,
173174
GetLoggedInFingerprintResponse,
174175
GetNextAddress,
@@ -1870,12 +1871,13 @@ async def get_coin_records_by_names(self, request: dict[str, Any]) -> EndpointRe
18701871

18711872
return {"coin_records": [cr.to_json_dict() for cr in coin_records]}
18721873

1873-
async def get_current_derivation_index(self, request: dict[str, Any]) -> dict[str, Any]:
1874+
@marshal
1875+
async def get_current_derivation_index(self, request: Empty) -> GetCurrentDerivationIndexResponse:
18741876
assert self.service.wallet_state_manager is not None
18751877

18761878
index: Optional[uint32] = await self.service.wallet_state_manager.puzzle_store.get_last_derivation_path()
18771879

1878-
return {"success": True, "index": index}
1880+
return GetCurrentDerivationIndexResponse(index)
18791881

18801882
async def extend_derivation_index(self, request: dict[str, Any]) -> dict[str, Any]:
18811883
assert self.service.wallet_state_manager is not None

chia/wallet/wallet_rpc_client.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
GatherSigningInfoResponse,
8787
GenerateMnemonicResponse,
8888
GetCATListResponse,
89+
GetCurrentDerivationIndexResponse,
8990
GetHeightInfoResponse,
9091
GetLoggedInFingerprintResponse,
9192
GetNextAddress,
@@ -369,10 +370,8 @@ async def spend_clawback_coins(
369370
async def delete_unconfirmed_transactions(self, request: DeleteUnconfirmedTransactions) -> None:
370371
await self.fetch("delete_unconfirmed_transactions", request.to_json_dict())
371372

372-
async def get_current_derivation_index(self) -> str:
373-
response = await self.fetch("get_current_derivation_index", {})
374-
index = response["index"]
375-
return str(index)
373+
async def get_current_derivation_index(self) -> GetCurrentDerivationIndexResponse:
374+
return GetCurrentDerivationIndexResponse.from_json_dict(await self.fetch("get_current_derivation_index", {}))
376375

377376
async def extend_derivation_index(self, index: int) -> str:
378377
response = await self.fetch("extend_derivation_index", {"index": index})

0 commit comments

Comments
 (0)