-
Notifications
You must be signed in to change notification settings - Fork 103
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
Adding API endpoint to get fee balance per account #2165
Changes from 2 commits
26f6d6e
4401ce7
66c21d9
8fcad79
d19a139
15124eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[route.getfeebalance] | ||
PATH = ["/fee_balance/:address"] | ||
":address" = "Literal" | ||
DOC = "Get current balance in address account." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Balance in fee state" or something like that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And mention that we are expecting an ethereum address in hex format. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in d19a139 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
//! Sequencer-specific API endpoint handlers. | ||
|
||
use std::{ | ||
collections::{BTreeSet, HashMap}, | ||
env, | ||
}; | ||
|
||
use anyhow::Result; | ||
use committable::Committable; | ||
use espresso_types::{NamespaceId, NsProof, PubKey, Transaction}; | ||
use espresso_types::{FeeMerkleTree, NamespaceId, NsProof, PubKey, Transaction}; | ||
use futures::{try_join, FutureExt}; | ||
use hotshot_query_service::merklized_state::Snapshot; | ||
use hotshot_query_service::{ | ||
availability::{self, AvailabilityDataSource, CustomSnafu, FetchBlockSnafu}, | ||
data_source::storage::ExplorerStorage, | ||
|
@@ -27,6 +23,10 @@ use hotshot_types::{ | |
}; | ||
use serde::{de::Error as _, Deserialize, Serialize}; | ||
use snafu::OptionExt; | ||
use std::{ | ||
collections::{BTreeSet, HashMap}, | ||
env, | ||
}; | ||
use tagged_base64::TaggedBase64; | ||
use tide_disco::{method::ReadState, Api, Error as _, StatusCode}; | ||
use vbs::version::StaticVersionType; | ||
|
@@ -46,6 +46,42 @@ pub struct NamespaceProofQueryData { | |
pub transactions: Vec<Transaction>, | ||
} | ||
|
||
pub(super) fn get_balance<State, Ver>() -> Result<Api<State, merklized_state::Error, Ver>> | ||
fkrell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
where | ||
State: 'static + Send + Sync + ReadState, | ||
Ver: 'static + StaticVersionType, | ||
<State as ReadState>::State: Send | ||
+ Sync | ||
+ MerklizedStateDataSource<SeqTypes, FeeMerkleTree, 256> | ||
fkrell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
+ MerklizedStateHeightPersistence, | ||
//for<'a> <<UniversalMerkleTree<FeeAmount,Sha3Digest,FeeAccount,256,Sha3Node> as hotshot_query_service::merklized_state::MerklizedState<Types, ARITY>>::Commit as TryFrom<&'a TaggedBase64>>::Error: Display, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in d19a139 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete before merging There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in d19a139 |
||
{ | ||
let mut options = merklized_state::Options::default(); | ||
let extension = toml::from_str(include_str!("../../api/merklized_state.toml"))?; | ||
options.extensions.push(extension); | ||
|
||
let mut api = | ||
merklized_state::define_api::<State, SeqTypes, FeeMerkleTree, Ver, 256>(&options)?; | ||
|
||
api.get("getfeebalance", move |req, state| { | ||
async move { | ||
let address = req.string_param("address")?; | ||
let height = state.get_last_state_height().await?; | ||
sveitser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let snapshot = Snapshot::Index(height as u64); | ||
let key = address | ||
.parse() | ||
.map_err(|_| merklized_state::Error::Custom { | ||
message: "failed to parse Key param".to_string(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Failed to parse address? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in d19a139 |
||
status: StatusCode::INTERNAL_SERVER_ERROR, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a 400 / BadRequest error because it's the client's fault. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in d19a139 |
||
})?; | ||
let path = state.get_path(snapshot, key).await?; | ||
Ok(path.elem().copied()) | ||
} | ||
.boxed() | ||
})?; | ||
Ok(api) | ||
} | ||
|
||
pub(super) type AvailState<N, P, D, ApiVer> = ApiState<StorageState<N, P, D, ApiVer>>; | ||
|
||
type AvailabilityApi<N, P, D, V, ApiVer> = Api<AvailState<N, P, D, V>, availability::Error, ApiVer>; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a convention we usually use hyphens in URL segments eg
fee-balance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in d19a139