Skip to content

Commit 54c1446

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

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
@@ -552,6 +552,37 @@ Lists all tokens from all networks stored in state.
552552
}
553553
```
554554

555+
#### `token delete`
556+
557+
**Output** (network delete):
558+
559+
```json
560+
{
561+
"transactionId": "0.0.123@1700000000.123456789",
562+
"deletedToken": {
563+
"name": "MyToken",
564+
"tokenId": "0.0.67890"
565+
},
566+
"network": "testnet",
567+
"removedAliases": ["my-token (testnet)"]
568+
}
569+
```
570+
571+
**Output** (`--state-only`):
572+
573+
```json
574+
{
575+
"deletedToken": {
576+
"name": "MyToken",
577+
"tokenId": "0.0.67890"
578+
},
579+
"network": "testnet",
580+
"removedAliases": ["my-token (testnet)"]
581+
}
582+
```
583+
584+
`transactionId` is absent for `--state-only`. `removedAliases` is omitted when no aliases exist.
585+
555586
#### `token allowance-nft`
556587

557588
**Output** (specific serials):

src/plugins/batch/manifest.ts

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

src/plugins/token/README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ src/plugins/token/
6767
│ │ ├── types.ts # Internal types
6868
│ │ └── index.ts # Command exports
6969
│ ├── delete/
70-
│ │ ├── handler.ts # Token delete handler (local state only)
70+
│ │ ├── handler.ts # Token delete handler (network or local state)
7171
│ │ ├── input.ts # Input schema
7272
│ │ ├── output.ts # Output schema and template
7373
│ │ └── index.ts # Command exports
@@ -520,21 +520,30 @@ hcli token allowance-ft \
520520

521521
### Token Delete
522522

523-
Delete a token from local state. This only removes the token from the local address book, not from the Hedera network.
523+
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.
524524

525525
```bash
526-
# Delete by token alias
526+
# Delete by token alias (network delete)
527527
hcli token delete --token mytoken-alias
528528

529-
# Delete by token ID
529+
# Delete by token ID (network delete)
530530
hcli token delete --token 0.0.123456
531+
532+
# Provide admin key explicitly
533+
hcli token delete --token 0.0.123456 --admin-key <key-ref>
534+
535+
# Remove from local state only (no network transaction)
536+
hcli token delete --token mytoken-alias --state-only
531537
```
532538

533539
**Parameters:**
534540

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

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

539548
### Token List
540549

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)