Fix getMultisig implementation
This commit is contained in:
parent
b4dc05e98d
commit
ee2ffbf2e1
@ -1,7 +1,10 @@
|
||||
type Multisig {
|
||||
id: ID!
|
||||
chainId: String!
|
||||
address: String!
|
||||
# The @search annotation allows us to query the list of multisigs and filter
|
||||
# by (chainId, address) pairs. We use "hash" since we only need exact matches.
|
||||
# See https://dgraph.io/docs/graphql/schema/directives/search/#string
|
||||
chainId: String! @search(by: [hash])
|
||||
address: String! @search(by: [hash])
|
||||
pubkeyJSON: String!
|
||||
}
|
||||
|
||||
|
||||
@ -32,27 +32,46 @@ const createMultisig = async (multisig: DbAccount) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets multisig pubkey from faundb
|
||||
* This is the format returned by the graphQL API.
|
||||
*
|
||||
* Keep the format in sync with `GetMultisigAccountResponse` because
|
||||
* we return the full object in the API. Right now address and chainId
|
||||
* are somewhat unnecessary to query but still nice for debgging.
|
||||
*/
|
||||
interface MultisigFromQuery {
|
||||
address: string;
|
||||
chainId: string;
|
||||
pubkeyJSON: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets multisig pubkey from DB
|
||||
*
|
||||
* @param {string} address A multisig address.
|
||||
* @param {string} chainId The chainId the multisig belongs to.
|
||||
* @return Returns async function that makes a request to the dgraph graphql endpoint
|
||||
*/
|
||||
const getMultisig = async (address: string, chainId: string) => {
|
||||
return requestGraphQlJson({
|
||||
async function getMultisig(
|
||||
address: string,
|
||||
chainId: string,
|
||||
): Promise<MultisigFromQuery | undefined> {
|
||||
const result = await requestGraphQlJson({
|
||||
body: {
|
||||
query: `
|
||||
query GetMultisig {
|
||||
getMultisig(chainId: "${chainId}", address: "${address}") {
|
||||
chainId
|
||||
query MultisigsByAddressAndChainId {
|
||||
queryMultisig(filter: {address: {eq: "${address}"}, chainId: {eq: "${chainId}"}}) {
|
||||
address
|
||||
chainId
|
||||
pubkeyJSON
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
});
|
||||
};
|
||||
const elements: [MultisigFromQuery] = result.data.queryMultisig;
|
||||
const first = elements.find(() => true);
|
||||
return first;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates transaction record in dgraph
|
||||
|
||||
@ -8,13 +8,13 @@ export default async function multisigAddressApi(req: NextApiRequest, res: NextA
|
||||
const multisigAddress = req.query.multisigAddress?.toString() || "";
|
||||
const chainId = req.query.chainId?.toString() || "";
|
||||
console.log("Function `getMultisig` invoked", multisigAddress, chainId);
|
||||
const getRes = await getMultisig(multisigAddress, chainId);
|
||||
if (!getRes.data.getMultisig) {
|
||||
const multisig = await getMultisig(multisigAddress, chainId);
|
||||
if (!multisig) {
|
||||
res.status(404).send("Multisig not found");
|
||||
return;
|
||||
}
|
||||
console.log("success", getRes.data.getMultisig);
|
||||
res.status(200).send(getRes.data.getMultisig);
|
||||
console.log("success", multisig);
|
||||
res.status(200).send(multisig);
|
||||
return;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} catch (err: any) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user