Skip to content

Commit b272738

Browse files
vlad9486Adrian Nagy
authored andcommitted
(feat/graphql): fix account endpoint
1 parent b59148e commit b272738

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

node/native/src/graphql/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,20 @@ struct Query;
239239
impl Query {
240240
async fn account(
241241
public_key: String,
242-
token: String,
242+
token: Option<String>,
243243
context: &Context,
244244
) -> juniper::FieldResult<account::GraphQLAccount> {
245-
let token_id = TokenIdKeyHash::from_str(&token)?;
246245
let public_key = AccountPublicKey::from_str(&public_key)?;
246+
let req = match token {
247+
None => AccountQuery::SinglePublicKey(public_key),
248+
Some(token) => {
249+
let token_id = TokenIdKeyHash::from_str(&token)?;
250+
AccountQuery::PubKeyWithTokenId(public_key, token_id)
251+
}
252+
};
247253
let accounts: Vec<Account> = context
248254
.rpc_sender
249-
.oneshot_request(RpcRequest::LedgerAccountsGet(
250-
AccountQuery::PubKeyWithTokenId(public_key, token_id),
251-
))
255+
.oneshot_request(RpcRequest::LedgerAccountsGet(req))
252256
.await
253257
.ok_or(Error::StateMachineEmptyResponse)?;
254258

node/src/ledger/ledger_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ impl LedgerRequest {
236236
}
237237
LedgerReadRequest::AccountsForRpc(rpc_id, ledger_hash, account_query) => {
238238
let res = match &account_query {
239+
AccountQuery::All => ledger_ctx.get_accounts_for_rpc(ledger_hash, None),
239240
AccountQuery::SinglePublicKey(public_key) => ledger_ctx
240241
.get_accounts_for_rpc(ledger_hash, Some(public_key.clone())),
241-
AccountQuery::All => ledger_ctx.get_accounts_for_rpc(ledger_hash, None),
242242
AccountQuery::PubKeyWithTokenId(public_key, token_id_key_hash) => {
243243
let id = AccountId {
244244
public_key: public_key.clone().try_into().unwrap(),

node/src/rpc/rpc_actions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ pub enum RpcAction {
251251

252252
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
253253
pub enum AccountQuery {
254-
SinglePublicKey(AccountPublicKey),
255254
All,
255+
SinglePublicKey(AccountPublicKey),
256256
PubKeyWithTokenId(AccountPublicKey, TokenIdKeyHash),
257257
}
258258

node/src/rpc_effectful/rpc_effectful_effects.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,9 @@ pub fn rpc_effects<S: Service>(store: &mut Store<S>, action: ActionWithMeta<RpcE
639639
accounts,
640640
account_query,
641641
} => {
642+
// Is this todo still relevant?
642643
// TODO(adonagy): maybe something more effective?
643644
match account_query {
644-
AccountQuery::SinglePublicKey(_pk) => todo!(),
645645
// all the accounts for the FE in Slim form
646646
AccountQuery::All => {
647647
let mut accounts: BTreeMap<CompressedPubKey, Account> = accounts
@@ -683,7 +683,7 @@ pub fn rpc_effects<S: Service>(store: &mut Store<S>, action: ActionWithMeta<RpcE
683683
)
684684
}
685685
// for the graphql endpoint
686-
AccountQuery::PubKeyWithTokenId(..) => {
686+
AccountQuery::SinglePublicKey(..) | AccountQuery::PubKeyWithTokenId(..) => {
687687
respond_or_log!(
688688
store.service().respond_ledger_accounts(rpc_id, accounts),
689689
meta.time()

0 commit comments

Comments
 (0)