@kadena/kadena-cli
Version:
Kadena CLI tool to interact with the Kadena blockchain (manage keys, transactions, etc.)
37 lines • 1.31 kB
JavaScript
import { log } from '../../utils/logger.js';
export class AccountService {
// eslint-disable-next-line @typescript-eslint/parameter-properties, @typescript-eslint/naming-convention
constructor(services) {
this.services = services;
}
async get(filepath) {
return this.services.config.getAccount(filepath);
}
async getByAlias(alias) {
const accounts = await this.services.config.getAccounts();
const match = accounts.filter((account) => account.alias === alias);
if (match.length === 1) {
return match[0];
}
else if (match.length > 1) {
log.warning(`Multiple accounts found with alias "${alias}", it is recommended to use unique aliases`);
return match[0];
}
return null;
}
async create(account) {
const filepath = await this.services.config.setAccount(account, true);
const result = await this.get(filepath);
if (result === null) {
throw new Error(`Account "${filepath}" not found`);
}
return result;
}
async list() {
return this.services.config.getAccounts();
}
async delete(filepath) {
return this.services.config.deleteAccount(filepath);
}
}
//# sourceMappingURL=account.service.js.map