Skip to content

Commit aa0869c

Browse files
authored
feat(cli-tools): Internal token-mint command can mint for the authenticated user (#3080)
Improved internal `token-mint` command so that it easier to mint tokens and gas for the authenticated user. Now it is possible to use keyword `self` in place of `targetAddress`. When that is used, the target address is calculated from the provided private key. ## Example ``` streamr internal token-mint self 1234 5678 --private-key ... ``` ## Other changes The permission commands also use special keyword similar like the `self`-keyword introduced in this PR. Unified the cli-tools command help to use the same style in those commands as we now use in the `token-mint` command.
1 parent 9b2cb84 commit aa0869c

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
#!/usr/bin/env node
22
import '../src/logLevel'
33

4-
import { _operatorContractUtils } from '@streamr/sdk'
4+
import StreamrClient, { _operatorContractUtils } from '@streamr/sdk'
55
import { parseEther } from 'ethers'
6-
import { createCommand } from '../src/command'
6+
import { createClientCommand } from '../src/command'
77

8-
createCommand().action(async (targetAddress: string, dataTokenAmount: string, gasAmount?: string) => {
8+
const SELF_TARGET_ADDRESS_ID = 'self'
9+
10+
createClientCommand(async (client: StreamrClient, targetAddress: string, dataTokenAmount: string, gasAmount?: string) => {
11+
if (targetAddress === SELF_TARGET_ADDRESS_ID) {
12+
targetAddress = await client.getUserId()
13+
}
914
const adminWallet = _operatorContractUtils.getTestAdminWallet()
1015
const token = _operatorContractUtils.getTestTokenContract().connect(adminWallet)
1116
await (await token.mint(targetAddress, parseEther(dataTokenAmount))).wait()
@@ -17,5 +22,6 @@ createCommand().action(async (targetAddress: string, dataTokenAmount: string, ga
1722
}
1823
})
1924
.arguments('<targetAddress> <dataTokenAmount> [gasAmount]')
20-
.description('mint test tokens and optionally transfer gas to the given Ethereum address')
25+
.description('mint test tokens and optionally transfer gas to the given Ethereum address' +
26+
'\n\nNote: use keyword "self" as targetAddress to mint for the authenticated user')
2127
.parseAsync()

packages/cli-tools/src/permission.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const runModifyPermissionsCommand = (
4848
.addArgument(new Argument('<streamId>'))
4949
.addArgument(new Argument('<user>'))
5050
.addArgument(new Argument('<permissions...>').choices(Array.from(PERMISSIONS.keys())))
51-
.description(`${modification} permission: use keyword "public" as a user to ${modification} a public permission`)
51+
.description(`${modification} permission` +
52+
`\n\nNote: use keyword "public" as user to ${modification} a public permission`)
5253
.parseAsync(process.argv)
5354
}

0 commit comments

Comments
 (0)