Skip to content

Commit

Permalink
feat(context-module): add external plugin loader
Browse files Browse the repository at this point in the history
  • Loading branch information
aussedatlo committed May 14, 2024
1 parent b76691c commit 897203b
Show file tree
Hide file tree
Showing 9 changed files with 656 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export interface DappResponse {
b2c: B2c;
abis: Abis;
b2c_signatures: B2cSignatures;
}

export interface B2c {
blockchainName: string;
chainId: number;
contracts: Contract[];
name: string;
}

interface Contract {
address: string;
contractName: string;
selectors: { [selector: string]: ContractSelector };
}

interface ContractSelector {
erc20OfInterest: string[];
method: string;
plugin: string;
}

interface Abis {
[address: string]: object;
}

export interface B2cSignatures {
[address: string]: {
[selector: string]: B2cSignature;
};
}

interface B2cSignature {
plugin: string;
serialized_data: string;
signature: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { DappInfos } from "../model/DappInfos";

export type GetDappInfos = {
address: string;
selector: `0x${string}`;
chainId: number;
};

export interface ExternalPluginDataSource {
getDappInfos(params: GetDappInfos): Promise<DappInfos | undefined>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import axios from "axios";
import { ExternalPluginDataSource, GetDappInfos } from "./ExternalPluginDataSource";
import { DappResponse } from "./DappResponse";
import { DappInfos } from "../model/DappInfos";
import { SelectorDetails } from "../model/SelectorDetails";

export class HttpExternalPluginDataSource implements ExternalPluginDataSource {
constructor() {}

async getDappInfos({ chainId, address, selector }: GetDappInfos): Promise<DappInfos | undefined> {
const dappInfos = await axios.request<DappResponse[]>({
method: "GET",
url: "https://crypto-assets-service.api.ledger.com/v1/dapps",
params: { output: "b2c,b2c_signatures,abis", chain_id: chainId, contracts: address },
});

const { erc20OfInterest, method, plugin } =
dappInfos.data[0]?.b2c.contracts?.[0]?.selectors?.[selector] || {};
const { signature, serialized_data: serializedData } =
dappInfos.data[0]?.b2c_signatures?.[address]?.[selector] || {};

if (!erc20OfInterest || !method || !plugin || !signature || !serializedData) {
return;
}

const abi = dappInfos.data[0]?.abis?.[address];

if (!abi) {
return;
}

const selectorDetails: SelectorDetails = {
method,
plugin,
erc20OfInterest,
signature,
serializedData,
};

return { selectorDetails, abi: JSON.stringify(abi) };
}
}
Loading

0 comments on commit 897203b

Please sign in to comment.