From c3e6761f1831e987ad0e2bc92af64a62f2e05a53 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 18 Dec 2024 09:30:00 +0900 Subject: [PATCH] fix: no init before create account --- src/ain.ts | 19 +++++++++++-------- src/ainize.ts | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/ain.ts b/src/ain.ts index f4c8835..1256256 100644 --- a/src/ain.ts +++ b/src/ain.ts @@ -18,20 +18,23 @@ export default class AinModule { return AinModule.instance; } + static createAccount() { + const blockchainAPIEndpoint = getBlockChainAPIEndpoint(0); + const blockchainEventEndpoint = getBlockChainEventEndpoint(0); + const ain = new Ain(blockchainAPIEndpoint, blockchainEventEndpoint, 0); + + const newAccount = ain.wallet.create(1)[0]; + const wallet = ain.wallet.accounts[newAccount]; + + return wallet; + } + initAin(chainId: 0 | 1) { const blockchainAPIEndpoint = getBlockChainAPIEndpoint(chainId); const blockchainEventEndpoint = getBlockChainEventEndpoint(chainId); this.ain = new Ain(blockchainAPIEndpoint, blockchainEventEndpoint, chainId); } - createAccount() { - this.checkAinInitiated(); - const newAccount = this.ain!.wallet.create(1)[0]; - const wallet = this.ain!.wallet.accounts[newAccount]; - this.ain!.wallet.remove(newAccount); - return wallet; - } - setDefaultAccount(privateKey: string) { this.checkAinInitiated(); this.ain!.wallet.addAndSetDefaultAccount(privateKey); diff --git a/src/ainize.ts b/src/ainize.ts index 0dd631e..8c5c926 100644 --- a/src/ainize.ts +++ b/src/ainize.ts @@ -32,7 +32,7 @@ export default class Ainize { * @returns {Account} created account. */ static createAinAccount (): Account { - return AinModule.getInstance().createAccount(); + return AinModule.createAccount(); } /**