|
1 | 1 | #!/usr/bin/env node |
2 | 2 |
|
3 | 3 | import { CCKey } from "codechain-keystore"; |
| 4 | +import { |
| 5 | + AssetTransferAddress, |
| 6 | + PlatformAddress |
| 7 | +} from "codechain-sdk/lib/key/classes"; |
4 | 8 | import * as program from "commander"; |
5 | 9 | import * as fs from "fs"; |
6 | 10 | import * as _ from "lodash"; |
@@ -133,7 +137,7 @@ async function createCommand(args: any[], option: CreateOption) { |
133 | 137 | async function deleteCommand(args: any[], option: DeleteOption) { |
134 | 138 | const cckey = await CCKey.create({ dbPath: option.parent.keysPath }); |
135 | 139 | const accountType = parseAccountType(option.parent.accountType); |
136 | | - const address = parseAddress(option.address); |
| 140 | + const address = parseAddress(accountType, option.address); |
137 | 141 | const networkId = option.parent.networkId; |
138 | 142 | await deleteKey( |
139 | 143 | { |
@@ -181,7 +185,7 @@ async function importRawCommand([privateKey]: any[], option: ImportOption) { |
181 | 185 | async function exportCommand(args: any[], option: ExportOption) { |
182 | 186 | const cckey = await CCKey.create({ dbPath: option.parent.keysPath }); |
183 | 187 | const accountType = parseAccountType(option.parent.accountType); |
184 | | - const address = parseAddress(option.address); |
| 188 | + const address = parseAddress(accountType, option.address); |
185 | 189 | const passphrase = await parsePassphrase(option.passphrase); |
186 | 190 | const networkId = option.parent.networkId; |
187 | 191 | const secret = await exportKey( |
@@ -234,13 +238,23 @@ function parseAccountType(accountType: string): AccountType { |
234 | 238 | return accountType as AccountType; |
235 | 239 | } |
236 | 240 |
|
237 | | -function parseAddress(address: string): string { |
| 241 | +function parseAddress(accountType: AccountType, address: string): string { |
238 | 242 | if (_.isUndefined(address)) { |
239 | 243 | throw new CLIError(CLIErrorType.OptionRequired, { |
240 | 244 | optionName: "address" |
241 | 245 | }); |
242 | 246 | } |
243 | | - // FIXME: Validate the address. |
| 247 | + try { |
| 248 | + if (accountType === "platform") { |
| 249 | + PlatformAddress.fromString(address); |
| 250 | + } else { |
| 251 | + AssetTransferAddress.fromString(address); |
| 252 | + } |
| 253 | + } catch (err) { |
| 254 | + throw new CLIError(CLIErrorType.InvalidAddress, { |
| 255 | + message: err.message |
| 256 | + }); |
| 257 | + } |
244 | 258 | return address; |
245 | 259 | } |
246 | 260 |
|
|
0 commit comments