Skip to content

Commit

Permalink
Revert "staging -> master (#5451)" (#5453)
Browse files Browse the repository at this point in the history
This reverts commit 2091d28.
  • Loading branch information
mat-if authored Sep 27, 2024
1 parent 2091d28 commit 3120949
Show file tree
Hide file tree
Showing 63 changed files with 267 additions and 2,367 deletions.
8 changes: 3 additions & 5 deletions ironfish-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ironfish",
"version": "2.7.0",
"version": "2.6.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.7.0",
"@ironfish/sdk": "2.7.0",
"@ironfish/rust-nodejs": "2.6.0",
"@ironfish/sdk": "2.6.0",
"@ledgerhq/hw-transport-node-hid": "6.29.1",
"@oclif/core": "4.0.11",
"@oclif/plugin-help": "6.2.5",
Expand All @@ -69,8 +69,6 @@
"@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: 15 additions & 21 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 && networkId !== MAINNET.id) {
this.error(`Chainport transactions are only available on testnet and mainnet.`)
if (networkId !== TESTNET.id) {
this.error(`Chainport transactions are only available on testnet.`)
}

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

const tokens = await fetchChainportVerifiedTokens(networkId)

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

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

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

assetId = asset.id
if (!assetId) {
assetId = Asset.nativeId().toString('hex')
}
}

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

if (!asset) {
this.logger.error(
`Asset ${assetId} not supported by Chainport. Here are the supported tokens: \n\n${tokenNames.join(
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(
'\n',
)}\n`,
)
this.exit(1)
}

const targetNetworks = asset.target_networks
Expand Down
2 changes: 2 additions & 0 deletions ironfish-cli/src/commands/wallet/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ 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: 2 additions & 0 deletions ironfish-cli/src/commands/wallet/encrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ 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: 51 additions & 14 deletions ironfish-cli/src/commands/wallet/import.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
/* 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 } from '@ironfish/sdk'
import {
AccountFormat,
encodeAccountImport,
RPC_ERROR_CODES,
RpcRequestError,
} 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 { importAccount } from '../../utils'
import { Ledger, LedgerError } from '../../utils/ledger'
import { Ledger } from '../../utils/ledger'

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

const { name, isDefaultAccount } = await importAccount(
client,
account,
this.logger,
flags.name,
flags.createdAt,
flags.rescan,
)
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 } = result.content
this.log(`Account ${name} imported.`)

if (isDefaultAccount) {
Expand All @@ -123,9 +161,8 @@ export class ImportCommand extends IronfishCommand {
const account = await ledger.importAccount()
return encodeAccountImport(account, AccountFormat.Base64Json)
} catch (e) {
if (e instanceof LedgerError) {
this.logger.error(e.message + '\n')
this.exit(1)
if (e instanceof Error) {
this.error(e.message)
} else {
this.error('Unknown error while importing account from ledger device.')
}
Expand Down
2 changes: 2 additions & 0 deletions ironfish-cli/src/commands/wallet/lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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: 11 additions & 63 deletions ironfish-cli/src/commands/wallet/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ 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 @@ -97,22 +96,12 @@ 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 @@ -151,7 +140,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 == null) {
if (!metadata) {
metadata = await ui.inputPrompt('Enter metadata for the new asset')
}

Expand Down Expand Up @@ -224,12 +213,6 @@ 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 @@ -240,34 +223,25 @@ 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: [mint],
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,
},
],
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 @@ -308,23 +282,10 @@ 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 @@ -363,7 +324,6 @@ 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 @@ -396,7 +356,6 @@ 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 @@ -417,17 +376,6 @@ 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 3120949

Please sign in to comment.