Skip to content
Snippets Groups Projects
Commit 03714b74 authored by Mateusz Tyszczak's avatar Mateusz Tyszczak :scroll: Committed by Bartek Wrona
Browse files

Do not create a new chain for each beekeeper provider

parent 3134c551
No related branches found
No related tags found
1 merge request!292Add other signature providers
...@@ -7,9 +7,6 @@ ...@@ -7,9 +7,6 @@
"test": "../../../ts/npm-common-config/scripts/bash/npm-helpers/npm_download_browser_extensions.sh \"${HOME}/preinstalled_browser_extensions\" && ln -sf \"${HOME}/preinstalled_browser_extensions\" ./__tests__/extensions && playwright install chromium && playwright test --max-failures 1", "test": "../../../ts/npm-common-config/scripts/bash/npm-helpers/npm_download_browser_extensions.sh \"${HOME}/preinstalled_browser_extensions\" && ln -sf \"${HOME}/preinstalled_browser_extensions\" ./__tests__/extensions && playwright install chromium && playwright test --max-failures 1",
"test:manual": "rm -rf ./.parcel-cache && parcel test/index.html" "test:manual": "rm -rf ./.parcel-cache && parcel test/index.html"
}, },
"alias": {
"@hiveio/wax": "@hiveio/wax"
},
"dependencies": { "dependencies": {
"@hiveio/beekeeper": "1.27.10-stable.250305202831", "@hiveio/beekeeper": "1.27.10-stable.250305202831",
"@hiveio/wax": "file:../../../ts", "@hiveio/wax": "file:../../../ts",
......
...@@ -10,7 +10,7 @@ import BeekeeperProvider from "@hiveio/wax-signers-beekeeper"; ...@@ -10,7 +10,7 @@ import BeekeeperProvider from "@hiveio/wax-signers-beekeeper";
const chain = await createHiveChain(); const chain = await createHiveChain();
const provider = BeekeeperProvider.for(myWallet, "myaccount", "active"); const provider = BeekeeperProvider.for(myWallet, "myaccount", "active", chain);
// Create a transaction using the Wax Hive chain instance // Create a transaction using the Wax Hive chain instance
const tx = await chain.createTransaction(); const tx = await chain.createTransaction();
......
import { createHiveChain, type IOnlineSignatureProvider, type ITransaction, type TAccountName, type TRole } from "@hiveio/wax"; import type { IHiveChainInterface, IOnlineSignatureProvider, ITransaction, TAccountName, TRole } from "@hiveio/wax";
import type { IBeekeeperUnlockedWallet, TPublicKey } from "@hiveio/beekeeper"; import type { IBeekeeperUnlockedWallet, TPublicKey } from "@hiveio/beekeeper";
...@@ -10,7 +10,7 @@ export class WaxBeekeeperProviderError extends Error {} ...@@ -10,7 +10,7 @@ export class WaxBeekeeperProviderError extends Error {}
* *
* @example * @example
* ``` * ```
* const provider = BeekeeperProvider.for(myWallet, "myaccount", "active"); * const provider = BeekeeperProvider.for(myWallet, "myaccount", "active", chain);
* *
* // Create a transaction using the Wax Hive chain instance * // Create a transaction using the Wax Hive chain instance
* const tx = await chain.createTransaction(); * const tx = await chain.createTransaction();
...@@ -30,19 +30,17 @@ class BeekeeperProvider implements IOnlineSignatureProvider { ...@@ -30,19 +30,17 @@ class BeekeeperProvider implements IOnlineSignatureProvider {
private readonly publicKey: TPublicKey private readonly publicKey: TPublicKey
) {} ) {}
public static for(wallet: IBeekeeperUnlockedWallet, publicKeyOrAccount: TPublicKey | TAccountName, role?: TRole): BeekeeperProvider | Promise<BeekeeperProvider> { public static for(wallet: IBeekeeperUnlockedWallet, publicKeyOrAccount: TPublicKey | TAccountName, role?: TRole, chain?: IHiveChainInterface): BeekeeperProvider | Promise<BeekeeperProvider> {
if (role === undefined) if (role === undefined)
return new BeekeeperProvider(wallet, publicKeyOrAccount); return new BeekeeperProvider(wallet, publicKeyOrAccount);
return createHiveChain().then(chain => { return chain!.api.database_api.find_accounts({ accounts: [publicKeyOrAccount], delayed_votes_active: false }).then(({ accounts: [ account ] }) => {
return chain.api.database_api.find_accounts({ accounts: [publicKeyOrAccount], delayed_votes_active: false }).then(({ accounts: [ account ] }) => { if (account === undefined)
if (account === undefined) return Promise.reject(new WaxBeekeeperProviderError(`Account ${publicKeyOrAccount} not found`));
return Promise.reject(new WaxBeekeeperProviderError(`Account ${publicKeyOrAccount} not found`));
const actualRole = role === "memo" ? "memo_key" : role; const actualRole = role === "memo" ? "memo_key" : role;
return account[actualRole] ? new BeekeeperProvider(wallet, role === "memo" ? account.memo_key : account[role].key_auths[0][0]) : Promise.reject(new WaxBeekeeperProviderError(`Account ${publicKeyOrAccount} does not have ${role} key`)); return account[actualRole] ? new BeekeeperProvider(wallet, role === "memo" ? account.memo_key : account[role].key_auths[0][0]) : Promise.reject(new WaxBeekeeperProviderError(`Account ${publicKeyOrAccount} does not have ${role} key`));
});
}); });
} }
...@@ -53,7 +51,7 @@ class BeekeeperProvider implements IOnlineSignatureProvider { ...@@ -53,7 +51,7 @@ class BeekeeperProvider implements IOnlineSignatureProvider {
export interface WaxBeekeeperProviderCreator { export interface WaxBeekeeperProviderCreator {
for(wallet: IBeekeeperUnlockedWallet, publicKey: TPublicKey): BeekeeperProvider; for(wallet: IBeekeeperUnlockedWallet, publicKey: TPublicKey): BeekeeperProvider;
for(wallet: IBeekeeperUnlockedWallet, account: TAccountName, role: TRole): Promise<BeekeeperProvider>; for(wallet: IBeekeeperUnlockedWallet, account: TAccountName, role: TRole, chain: IHiveChainInterface): Promise<BeekeeperProvider>;
} }
export default BeekeeperProvider as WaxBeekeeperProviderCreator; export default BeekeeperProvider as WaxBeekeeperProviderCreator;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment