From 8187832271d928ecd71987df3358d0c1175658aa Mon Sep 17 00:00:00 2001 From: aowheel Date: Mon, 30 Sep 2024 21:29:49 +0900 Subject: [PATCH] =?UTF-8?q?cli=E3=81=8B=E3=82=89=E7=99=BB=E9=8C=B2?= =?UTF-8?q?=E3=82=A2=E3=82=AB=E3=82=A6=E3=83=B3=E3=83=88=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4=E3=81=99=E3=82=8B=E6=A9=9F=E8=83=BD=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- pkgs/cli/src/commands/wallet.ts | 13 ++++++++++++- pkgs/cli/src/services/wallet.ts | 12 ++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a00df6f..eb7c1f2 100644 --- a/package.json +++ b/package.json @@ -16,5 +16,6 @@ "frontend": "yarn workspace frontend", "contract": "yarn workspace contract", "cli": "yarn workspace cli" - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/pkgs/cli/src/commands/wallet.ts b/pkgs/cli/src/commands/wallet.ts index 6da93ab..1699e19 100644 --- a/pkgs/cli/src/commands/wallet.ts +++ b/pkgs/cli/src/commands/wallet.ts @@ -1,6 +1,6 @@ import { Command } from "commander"; import { getEthAddress, sendEth } from "../modules/viem"; -import { listProfiles, saveProfile } from "../services/wallet"; +import { listProfiles, saveProfile, deleteProfile } from "../services/wallet"; export const walletCommands = new Command(); @@ -33,6 +33,17 @@ walletCommands saveProfile({ name, privateKey }); }); +/** + * ウォレットを削除 + */ +walletCommands + .command("remove") + .description("remove a wallet") + .requiredOption("--name ", "Wallet name") + .action(({ name }) => { + deleteProfile({ name }); + }); + /** * ETHを送信 */ diff --git a/pkgs/cli/src/services/wallet.ts b/pkgs/cli/src/services/wallet.ts index 537db27..3ed470f 100644 --- a/pkgs/cli/src/services/wallet.ts +++ b/pkgs/cli/src/services/wallet.ts @@ -49,6 +49,18 @@ export const saveProfile = (params: Profile) => { console.log(`Profile ${params.name} with private key has been saved.`); }; +export const deleteProfile = (params: { name: string }) => { + const profiles = getProfiles(); + const index = profiles.findIndex((p) => p.name === params.name); + + if (index === -1) throw "Profile not found."; + + profiles.splice(index, 1); + + writeFileSync(profilesPath, JSON.stringify(profiles, null, 2)); + console.log(`Profile "${params.name}" with private key has been deleted.`); +} + export const listProfiles = () => { const profiles = getProfiles(); for (const profile of profiles) {