Skip to content

Commit

Permalink
Merge pull request #5454 from iron-fish/staging
Browse files Browse the repository at this point in the history
staging > master
  • Loading branch information
mat-if authored Sep 27, 2024
2 parents 3120949 + dd27332 commit 311abaf
Show file tree
Hide file tree
Showing 63 changed files with 2,367 additions and 267 deletions.
8 changes: 5 additions & 3 deletions ironfish-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ironfish",
"version": "2.6.0",
"version": "2.7.0",
"description": "CLI for running and interacting with an Iron Fish node",
"author": "Iron Fish <[email protected]> (https://ironfish.network)",
"main": "build/src/index.js",
Expand Down Expand Up @@ -59,8 +59,8 @@
"oclif:version": "oclif readme && git add README.md"
},
"dependencies": {
"@ironfish/rust-nodejs": "2.6.0",
"@ironfish/sdk": "2.6.0",
"@ironfish/rust-nodejs": "2.7.0",
"@ironfish/sdk": "2.7.0",
"@ledgerhq/hw-transport-node-hid": "6.29.1",
"@oclif/core": "4.0.11",
"@oclif/plugin-help": "6.2.5",
Expand All @@ -69,6 +69,8 @@
"@types/keccak": "3.0.4",
"@types/tar": "6.1.1",
"@zondax/ledger-ironfish": "0.1.2",
"@zondax/ledger-ironfish-dkg": "npm:@zondax/[email protected]",
"@zondax/ledger-js": "^1.0.1",
"axios": "1.7.2",
"bech32": "2.0.0",
"blessed": "0.1.81",
Expand Down
36 changes: 21 additions & 15 deletions ironfish-cli/src/commands/wallet/chainport/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

import { Asset } from '@ironfish/rust-nodejs'
import {
CreateTransactionRequest,
CurrencyUtils,
MAINNET,
RawTransaction,
RawTransactionSerde,
RpcAsset,
Expand Down Expand Up @@ -84,8 +84,8 @@ export class BridgeCommand extends IronfishCommand {

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

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

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

const tokens = await fetchChainportVerifiedTokens(networkId)

if (assetId == null) {
const tokenNames = tokens.map(
(t, index) => `${index + 1}. ${t.name} (${t.symbol}) - ${t.web3_address}`,
)

if (!assetId) {
const asset = await ui.assetPrompt(client, from, {
action: 'send',
showNativeAsset: true,
showNonCreatorAsset: true,
showSingleAssetChoice: false,
showSingleAssetChoice: true,
filter: (asset) => {
return tokens.some((t) => t.web3_address === asset.id)
},
})

assetId = asset?.id

if (!assetId) {
assetId = Asset.nativeId().toString('hex')
if (!asset) {
this.logger.error(
`No supported Chainport asset found for this account. Here are the supported tokens: \n\n${tokenNames.join(
'\n',
)}\n`,
)
this.exit(1)
}

assetId = asset.id
}

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

if (!asset) {
const names = tokens.map(
(t, index) => `${index + 1}. ${t.name} (${t.symbol}) - ${t.web3_address}`,
)

this.error(
`Asset ${assetId} not supported by Chainport. Here are the supported tokens: \n\n${names.join(
this.logger.error(
`Asset ${assetId} not supported by Chainport. Here are the supported tokens: \n\n${tokenNames.join(
'\n',
)}\n`,
)
this.exit(1)
}

const targetNetworks = asset.target_networks
Expand Down
2 changes: 0 additions & 2 deletions ironfish-cli/src/commands/wallet/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { RemoteFlags } from '../../flags'
import { inputPrompt } from '../../ui'

export class DecryptCommand extends IronfishCommand {
static hidden = true

static description = 'decrypt accounts in the wallet'

static flags = {
Expand Down
2 changes: 0 additions & 2 deletions ironfish-cli/src/commands/wallet/encrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { RemoteFlags } from '../../flags'
import { inputPrompt } from '../../ui'

export class EncryptCommand extends IronfishCommand {
static hidden = true

static description = 'encrypt accounts in the wallet'

static flags = {
Expand Down
65 changes: 14 additions & 51 deletions ironfish-cli/src/commands/wallet/import.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import {
AccountFormat,
encodeAccountImport,
RPC_ERROR_CODES,
RpcRequestError,
} from '@ironfish/sdk'
import { AccountFormat, encodeAccountImport } from '@ironfish/sdk'
import { Args, Flags, ux } from '@oclif/core'
import { IronfishCommand } from '../../command'
import { RemoteFlags } from '../../flags'
import { checkWalletUnlocked, inputPrompt } from '../../ui'
import { importFile, importPipe, longPrompt } from '../../ui/longPrompt'
import { Ledger } from '../../utils/ledger'
import { importAccount } from '../../utils'
import { Ledger, LedgerError } from '../../utils/ledger'

export class ImportCommand extends IronfishCommand {
static description = `import an account`
Expand Down Expand Up @@ -102,49 +98,15 @@ export class ImportCommand extends IronfishCommand {
flags.name = name
}

let result

while (!result) {
try {
result = await client.wallet.importAccount({
account,
rescan: flags.rescan,
name: flags.name,
createdAt: flags.createdAt,
})
} catch (e) {
if (
e instanceof RpcRequestError &&
(e.code === RPC_ERROR_CODES.DUPLICATE_ACCOUNT_NAME.toString() ||
e.code === RPC_ERROR_CODES.IMPORT_ACCOUNT_NAME_REQUIRED.toString() ||
e.code === RPC_ERROR_CODES.DUPLICATE_IDENTITY_NAME.toString())
) {
const message = 'Enter a name for the account'

if (e.code === RPC_ERROR_CODES.DUPLICATE_ACCOUNT_NAME.toString()) {
this.log()
this.log(e.codeMessage)
}

if (e.code === RPC_ERROR_CODES.DUPLICATE_IDENTITY_NAME.toString()) {
this.log()
this.log(e.codeMessage)
}

const name = await inputPrompt(message, true)
if (name === flags.name) {
this.error(`Entered the same name: '${name}'`)
}

flags.name = name
continue
}

throw e
}
}
const { name, isDefaultAccount } = await importAccount(
client,
account,
this.logger,
flags.name,
flags.createdAt,
flags.rescan,
)

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

if (isDefaultAccount) {
Expand All @@ -161,8 +123,9 @@ export class ImportCommand extends IronfishCommand {
const account = await ledger.importAccount()
return encodeAccountImport(account, AccountFormat.Base64Json)
} catch (e) {
if (e instanceof Error) {
this.error(e.message)
if (e instanceof LedgerError) {
this.logger.error(e.message + '\n')
this.exit(1)
} else {
this.error('Unknown error while importing account from ledger device.')
}
Expand Down
2 changes: 0 additions & 2 deletions ironfish-cli/src/commands/wallet/lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { IronfishCommand } from '../../command'
import { RemoteFlags } from '../../flags'

export class LockCommand extends IronfishCommand {
static hidden = true

static description = 'lock accounts in the wallet'

static flags = {
Expand Down
74 changes: 63 additions & 11 deletions ironfish-cli/src/commands/wallet/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { promptCurrency } from '../../utils/currency'
import { promptExpiration } from '../../utils/expiration'
import { getExplorer } from '../../utils/explorer'
import { selectFee } from '../../utils/fees'
import { sendTransactionWithLedger } from '../../utils/ledger'
import { watchTransaction } from '../../utils/transaction'

export class Mint extends IronfishCommand {
Expand Down Expand Up @@ -96,12 +97,22 @@ This will create tokens and increase supply for a given asset.`
transferOwnershipTo: Flags.string({
description: 'The public address of the account to transfer ownership of this asset to.',
}),
transferTo: Flags.string({
description: 'transfer all newly minted coins to this public address',
}),
transferToMemo: Flags.string({
description: 'The memo of transfer when using transferTo',
}),
unsignedTransaction: Flags.boolean({
default: false,
description:
'Return a serialized UnsignedTransaction. Use it to create a transaction and build proofs but not post to the network',
exclusive: ['rawTransaction'],
}),
ledger: Flags.boolean({
default: false,
description: 'Mint a transaction using a Ledger device',
}),
}

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

if (!metadata) {
if (metadata == null) {
metadata = await ui.inputPrompt('Enter metadata for the new asset')
}

Expand Down Expand Up @@ -213,6 +224,12 @@ This will create tokens and increase supply for a given asset.`
}
}

if (flags.transferTo) {
if (!isValidPublicAddress(flags.transferTo)) {
this.error('transferTo must be a valid public address')
}
}

let expiration = flags.expiration
if ((flags.rawTransaction || flags.unsignedTransaction) && expiration === undefined) {
expiration = await promptExpiration({ logger: this.logger, client: client })
Expand All @@ -223,25 +240,34 @@ This will create tokens and increase supply for a given asset.`
this.exit(1)
}

const mint = {
// Only provide the asset id if we are not minting an asset for the first time
...(assetData != null ? { assetId } : {}),
name: name,
metadata: metadata,
value: CurrencyUtils.encode(amount),
transferOwnershipTo: flags.transferOwnershipTo,
}

const params: CreateTransactionRequest = {
account,
outputs: [],
mints: [
{
// Only provide the asset id if we are not minting an asset for the first time
...(assetData != null ? { assetId } : {}),
name,
metadata,
value: CurrencyUtils.encode(amount),
transferOwnershipTo: flags.transferOwnershipTo,
},
],
mints: [mint],
fee: flags.fee ? CurrencyUtils.encode(flags.fee) : null,
feeRate: flags.feeRate ? CurrencyUtils.encode(flags.feeRate) : null,
expiration: expiration,
confirmations: flags.confirmations,
}

if (flags.transferTo) {
params.outputs.push({
publicAddress: flags.transferTo,
amount: mint.value,
assetId: assetId,
memo: flags.transferToMemo,
})
}

let raw: RawTransaction
if (params.fee === null && params.feeRate === null) {
raw = await selectFee({
Expand Down Expand Up @@ -282,10 +308,23 @@ This will create tokens and increase supply for a given asset.`
name,
metadata,
flags.transferOwnershipTo,
flags.transferTo,
flags.confirm,
assetData,
)

if (flags.ledger) {
await sendTransactionWithLedger(
client,
raw,
account,
flags.watch,
flags.confirm,
this.logger,
)
this.exit(0)
}

ux.action.start('Sending the transaction')

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

Expand Down Expand Up @@ -356,6 +396,7 @@ This will create tokens and increase supply for a given asset.`
name?: string,
metadata?: string,
transferOwnershipTo?: string,
transferTo?: string,
confirm?: boolean,
assetData?: RpcAsset,
): Promise<void> {
Expand All @@ -376,6 +417,17 @@ This will create tokens and increase supply for a given asset.`
`Fee: ${renderedFee}`,
]

if (transferTo) {
confirmMessage.push(
`\nAll ${CurrencyUtils.render(
amount,
false,
assetId,
assetData?.verification,
)} of this asset will be transferred to ${transferTo}.`,
)
}

if (transferOwnershipTo) {
confirmMessage.push(
`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.`,
Expand Down
Loading

0 comments on commit 311abaf

Please sign in to comment.