Skip to content

Commit

Permalink
Merge pull request #2488 from iron-fish/staging
Browse files Browse the repository at this point in the history
STAGING -> MASTER
  • Loading branch information
NullSoldier authored Nov 1, 2022
2 parents 02939ae + 7ed71e7 commit 67da183
Show file tree
Hide file tree
Showing 48 changed files with 1,251 additions and 610 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ See https://ironfish.network

The following steps should only be used to install if you are planning on contributing to the Iron Fish codebase. Otherwise, we **strongly** recommend using the installation methods here: https://ironfish.network/docs/onboarding/installation-iron-fish

1. Install [Node.js 16.x](https://nodejs.org/en/download/)
1. Install [Node.js 16.x](https://nodejs.org/download/release/latest-v16.x/)
1. Install [Rust](https://www.rust-lang.org/learn/get-started).
1. Install [Yarn](https://classic.yarnpkg.com/en/docs/install).
1. Windows:
1. Install [Build Tools for Visual Studio 2019](https://docs.microsoft.com/en-us/visualstudio/releases/2019/history#release-dates-and-build-numbers), including the C++ Build Tools and the Windows 10 SDK, for Rust.
1. Rust builds also require installing [MinGW-w64 via win-builds](http://win-builds.org/doku.php/download_and_installation_from_windows).
1. Choose `Native Windows`, `x86_64`, choose an empty directory, and click OK.
1. On the next screen, click `Process`.
1. Once it finishes, add the `bin` folder containing `cc` to your PATH environment variable.
1. Install the current version of Python from the [Microsoft Store package](https://www.microsoft.com/en-us/p/python-310/9pjpw5ldxlz5).
1. Install Visual C++ Build Environment: [Visual Studio Build Tools](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools)
(using "Visual C++ build tools" or "Desktop development with C++" workload)

If the above steps didn't work for you, please visit [Microsoft's Node.js Guidelines for Windows](https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#compiling-native-addon-modules) for additional tips.

1. Run `yarn install` from the root directory to install packages.

- If `yarn install` fails with an error that includes "Failed to build cmake", you may need to first install cmake. For example, on macOS:
Expand Down
6 changes: 3 additions & 3 deletions ironfish-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ironfish",
"version": "0.1.50",
"version": "0.1.51",
"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 @@ -55,8 +55,8 @@
},
"dependencies": {
"@aws-sdk/client-s3": "3.127.0",
"@ironfish/rust-nodejs": "0.1.15",
"@ironfish/sdk": "0.0.27",
"@ironfish/rust-nodejs": "0.1.16",
"@ironfish/sdk": "0.0.28",
"@oclif/core": "1.16.1",
"@oclif/plugin-help": "5.1.12",
"@oclif/plugin-not-found": "2.3.1",
Expand Down
99 changes: 62 additions & 37 deletions ironfish-cli/src/commands/accounts/pay.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* 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 { CurrencyUtils, isValidPublicAddress } from '@ironfish/sdk'
import { CliUx, Flags } from '@oclif/core'
import { IronfishCommand } from '../../command'
Expand Down Expand Up @@ -48,6 +47,12 @@ export class Pay extends IronfishCommand {
description:
'The block sequence after which the transaction will be removed from the mempool. Set to 0 for no expiration.',
}),
priority: Flags.string({
default: 'medium',
char: 'p',
description: 'The priority level for transaction fee estimation.',
options: ['low', 'medium', 'high'],
}),
}

async start(): Promise<void> {
Expand Down Expand Up @@ -103,33 +108,18 @@ export class Pay extends IronfishCommand {
fee = CurrencyUtils.decodeIron(flags.fee)
}

if (fee == null) {
let dynamicFee: bigint | null
try {
const response = await client.getFees({ numOfBlocks: 100 })
dynamicFee = CurrencyUtils.decode(response.content.p25)
} catch {
dynamicFee = null
}

const input = (await CliUx.ux.prompt(
`Enter the fee amount in $IRON (min: ${CurrencyUtils.renderIron(1n)}${
dynamicFee ? `, recommended: ${dynamicFee}` : ''
})`,
{
required: true,
},
)) as string
if (!from) {
const response = await client.getDefaultAccount()
const defaultAccount = response.content.account

if (!CurrencyUtils.isValidIron(input)) {
this.error(`A valid amount is required`)
if (!defaultAccount) {
this.error(
`No account is currently active.
Use ironfish accounts:create <name> to first create an account`,
)
}

fee = CurrencyUtils.decodeIron(input)
}

if (fee < 1n) {
this.error(`The minimum fee is ${CurrencyUtils.renderOre(1n, true)}`)
from = defaultAccount.name
}

if (!to) {
Expand All @@ -142,23 +132,58 @@ export class Pay extends IronfishCommand {
}
}

if (!from) {
const response = await client.getDefaultAccount()
const defaultAccount = response.content.account
if (!isValidPublicAddress(to)) {
this.log(`A valid public address is required`)
this.exit(1)
}

if (!defaultAccount) {
this.error(
`No account is currently active.
Use ironfish accounts:create <name> to first create an account`,
)
if (fee == null) {
let suggestedFee = ''
try {
const response = await client.estimateFee({
fromAccountName: from,
receives: [
{
publicAddress: to,
amount: CurrencyUtils.encode(amount),
memo: memo,
},
],
})

switch (flags.priority) {
case 'low':
suggestedFee = CurrencyUtils.renderIron(response.content.low)
break
case 'high':
suggestedFee = CurrencyUtils.renderIron(response.content.high)
break
default:
suggestedFee = CurrencyUtils.renderIron(response.content.medium)
}
} catch {
suggestedFee = ''
}

from = defaultAccount.name
const input = (await CliUx.ux.prompt(
`Enter the fee amount in $IRON (min: ${CurrencyUtils.renderIron(
1n,
)} recommended: ${suggestedFee})`,
{
required: true,
default: suggestedFee,
},
)) as string

if (!CurrencyUtils.isValidIron(input)) {
this.error(`A valid amount is required`)
}

fee = CurrencyUtils.decodeIron(input)
}

if (!isValidPublicAddress(to)) {
this.log(`A valid public address is required`)
this.exit(1)
if (fee < 1n) {
this.error(`The minimum fee is ${CurrencyUtils.renderOre(1n, true)}`)
}

if (expirationSequence !== undefined && expirationSequence < 0) {
Expand Down
60 changes: 36 additions & 24 deletions ironfish-cli/src/commands/deposit-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,6 @@ export default class DepositAll extends IronfishCommand {
this.client = await this.sdk.connectRpc(false, true)
this.api = new WebApi()

let fee = null

if (flags.fee) {
const [parsedFee] = BigIntUtils.tryParse(flags.fee)

if (parsedFee != null) {
fee = parsedFee
}
}

if (fee == null) {
try {
// fees p25 of last 100 blocks
const feeString = (await this.client.getFees({ numOfBlocks: 100 })).content.p25
fee = CurrencyUtils.decode(feeString)
} catch {
fee = 1n
}
}

const terminate = flags.terminate
const expirationSequenceDelta = flags.expirationSequenceDelta

Expand Down Expand Up @@ -114,11 +94,26 @@ export default class DepositAll extends IronfishCommand {
Assert.isNotNull(this.client)
Assert.isNotNull(this.api)

let fee = null

if (flags.fee) {
const [parsedFee] = BigIntUtils.tryParse(flags.fee)

if (parsedFee == null) {
this.log(`Error reading the fee value, please enter a valid number.`)
this.exit(0)
} else if (parsedFee <= 0n) {
this.log(`The minimum fee is ${CurrencyUtils.renderIron(1n, true)}`)
this.exit(0)
}

fee = parsedFee
}

const { canSend, errorReason } = await verifyCanSend(
this.client,
this.api,
expirationSequenceDelta,
fee,
graffiti,
)
if (!canSend) {
Expand All @@ -128,10 +123,8 @@ export default class DepositAll extends IronfishCommand {
}

if (!flags.confirm) {
const displayFee = CurrencyUtils.renderIron(fee, true)

this.log(
`You are about to deposit all your $IRON to the Iron Fish deposit account. Each transaction will use a fee of ${displayFee}. The memos will contain the graffiti "${graffiti}".`,
`You are about to deposit all your $IRON to the Iron Fish deposit account. Each transaction will use an estimate fee based on recent transactions. The memos will contain the graffiti "${graffiti}".`,
)

const confirm = await CliUx.ux.confirm('Do you confirm (Y/N)?')
Expand Down Expand Up @@ -208,6 +201,25 @@ export default class DepositAll extends IronfishCommand {
confirmedBalance = CurrencyUtils.decode(balanceResp.content.confirmed)
unconfirmedBalance = CurrencyUtils.decode(balanceResp.content.unconfirmed)
pendingBalance = CurrencyUtils.decode(balanceResp.content.pending)

if (flags.fee === undefined || fee == null) {
try {
const response = await this.client.estimateFee({
fromAccountName: accountName,
receives: [
{
publicAddress: bankDepositAddress,
amount: CurrencyUtils.encode(confirmedBalance),
memo: graffiti,
},
],
})
fee = CurrencyUtils.decode(response.content.medium)
} catch {
fee = 1n
}
}

// putting this inside of loop to protect against future config changes to allowable size
const { minDepositSize, maxDepositSize } = await this.api.getMinAndMaxDepositSize()
const minDepositOre = CurrencyUtils.decodeIron(minDepositSize)
Expand Down
61 changes: 37 additions & 24 deletions ironfish-cli/src/commands/deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,6 @@ export default class Bank extends IronfishCommand {
this.client = await this.sdk.connectRpc(false, true)
this.api = new WebApi()

let fee = null

if (flags.fee) {
const [parsedFee] = BigIntUtils.tryParse(flags.fee)

if (parsedFee != null) {
fee = parsedFee
}
}

if (fee == null) {
try {
// fees p25 of last 100 blocks
const feeString = (await this.client.getFees({ numOfBlocks: 100 })).content.p25
fee = CurrencyUtils.decode(feeString)
} catch {
fee = 1n
}
}

const expirationSequenceDelta = flags.expirationSequenceDelta

const accountName =
Expand Down Expand Up @@ -108,11 +88,47 @@ export default class Bank extends IronfishCommand {
Assert.isNotNull(this.client)
Assert.isNotNull(this.api)

let fee = null

if (flags.fee) {
const [parsedFee] = BigIntUtils.tryParse(flags.fee)

if (parsedFee == null) {
this.log(`Error reading the fee value, please enter a valid number.`)
this.exit(0)
} else if (parsedFee <= 0n) {
this.log(`The minimum fee is ${CurrencyUtils.renderIron(1n, true)}`)
this.exit(0)
}

fee = parsedFee
}

const balanceResp = await this.client.getAccountBalance({ account: accountName })
const confirmedBalance = BigInt(balanceResp.content.confirmed)

if (fee == null) {
try {
const response = await this.client.estimateFee({
fromAccountName: accountName,
receives: [
{
publicAddress: bankDepositAddress,
amount: CurrencyUtils.encode(confirmedBalance),
memo: graffiti,
},
],
})
fee = CurrencyUtils.decode(response.content.medium)
} catch {
fee = 1n
}
}

const { canSend, errorReason } = await verifyCanSend(
this.client,
this.api,
expirationSequenceDelta,
fee,
graffiti,
)
if (!canSend) {
Expand All @@ -121,9 +137,6 @@ export default class Bank extends IronfishCommand {
this.exit(1)
}

const balanceResp = await this.client.getAccountBalance({ account: accountName })
const confirmedBalance = BigInt(balanceResp.content.confirmed)

if (confirmedBalance < fee + minDepositOre) {
this.log(
`Insufficient balance: ${CurrencyUtils.renderIron(
Expand Down
Loading

0 comments on commit 67da183

Please sign in to comment.