Skip to content

Commit

Permalink
Add a wallet endpoint to get used addresses for a particular wallet ID
Browse files Browse the repository at this point in the history
  • Loading branch information
cmmarslender committed Feb 16, 2023
1 parent b0a0314 commit 9db36c5
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions chia/rpc/wallet_rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def get_routes(self) -> Dict[str, Endpoint]:
"/sign_message_by_id": self.sign_message_by_id,
"/verify_signature": self.verify_signature,
"/get_transaction_memo": self.get_transaction_memo,
"/get_used_addresses": self.get_used_addresses,
# CATs and trading
"/cat_set_name": self.cat_set_name,
"/cat_asset_id_to_name": self.cat_asset_id_to_name,
Expand Down Expand Up @@ -883,6 +884,30 @@ async def get_transaction_memo(self, request: Dict) -> EndpointResult:
response[coin_id.hex()] = [memo.hex() for memo in memo_list]
return {transaction_id.hex(): response}

async def get_used_addresses(self, request: Dict) -> EndpointResult:
"""Returns addresses that have actually been used, as determined by looking at the puzzle hash of coins"""
wallet_id = int(request.get("wallet_id", 1))

async with self.service.wallet_state_manager.db_wrapper.reader_no_transaction() as conn:
rows = await conn.execute_fetchall(
"SELECT DISTINCT derivation_paths.puzzle_hash, hardened from derivation_paths"
" inner join coin_record on derivation_paths.puzzle_hash=coin_record.puzzle_hash"
" where coin_record.wallet_id=?"
" order by hardened asc",
(wallet_id,),
)

return {
"addresses": [
{
"puzzle_hash": row[0],
"address": encode_puzzle_hash(bytes32.from_hexstr(row[0]), "xch"),
"observer": row[1] == 0,
}
for row in rows
]
}

async def get_transactions(self, request: Dict) -> EndpointResult:
wallet_id = int(request["wallet_id"])

Expand Down

0 comments on commit 9db36c5

Please sign in to comment.