Skip to content

Commit

Permalink
feat: allow to switch on direct transaction when the relayer service …
Browse files Browse the repository at this point in the history
…is down (#865)
  • Loading branch information
levalleux-ludo authored Dec 16, 2024
1 parent 6c564eb commit 82ded73
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/core-sdk/src/meta-tx/biconomy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,30 @@ export class Biconomy {
}
return resubmittedResponse;
}

public async check(
args: {
contract?: string;
} = {}
): Promise<boolean> {
const url = `${
this._relayerUrl
}/ready?apiKey=${this._apiKey || ""}&apiId=${this._apiId || ""}&contract=${args.contract || ""}`;
try {
const response = await _fetch(url, {
method: "GET",
headers: {
"content-type": "application/json;charset=UTF-8",
"Access-Control-Allow-Origin": "*"
}
});
if (!response.ok) {
return false;
}
const json = (await response.json()) as { ready: boolean };
return json?.ready || false;
} catch (e) {
return false;
}
}
}
23 changes: 23 additions & 0 deletions packages/core-sdk/src/mixins/base-core-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ErrorFragment
} from "@bosonprotocol/common";
import { TokenInfoManager } from "../utils/tokenInfoManager";
import { Biconomy } from "../meta-tx/biconomy";

export class BaseCoreSDK {
protected _web3Lib: Web3LibAdapter;
Expand Down Expand Up @@ -91,6 +92,28 @@ export class BaseCoreSDK {
contractAddress
};
}

protected async assertAndGetMetaTxConfig2(
overrides: Partial<{
verifierAddress: string;
metaTxConfig: Partial<Omit<MetaTxConfig, "apiIds"> & { apiId: string }>;
metaTransactionMethod: string;
}> = {}
) {
const ret = this.assertAndGetMetaTxConfig(overrides);

// Check the meta-tx gateway is ready and accepts relaying transaction to the targeted contract
const biconomy = new Biconomy(
ret.metaTxRelayerUrl,
ret.metaTxApiKey,
ret.metaTxApiId
);
const ready = await biconomy.check({
contract: ret.contractAddress
});

return ready ? ret : undefined;
}
}

// Doc: https://www.typescriptlang.org/docs/handbook/mixins.html#alternative-pattern
Expand Down

0 comments on commit 82ded73

Please sign in to comment.