Skip to content

Commit

Permalink
adds newly supported classic ops, tweaks route and query for history
Browse files Browse the repository at this point in the history
  • Loading branch information
aristidesstaffieri committed Nov 20, 2023
1 parent e14c2d4 commit a8f793d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/route/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ export function initApiServer(
reply
) => {
const pubKey = request.params["pubKey"];
const contractIds = request.query["contract_ids"].split(",");
const contractIds = request.query["contract_ids"]
? request.query["contract_ids"].split(",")
: [];
const { data, error } = await mercuryClient.getAccountBalances(
pubKey,
contractIds,
Expand Down
8 changes: 8 additions & 0 deletions src/service/mercury/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,11 @@ export class MercuryClient {

getAccountHistory = async (pubKey: string) => {
try {
const xdrPubKey = new Address(pubKey).toScVal().toXDR("base64");
const getData = async () => {
const data = await this.urqlClient.query(query.getAccountHistory, {
pubKey,
xdrPubKey,
});
const errorMessage = getGraphQlError(data.error);
if (errorMessage) {
Expand Down Expand Up @@ -369,6 +371,12 @@ export class MercuryClient {
contractIds: string[],
network: NetworkNames
) => {
if (contractIds.length < 1) {
return {
data: [],
error: null,
};
}
// TODO: once classic subs include balance, add query
try {
const getData = async () => {
Expand Down
70 changes: 65 additions & 5 deletions src/service/mercury/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const query = {
}
`,
getAccountHistory: `
query GetAccountHistory($pubKey: String!) {
query GetAccountHistory($pubKey: String!, $xdrPubKey: String!) {
mintEvent: eventByTopic(t1: "AAAADgAAAARtaW50") {
edges {
node {
Expand All @@ -66,7 +66,7 @@ export const query = {
}
}
}
transferToEvent: eventByTopic(t1: "AAAADgAAAAh0cmFuc2Zlcg==", t2: $pubKey) {
transferToEvent: eventByTopic(t1: "AAAADgAAAAh0cmFuc2Zlcg==", t2: $xdrPubKey) {
edges {
node {
contractId
Expand All @@ -80,7 +80,7 @@ export const query = {
}
}
}
transferFromEvent: eventByTopic(t1: "AAAADgAAAAh0cmFuc2Zlcg==", t3: $pubKey) {
transferFromEvent: eventByTopic(t1: "AAAADgAAAAh0cmFuc2Zlcg==", t3: $xdrPubKey) {
edges {
node {
contractId
Expand Down Expand Up @@ -464,13 +464,73 @@ export const query = {
limit
lineNative
poolshareByLinePoolShare {
assetA
assetB
assetByA {
code
}
assetByB {
code
}
fee
}
}
}
changeTrustByPublicKey(publicKeyText: $pubKey) {
edges {
node {
limit
lineAsset
lineNative
linePoolShare
source
sourceMuxed
}
}
}
accountMergeByPublicKey(publicKeyText: $pubKey) {
edges {
node {
destination
destinationMuxed
source
sourceMuxed
}
}
}
bumpSequenceByPublicKey(publicKeyText: $pubKey) {
edges {
node {
source
sourceMuxed
bumpTo
}
}
}
claimClaimableBalanceByPublicKey(publicKeyText: $pubKey) {
edges {
node {
source
sourceMuxed
balanceId
}
}
}
createClaimableBalanceByPublicKey(publicKeyText: $pubKey) {
edges {
node {
amount
asset
assetNative
source
sourceMuxed
}
}
}
}
`,
};

0 comments on commit a8f793d

Please sign in to comment.