Skip to content

Commit 311abaf

Browse files
authored
Merge pull request #5454 from iron-fish/staging
staging > master
2 parents 3120949 + dd27332 commit 311abaf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2367
-267
lines changed

ironfish-cli/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ironfish",
3-
"version": "2.6.0",
3+
"version": "2.7.0",
44
"description": "CLI for running and interacting with an Iron Fish node",
55
"author": "Iron Fish <[email protected]> (https://ironfish.network)",
66
"main": "build/src/index.js",
@@ -59,8 +59,8 @@
5959
"oclif:version": "oclif readme && git add README.md"
6060
},
6161
"dependencies": {
62-
"@ironfish/rust-nodejs": "2.6.0",
63-
"@ironfish/sdk": "2.6.0",
62+
"@ironfish/rust-nodejs": "2.7.0",
63+
"@ironfish/sdk": "2.7.0",
6464
"@ledgerhq/hw-transport-node-hid": "6.29.1",
6565
"@oclif/core": "4.0.11",
6666
"@oclif/plugin-help": "6.2.5",
@@ -69,6 +69,8 @@
6969
"@types/keccak": "3.0.4",
7070
"@types/tar": "6.1.1",
7171
"@zondax/ledger-ironfish": "0.1.2",
72+
"@zondax/ledger-ironfish-dkg": "npm:@zondax/[email protected]",
73+
"@zondax/ledger-js": "^1.0.1",
7274
"axios": "1.7.2",
7375
"bech32": "2.0.0",
7476
"blessed": "0.1.81",

ironfish-cli/src/commands/wallet/chainport/send.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
44

5-
import { Asset } from '@ironfish/rust-nodejs'
65
import {
76
CreateTransactionRequest,
87
CurrencyUtils,
8+
MAINNET,
99
RawTransaction,
1010
RawTransactionSerde,
1111
RpcAsset,
@@ -84,8 +84,8 @@ export class BridgeCommand extends IronfishCommand {
8484

8585
const networkId = (await client.chain.getNetworkInfo()).content.networkId
8686

87-
if (networkId !== TESTNET.id) {
88-
this.error(`Chainport transactions are only available on testnet.`)
87+
if (networkId !== TESTNET.id && networkId !== MAINNET.id) {
88+
this.error(`Chainport transactions are only available on testnet and mainnet.`)
8989
}
9090

9191
if (!flags.offline) {
@@ -184,38 +184,44 @@ export class BridgeCommand extends IronfishCommand {
184184

185185
const tokens = await fetchChainportVerifiedTokens(networkId)
186186

187-
if (assetId == null) {
187+
const tokenNames = tokens.map(
188+
(t, index) => `${index + 1}. ${t.name} (${t.symbol}) - ${t.web3_address}`,
189+
)
190+
191+
if (!assetId) {
188192
const asset = await ui.assetPrompt(client, from, {
189193
action: 'send',
190194
showNativeAsset: true,
191195
showNonCreatorAsset: true,
192-
showSingleAssetChoice: false,
196+
showSingleAssetChoice: true,
193197
filter: (asset) => {
194198
return tokens.some((t) => t.web3_address === asset.id)
195199
},
196200
})
197201

198-
assetId = asset?.id
199-
200-
if (!assetId) {
201-
assetId = Asset.nativeId().toString('hex')
202+
if (!asset) {
203+
this.logger.error(
204+
`No supported Chainport asset found for this account. Here are the supported tokens: \n\n${tokenNames.join(
205+
'\n',
206+
)}\n`,
207+
)
208+
this.exit(1)
202209
}
210+
211+
assetId = asset.id
203212
}
204213

205214
const asset: ChainportVerifiedToken | undefined = tokens.find(
206215
(t) => t.web3_address === assetId,
207216
)
208217

209218
if (!asset) {
210-
const names = tokens.map(
211-
(t, index) => `${index + 1}. ${t.name} (${t.symbol}) - ${t.web3_address}`,
212-
)
213-
214-
this.error(
215-
`Asset ${assetId} not supported by Chainport. Here are the supported tokens: \n\n${names.join(
219+
this.logger.error(
220+
`Asset ${assetId} not supported by Chainport. Here are the supported tokens: \n\n${tokenNames.join(
216221
'\n',
217222
)}\n`,
218223
)
224+
this.exit(1)
219225
}
220226

221227
const targetNetworks = asset.target_networks

ironfish-cli/src/commands/wallet/decrypt.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { RemoteFlags } from '../../flags'
88
import { inputPrompt } from '../../ui'
99

1010
export class DecryptCommand extends IronfishCommand {
11-
static hidden = true
12-
1311
static description = 'decrypt accounts in the wallet'
1412

1513
static flags = {

ironfish-cli/src/commands/wallet/encrypt.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { RemoteFlags } from '../../flags'
88
import { inputPrompt } from '../../ui'
99

1010
export class EncryptCommand extends IronfishCommand {
11-
static hidden = true
12-
1311
static description = 'encrypt accounts in the wallet'
1412

1513
static flags = {

ironfish-cli/src/commands/wallet/import.ts

Lines changed: 14 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
/* This Source Code Form is subject to the terms of the Mozilla Public
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4-
import {
5-
AccountFormat,
6-
encodeAccountImport,
7-
RPC_ERROR_CODES,
8-
RpcRequestError,
9-
} from '@ironfish/sdk'
4+
import { AccountFormat, encodeAccountImport } from '@ironfish/sdk'
105
import { Args, Flags, ux } from '@oclif/core'
116
import { IronfishCommand } from '../../command'
127
import { RemoteFlags } from '../../flags'
138
import { checkWalletUnlocked, inputPrompt } from '../../ui'
149
import { importFile, importPipe, longPrompt } from '../../ui/longPrompt'
15-
import { Ledger } from '../../utils/ledger'
10+
import { importAccount } from '../../utils'
11+
import { Ledger, LedgerError } from '../../utils/ledger'
1612

1713
export class ImportCommand extends IronfishCommand {
1814
static description = `import an account`
@@ -102,49 +98,15 @@ export class ImportCommand extends IronfishCommand {
10298
flags.name = name
10399
}
104100

105-
let result
106-
107-
while (!result) {
108-
try {
109-
result = await client.wallet.importAccount({
110-
account,
111-
rescan: flags.rescan,
112-
name: flags.name,
113-
createdAt: flags.createdAt,
114-
})
115-
} catch (e) {
116-
if (
117-
e instanceof RpcRequestError &&
118-
(e.code === RPC_ERROR_CODES.DUPLICATE_ACCOUNT_NAME.toString() ||
119-
e.code === RPC_ERROR_CODES.IMPORT_ACCOUNT_NAME_REQUIRED.toString() ||
120-
e.code === RPC_ERROR_CODES.DUPLICATE_IDENTITY_NAME.toString())
121-
) {
122-
const message = 'Enter a name for the account'
123-
124-
if (e.code === RPC_ERROR_CODES.DUPLICATE_ACCOUNT_NAME.toString()) {
125-
this.log()
126-
this.log(e.codeMessage)
127-
}
128-
129-
if (e.code === RPC_ERROR_CODES.DUPLICATE_IDENTITY_NAME.toString()) {
130-
this.log()
131-
this.log(e.codeMessage)
132-
}
133-
134-
const name = await inputPrompt(message, true)
135-
if (name === flags.name) {
136-
this.error(`Entered the same name: '${name}'`)
137-
}
138-
139-
flags.name = name
140-
continue
141-
}
142-
143-
throw e
144-
}
145-
}
101+
const { name, isDefaultAccount } = await importAccount(
102+
client,
103+
account,
104+
this.logger,
105+
flags.name,
106+
flags.createdAt,
107+
flags.rescan,
108+
)
146109

147-
const { name, isDefaultAccount } = result.content
148110
this.log(`Account ${name} imported.`)
149111

150112
if (isDefaultAccount) {
@@ -161,8 +123,9 @@ export class ImportCommand extends IronfishCommand {
161123
const account = await ledger.importAccount()
162124
return encodeAccountImport(account, AccountFormat.Base64Json)
163125
} catch (e) {
164-
if (e instanceof Error) {
165-
this.error(e.message)
126+
if (e instanceof LedgerError) {
127+
this.logger.error(e.message + '\n')
128+
this.exit(1)
166129
} else {
167130
this.error('Unknown error while importing account from ledger device.')
168131
}

ironfish-cli/src/commands/wallet/lock.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { IronfishCommand } from '../../command'
66
import { RemoteFlags } from '../../flags'
77

88
export class LockCommand extends IronfishCommand {
9-
static hidden = true
10-
119
static description = 'lock accounts in the wallet'
1210

1311
static flags = {

ironfish-cli/src/commands/wallet/mint.ts

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { promptCurrency } from '../../utils/currency'
2323
import { promptExpiration } from '../../utils/expiration'
2424
import { getExplorer } from '../../utils/explorer'
2525
import { selectFee } from '../../utils/fees'
26+
import { sendTransactionWithLedger } from '../../utils/ledger'
2627
import { watchTransaction } from '../../utils/transaction'
2728

2829
export class Mint extends IronfishCommand {
@@ -96,12 +97,22 @@ This will create tokens and increase supply for a given asset.`
9697
transferOwnershipTo: Flags.string({
9798
description: 'The public address of the account to transfer ownership of this asset to.',
9899
}),
100+
transferTo: Flags.string({
101+
description: 'transfer all newly minted coins to this public address',
102+
}),
103+
transferToMemo: Flags.string({
104+
description: 'The memo of transfer when using transferTo',
105+
}),
99106
unsignedTransaction: Flags.boolean({
100107
default: false,
101108
description:
102109
'Return a serialized UnsignedTransaction. Use it to create a transaction and build proofs but not post to the network',
103110
exclusive: ['rawTransaction'],
104111
}),
112+
ledger: Flags.boolean({
113+
default: false,
114+
description: 'Mint a transaction using a Ledger device',
115+
}),
105116
}
106117

107118
async start(): Promise<void> {
@@ -140,7 +151,7 @@ This will create tokens and increase supply for a given asset.`
140151
name = await ui.inputPrompt('Enter the name for the new asset', true)
141152
}
142153

143-
if (!metadata) {
154+
if (metadata == null) {
144155
metadata = await ui.inputPrompt('Enter metadata for the new asset')
145156
}
146157

@@ -213,6 +224,12 @@ This will create tokens and increase supply for a given asset.`
213224
}
214225
}
215226

227+
if (flags.transferTo) {
228+
if (!isValidPublicAddress(flags.transferTo)) {
229+
this.error('transferTo must be a valid public address')
230+
}
231+
}
232+
216233
let expiration = flags.expiration
217234
if ((flags.rawTransaction || flags.unsignedTransaction) && expiration === undefined) {
218235
expiration = await promptExpiration({ logger: this.logger, client: client })
@@ -223,25 +240,34 @@ This will create tokens and increase supply for a given asset.`
223240
this.exit(1)
224241
}
225242

243+
const mint = {
244+
// Only provide the asset id if we are not minting an asset for the first time
245+
...(assetData != null ? { assetId } : {}),
246+
name: name,
247+
metadata: metadata,
248+
value: CurrencyUtils.encode(amount),
249+
transferOwnershipTo: flags.transferOwnershipTo,
250+
}
251+
226252
const params: CreateTransactionRequest = {
227253
account,
228254
outputs: [],
229-
mints: [
230-
{
231-
// Only provide the asset id if we are not minting an asset for the first time
232-
...(assetData != null ? { assetId } : {}),
233-
name,
234-
metadata,
235-
value: CurrencyUtils.encode(amount),
236-
transferOwnershipTo: flags.transferOwnershipTo,
237-
},
238-
],
255+
mints: [mint],
239256
fee: flags.fee ? CurrencyUtils.encode(flags.fee) : null,
240257
feeRate: flags.feeRate ? CurrencyUtils.encode(flags.feeRate) : null,
241258
expiration: expiration,
242259
confirmations: flags.confirmations,
243260
}
244261

262+
if (flags.transferTo) {
263+
params.outputs.push({
264+
publicAddress: flags.transferTo,
265+
amount: mint.value,
266+
assetId: assetId,
267+
memo: flags.transferToMemo,
268+
})
269+
}
270+
245271
let raw: RawTransaction
246272
if (params.fee === null && params.feeRate === null) {
247273
raw = await selectFee({
@@ -282,10 +308,23 @@ This will create tokens and increase supply for a given asset.`
282308
name,
283309
metadata,
284310
flags.transferOwnershipTo,
311+
flags.transferTo,
285312
flags.confirm,
286313
assetData,
287314
)
288315

316+
if (flags.ledger) {
317+
await sendTransactionWithLedger(
318+
client,
319+
raw,
320+
account,
321+
flags.watch,
322+
flags.confirm,
323+
this.logger,
324+
)
325+
this.exit(0)
326+
}
327+
289328
ux.action.start('Sending the transaction')
290329

291330
const response = await client.wallet.postTransaction({
@@ -324,6 +363,7 @@ This will create tokens and increase supply for a given asset.`
324363
Value: renderedValue,
325364
Fee: renderedFee,
326365
Hash: transaction.hash().toString('hex'),
366+
'Transfered To': flags.transferTo ? flags.transferTo : undefined,
327367
}),
328368
)
329369

@@ -356,6 +396,7 @@ This will create tokens and increase supply for a given asset.`
356396
name?: string,
357397
metadata?: string,
358398
transferOwnershipTo?: string,
399+
transferTo?: string,
359400
confirm?: boolean,
360401
assetData?: RpcAsset,
361402
): Promise<void> {
@@ -376,6 +417,17 @@ This will create tokens and increase supply for a given asset.`
376417
`Fee: ${renderedFee}`,
377418
]
378419

420+
if (transferTo) {
421+
confirmMessage.push(
422+
`\nAll ${CurrencyUtils.render(
423+
amount,
424+
false,
425+
assetId,
426+
assetData?.verification,
427+
)} of this asset will be transferred to ${transferTo}.`,
428+
)
429+
}
430+
379431
if (transferOwnershipTo) {
380432
confirmMessage.push(
381433
`Ownership of this asset will be transferred to ${transferOwnershipTo}. The current account will no longer have any permission to mint or modify this asset. This cannot be undone.`,

0 commit comments

Comments
 (0)