Skip to content

Commit

Permalink
rusk: HTTP - add endpoint for query moonlight address
Browse files Browse the repository at this point in the history
Resolves #3414
  • Loading branch information
herr-seppia committed Jan 24, 2025
1 parent e818f0c commit ff319a8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
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/node/<address>/account` endpoint [#3414]

### Changed

- Change dependency declaration to not require strict equal [#3405]
Expand Down Expand Up @@ -300,6 +304,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 -->
[#3414]: https://github.com/dusk-network/rusk/issues/3414
[#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 @@ -6,12 +6,14 @@

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 All @@ -28,6 +30,7 @@ impl HandleRequest for Rusk {
match request.uri.inner() {
("contracts", Some(_), _) => true,
("node", _, "provisioners") => true,
("node", Some(_), "account") => true,
("node", _, "crs") => true,
_ => false,
}
Expand All @@ -43,6 +46,8 @@ impl HandleRequest for Rusk {
self.handle_contract_query(contract_id, method, data, feeder)
}
("node", _, "provisioners") => self.get_provisioners(),

("node", Some(pk), "account") => self.get_account(pk),
("node", _, "crs") => self.get_crs(),
_ => Err(anyhow::anyhow!("Unsupported")),
}
Expand Down Expand Up @@ -107,6 +112,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

0 comments on commit ff319a8

Please sign in to comment.