Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rusk: HTTP - add endpoint for query account status #3423

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions rusk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- Add `/on/account:<address>/status` endpoint [#3422]

### Changed

- Change dependency declaration to not require strict equal [#3405]
Expand Down Expand Up @@ -296,6 +300,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add build system that generates keys for circuits and caches them.

<!-- Issues -->
[#3422]: https://github.com/dusk-network/rusk/issues/3422
[#3405]: https://github.com/dusk-network/rusk/issues/3405
[#3359]: https://github.com/dusk-network/rusk/issues/3359
[#3206]: https://github.com/dusk-network/rusk/issues/3206
Expand Down
25 changes: 24 additions & 1 deletion rusk/src/lib/http/rusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
use super::event::Event;
use super::*;

use dusk_bytes::Serializable;
use dusk_bytes::{DeserializableSlice, Serializable};
use dusk_core::abi::ContractId;
use dusk_core::signatures::bls::PublicKey as BlsPublicKey;
use dusk_core::stake::StakeFundOwner;
use node::vm::VMExecution;
use rusk_profile::CRS_17_HASH;
use serde::Serialize;
use serde_json::json;
use std::sync::{mpsc, Arc};
use std::thread;
use tokio::task;
Expand Down Expand Up @@ -44,6 +46,7 @@ impl HandleRequest for Rusk {
match request.uri.inner() {
("contracts", Some(_), _) => true,
("node", _, "provisioners") => true,
("account", Some(_), "status") => true,
("node", _, "crs") => true,
_ => false,
}
Expand All @@ -59,6 +62,8 @@ impl HandleRequest for Rusk {
self.handle_contract_query(contract_id, method, data, feeder)
}
("node", _, "provisioners") => self.get_provisioners(),

("account", Some(pk), "status") => self.get_account(pk),
("node", _, "crs") => self.get_crs(),
_ => Err(anyhow::anyhow!("Unsupported")),
}
Expand Down Expand Up @@ -151,6 +156,24 @@ impl Rusk {
Ok(ResponseData::new(serde_json::to_value(prov)?))
}

fn get_account(&self, pk: &str) -> anyhow::Result<ResponseData> {
let pk = bs58::decode(pk)
.into_vec()
.map_err(|_| anyhow::anyhow!("Invalid bs58 account"))?;
let pk = BlsPublicKey::from_slice(&pk)
.map_err(|_| anyhow::anyhow!("Invalid bls account"))?;
let account = self
.account(&pk)
.map(|account| {
json!({
"balance": account.balance,
"nonce": account.nonce,
})
})
.map_err(|e| anyhow::anyhow!("Cannot query the state {e:?}"))?;
Ok(ResponseData::new(account))
}

fn get_crs(&self) -> anyhow::Result<ResponseData> {
let crs = rusk_profile::get_common_reference_string()?;
Ok(ResponseData::new(crs).with_header("crs-hash", CRS_17_HASH))
Expand Down
Loading