@ledgerhq/coin-hedera
Version:
Ledger Hedera Coin integration
36 lines • 964 B
JavaScript
import { Client } from "@hashgraph/sdk";
let _hederaClientPromise = null;
async function broadcastTransaction(transaction) {
return transaction.execute(await getInstance());
}
async function createClient() {
const client = await Client.forMainnetAsync();
client.setMaxNodesPerTransaction(1);
return client;
}
async function getInstance() {
_hederaClientPromise ??= createClient().catch(error => {
_hederaClientPromise = null;
throw error;
});
return _hederaClientPromise;
}
// for testing purposes only, used to reset singleton client instance
async function _resetInstance() {
try {
const client = await _hederaClientPromise;
client?.close();
}
catch {
// intentionally ignored during clean up
}
finally {
_hederaClientPromise = null;
}
}
export const rpcClient = {
getInstance,
broadcastTransaction,
_resetInstance,
};
//# sourceMappingURL=rpc.js.map