Skip to content

Commit 6ebb596

Browse files
committed
feat(1651): code review aligments
Signed-off-by: matevszm <mateusz.marcinkowski@blockydevs.com>
1 parent 8291812 commit 6ebb596

File tree

4 files changed

+60
-9
lines changed

4 files changed

+60
-9
lines changed

docs/output-schemas-guide.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,37 @@ Lists all tokens from all networks stored in state.
541541
}
542542
```
543543

544+
#### `token delete`
545+
546+
**Output** (network delete):
547+
548+
```json
549+
{
550+
"transactionId": "0.0.123@1700000000.123456789",
551+
"deletedToken": {
552+
"name": "MyToken",
553+
"tokenId": "0.0.67890"
554+
},
555+
"network": "testnet",
556+
"removedAliases": ["my-token (testnet)"]
557+
}
558+
```
559+
560+
**Output** (`--state-only`):
561+
562+
```json
563+
{
564+
"deletedToken": {
565+
"name": "MyToken",
566+
"tokenId": "0.0.67890"
567+
},
568+
"network": "testnet",
569+
"removedAliases": ["my-token (testnet)"]
570+
}
571+
```
572+
573+
`transactionId` is absent for `--state-only`. `removedAliases` is omitted when no aliases exist.
574+
544575
### Topic Plugin
545576

546577
#### `topic create`

src/plugins/batch/manifest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export const batchPluginManifest: PluginManifest = {
103103
'token-create-nft-batch-state',
104104
'token-create-nft-from-file-batch-state',
105105
'token-associate-batch-state',
106+
'token-delete-batch-state',
106107
],
107108
options: [
108109
{

src/plugins/token/README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ src/plugins/token/
6161
│ │ ├── output.ts # Output schema and template
6262
│ │ └── index.ts # Command exports
6363
│ ├── delete/
64-
│ │ ├── handler.ts # Token delete handler (local state only)
64+
│ │ ├── handler.ts # Token delete handler (network or local state)
6565
│ │ ├── input.ts # Input schema
6666
│ │ ├── output.ts # Output schema and template
6767
│ │ └── index.ts # Command exports
@@ -353,21 +353,30 @@ hcli token transfer-nft \
353353

354354
### Token Delete
355355

356-
Delete a token from local state. This only removes the token from the local address book, not from the Hedera network.
356+
Delete a token from the Hedera network and remove it from local state. The token must have an admin key to be deleted from the network.
357357

358358
```bash
359-
# Delete by token alias
359+
# Delete by token alias (network delete)
360360
hcli token delete --token mytoken-alias
361361

362-
# Delete by token ID
362+
# Delete by token ID (network delete)
363363
hcli token delete --token 0.0.123456
364+
365+
# Provide admin key explicitly
366+
hcli token delete --token 0.0.123456 --admin-key <key-ref>
367+
368+
# Remove from local state only (no network transaction)
369+
hcli token delete --token mytoken-alias --state-only
364370
```
365371

366372
**Parameters:**
367373

368374
- `--token` / `-T`: Token identifier: either a token alias or token-id - **Required**
375+
- `--admin-key`: Admin key reference for signing (auto-resolved from key manager if omitted) - **Optional**
376+
- `--key-manager`: Key manager type, defaults to config setting - **Optional**
377+
- `--state-only`: Remove token from local state only, without a network transaction - **Optional**
369378

370-
Any aliases associated with the token on the current network will also be removed.
379+
`--state-only` and `--admin-key` are mutually exclusive. Any aliases associated with the token on the current network will also be removed.
371380

372381
### Token List
373382

src/plugins/token/commands/delete/handler.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CommandHandlerArgs, CommandResult } from '@/core';
1+
import type { CommandHandlerArgs, CommandResult, CoreApi } from '@/core';
22
import type { ResolvedPublicKey } from '@/core/services/key-resolver/types';
33
import type {
44
KeyManager,
@@ -62,7 +62,12 @@ export class TokenDeleteCommand extends BaseTransactionCommand<
6262
const tokenState = new ZustandTokenStateHelper(api.state, logger);
6363

6464
const resolvedToken = resolveTokenParameter(validArgs.token, api, network);
65-
const tokenId = resolvedToken!.tokenId;
65+
if (!resolvedToken) {
66+
throw new NotFoundError('Token not found', {
67+
context: { token: validArgs.token },
68+
});
69+
}
70+
const tokenId = resolvedToken.tokenId;
6671
const key = composeKey(network, tokenId);
6772

6873
const tokenInState = tokenState.getToken(key);
@@ -113,7 +118,12 @@ export class TokenDeleteCommand extends BaseTransactionCommand<
113118
const network = api.network.getCurrentNetwork();
114119

115120
const resolvedToken = resolveTokenParameter(validArgs.token, api, network);
116-
const tokenId = resolvedToken!.tokenId;
121+
if (!resolvedToken) {
122+
throw new NotFoundError('Token not found', {
123+
context: { token: validArgs.token },
124+
});
125+
}
126+
const tokenId = resolvedToken.tokenId;
117127

118128
const tokenInfo = await api.mirror.getTokenInfo(tokenId);
119129

@@ -147,7 +157,7 @@ export class TokenDeleteCommand extends BaseTransactionCommand<
147157
}
148158

149159
private async resolveAdminKey(
150-
api: CommandHandlerArgs['api'],
160+
api: CoreApi,
151161
validArgs: TokenDeleteInput,
152162
keyManager: KeyManager,
153163
tokenAdminPublicKey: string,

0 commit comments

Comments
 (0)