Add a wallet RPC for converting heights to timestamps (#14357)

* Add a wallet RPC for converting heights to timestamps

* flake8
This commit is contained in:
Matt Hauff 2023-01-18 12:55:06 -07:00 committed by GitHub
parent 7b660956db
commit 8bb8ae5fea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View File

@ -109,6 +109,7 @@ class WalletRpcApi:
"/push_tx": self.push_tx,
"/push_transactions": self.push_transactions,
"/farm_block": self.farm_block, # Only when node simulator is running
"/get_timestamp_for_height": self.get_timestamp_for_height,
# this function is just here for backwards-compatibility. It will probably
# be removed in the future
"/get_initial_freeze_period": self.get_initial_freeze_period,
@ -541,6 +542,9 @@ class WalletRpcApi:
await self.service.server.send_to_all([msg], NodeType.FULL_NODE)
return {}
async def get_timestamp_for_height(self, request) -> EndpointResult:
return {"timestamp": await self.service.get_timestamp_for_height(uint32(request["height"]))}
##########################################################################################
# Wallet Management
##########################################################################################

View File

@ -90,6 +90,9 @@ class WalletRpcClient(RpcClient):
async def farm_block(self, address: str) -> Dict[str, Any]:
return await self.fetch("farm_block", {"address": address})
async def get_timestamp_for_height(self, height: uint32) -> uint64:
return uint64((await self.fetch("get_timestamp_for_height", {"height": height}))["timestamp"])
# Wallet Management APIs
async def get_wallets(self, wallet_type: Optional[WalletType] = None) -> Dict:
request: Dict[str, Any] = {}

View File

@ -296,6 +296,19 @@ async def test_push_transactions(wallet_rpc_environment: WalletRpcTestEnvironmen
assert tx.confirmed
@pytest.mark.asyncio
async def test_get_timestamp_for_height(wallet_rpc_environment: WalletRpcTestEnvironment):
env: WalletRpcTestEnvironment = wallet_rpc_environment
full_node_api: FullNodeSimulator = env.full_node.api
client: WalletRpcClient = env.wallet_1.rpc_client
await generate_funds(full_node_api, env.wallet_1)
# This tests that the client returns a uint64, rather than raising or returning something unexpected
uint64(await client.get_timestamp_for_height(uint32(1)))
@pytest.mark.parametrize(
"output_args, fee, select_coin, is_cat",
[