Skip to content

Commit

Permalink
- add multi resolver function that can handle multiple inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
lennardevertz committed May 29, 2024
1 parent 3e2c717 commit b8a89cc
Show file tree
Hide file tree
Showing 2 changed files with 398 additions and 308 deletions.
50 changes: 50 additions & 0 deletions src/baseIdrissCrypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,56 @@ export abstract class BaseIdrissCrypto {
);
}

public async multiResolve(
inputs: string[],
resolveOptions: ResolveOptions = {},
): Promise<{ [input: string]: { [tagName: string]: string } }> {
const allDigestionPromises = inputs.map(async (input) => {
try {
const identifier = await transformIdentifier(input);
const filteredWalletTags = filterWalletTags(resolveOptions);

return Promise.all(
filteredWalletTags.map(async ({ tagAddress, tagName }) => {
const digested = await this.digestMessage(identifier + tagAddress);
return { digested, tagName, input };
}),
);
} catch (error) {
console.error(`Error processing ${input}`);
return [];
}
});

const allDigestions = (await Promise.all(allDigestionPromises))
.flat()
.filter((v) => v);
const digestedMessages = allDigestions.map((v) => v.digested);

const getMultipleIDrissResponse: Array<[string, string]> =
await this.idrissMultipleRegistryContract.callMethod({
method: { name: 'getMultipleIDriss', args: [digestedMessages] },
});

const results: { [input: string]: { [tagName: string]: string } } = {};

getMultipleIDrissResponse.forEach(([digested, resolvedAddress]) => {
if (!resolvedAddress) return;

const foundResult = allDigestions.find((v) => v.digested === digested);
if (!foundResult)
throw new Error(`Expected digested message: ${digested}`);

if (!results[foundResult.input]) {
results[foundResult.input] = {};
}

results[foundResult.input][foundResult.tagName] = resolvedAddress;
});

return results;
}

public async multitransferToIDriss(
sendParams: SendToAnyoneParams[],
transactionOptions: TransactionOptions = {},
Expand Down
Loading

0 comments on commit b8a89cc

Please sign in to comment.