Skip to content

Commit

Permalink
Update Bundlr initialization logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lorisleiva committed May 2, 2022
1 parent 9c893f2 commit de23852
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/drivers/storage/BundlrStorageDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,22 @@ export class BundlrStorageDriver extends StorageDriver {
};

const identity = this.metaplex.identity();
const bundlr =
identity instanceof KeypairIdentityDriver
? new NodeBundlr(address, currency, identity.keypair.secretKey, options)
: new WebBundlr(address, currency, identity, options);

// Try to initiate bundlr.
let bundlr: WebBundlr | NodeBundlr;
try {
// Check for valid bundlr node.
await bundlr.utils.getBundlerAddress(currency);
bundlr = await (identity instanceof KeypairIdentityDriver
? NodeBundlr.init(address, currency, identity.keypair.secretKey, options)
: WebBundlr.init(address, currency, identity, options));
} catch (error) {
throw new FailedToConnectToBundlrAddressError(address, error as Error);
throw new FailedToInitializeBundlrError(error as Error);
}

if (bundlr instanceof WebBundlr) {
try {
// Try to initiate bundlr.
await bundlr.ready();
} catch (error) {
throw new FailedToInitializeBundlrError(error as Error);
}
try {
// Check the provided Bundlr address is reachable.
await bundlr.utils.getBundlerAddress(currency);
} catch (error) {
throw new FailedToConnectToBundlrAddressError(address, error as Error);
}

this.bundlr = bundlr;
Expand Down

0 comments on commit de23852

Please sign in to comment.