Skip to content

Commit 6fb75f4

Browse files
authored
Merge pull request #3563 from iron-fish/staging
STAGING -> MASTER (2/25/23)
2 parents 46295bc + 815b64b commit 6fb75f4

Some content is hidden

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

44 files changed

+1630
-42
lines changed

ironfish-cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ironfish",
3-
"version": "0.1.69",
3+
"version": "0.1.70",
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",
@@ -61,7 +61,7 @@
6161
"@aws-sdk/client-secrets-manager": "3.276.0",
6262
"@aws-sdk/s3-request-presigner": "3.127.0",
6363
"@ironfish/rust-nodejs": "0.1.27",
64-
"@ironfish/sdk": "0.0.46",
64+
"@ironfish/sdk": "0.0.47",
6565
"@oclif/core": "1.23.1",
6666
"@oclif/plugin-help": "5.1.12",
6767
"@oclif/plugin-not-found": "2.3.1",

ironfish-cli/src/commands/service/faucet.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@ export default class Faucet extends IronfishCommand {
149149

150150
const response = await client.getAccountBalance({ account })
151151

152-
if (BigInt(response.content.confirmed) < BigInt(FAUCET_AMOUNT + FAUCET_FEE)) {
152+
if (BigInt(response.content.available) < BigInt(FAUCET_AMOUNT + FAUCET_FEE)) {
153153
if (!this.warnedFund) {
154154
this.log(
155155
`Faucet has insufficient funds. Needs ${FAUCET_AMOUNT + FAUCET_FEE} but has ${
156-
response.content.confirmed
157-
}. Waiting on more funds.`,
156+
response.content.available
157+
} available to spend. Waiting on more funds.`,
158158
)
159159

160160
this.warnedFund = true
@@ -167,7 +167,7 @@ export default class Faucet extends IronfishCommand {
167167
this.warnedFund = false
168168

169169
const maxPossibleRecipients = Math.min(
170-
Number(BigInt(response.content.confirmed) / BigInt(FAUCET_AMOUNT + FAUCET_FEE)),
170+
Number(BigInt(response.content.available) / BigInt(FAUCET_AMOUNT + FAUCET_FEE)),
171171
MAX_RECIPIENTS_PER_TRANSACTION,
172172
)
173173

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ export class BalanceCommand extends IronfishCommand {
6464
this.log(`Account: ${response.content.account}`)
6565
this.log(`Head Hash: ${response.content.blockHash || 'NULL'}`)
6666
this.log(`Head Sequence: ${response.content.sequence || 'NULL'}`)
67+
this.log(
68+
`Available: ${CurrencyUtils.renderIron(response.content.available, true, assetId)}`,
69+
)
6770
this.log(
6871
`Confirmed: ${CurrencyUtils.renderIron(response.content.confirmed, true, assetId)}`,
6972
)
@@ -77,13 +80,20 @@ export class BalanceCommand extends IronfishCommand {
7780
}
7881

7982
this.log(`Account: ${response.content.account}`)
80-
this.log(`Balance: ${CurrencyUtils.renderIron(response.content.confirmed, true, assetId)}`)
83+
this.log(
84+
`Available Balance: ${CurrencyUtils.renderIron(
85+
response.content.available,
86+
true,
87+
assetId,
88+
)}`,
89+
)
8190
}
8291

8392
explainBalance(response: GetBalanceResponse, assetId: string): void {
8493
const unconfirmed = CurrencyUtils.decode(response.unconfirmed)
8594
const confirmed = CurrencyUtils.decode(response.confirmed)
8695
const pending = CurrencyUtils.decode(response.pending)
96+
const available = CurrencyUtils.decode(response.available)
8797

8898
const unconfirmedDelta = unconfirmed - confirmed
8999
const pendingDelta = pending - unconfirmed
@@ -97,7 +107,11 @@ export class BalanceCommand extends IronfishCommand {
97107
)
98108
this.log('')
99109

100-
this.log(`Your confirmed balance is made of notes on the chain that are safe to spend`)
110+
this.log(`Your available balance is made of notes on the chain that are safe to spend`)
111+
this.log(`Available: ${CurrencyUtils.renderIron(available, true, assetId)}`)
112+
this.log('')
113+
114+
this.log('Your confirmed balance includes all notes from transactions on the chain')
101115
this.log(`Confirmed: ${CurrencyUtils.renderIron(confirmed, true, assetId)}`)
102116
this.log('')
103117

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,19 @@ export class BalancesCommand extends IronfishCommand {
5050
assetId: {
5151
header: 'Asset Id',
5252
},
53-
confirmed: {
54-
header: 'Confirmed Balance',
55-
get: (row) => CurrencyUtils.renderIron(row.confirmed),
53+
available: {
54+
header: 'Available Balance',
55+
get: (row) => CurrencyUtils.renderIron(row.available),
5656
},
5757
}
5858

5959
if (flags.all) {
6060
columns = {
6161
...columns,
62+
confirmed: {
63+
header: 'Confirmed Balance',
64+
get: (row) => CurrencyUtils.renderIron(row.confirmed),
65+
},
6266
unconfirmed: {
6367
header: 'Unconfirmed Balance',
6468
get: (row) => CurrencyUtils.renderIron(row.unconfirmed),

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class ImportCommand extends IronfishCommand {
8484
}
8585
}
8686
CliUx.ux.error(
87-
`Detected mnemonic input, but the import failed.
87+
`Detected mnemonic input, but the import failed.
8888
Please verify the input text or use a different method to import wallet`,
8989
)
9090
}
@@ -101,7 +101,16 @@ export class ImportCommand extends IronfishCommand {
101101
// bech32 encoded json
102102
const [decoded, _] = Bech32m.decode(data)
103103
if (decoded) {
104-
return JSONUtils.parse<AccountImport>(decoded)
104+
let data = JSONUtils.parse<AccountImport>(decoded)
105+
106+
if (data.spendingKey) {
107+
data = {
108+
...data,
109+
...generateKeyFromPrivateKey(data.spendingKey),
110+
}
111+
}
112+
113+
return data
105114
}
106115

107116
// mnemonic or explicit spending key
@@ -118,7 +127,16 @@ export class ImportCommand extends IronfishCommand {
118127

119128
// raw json
120129
try {
121-
return JSONUtils.parse<AccountImport>(data)
130+
let json = JSONUtils.parse<AccountImport>(data)
131+
132+
if (json.spendingKey) {
133+
json = {
134+
...json,
135+
...generateKeyFromPrivateKey(json.spendingKey),
136+
}
137+
}
138+
139+
return json
122140
} catch (e) {
123141
CliUx.ux.error(`Import failed for the given input: ${data}`)
124142
}
@@ -127,7 +145,7 @@ export class ImportCommand extends IronfishCommand {
127145
async importFile(path: string): Promise<AccountImport> {
128146
const resolved = this.sdk.fileSystem.resolve(path)
129147
const data = await this.sdk.fileSystem.readFile(resolved)
130-
return this.stringToAccountImport(data)
148+
return this.stringToAccountImport(data.trim())
131149
}
132150

133151
async importPipe(): Promise<AccountImport> {

ironfish-cli/src/utils/asset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export async function selectAsset(
4848
const choices = balances.map((balance) => {
4949
const assetName = BufferUtils.toHuman(Buffer.from(balance.assetName, 'hex'))
5050
const name = `${balance.assetId} (${assetName}) (${CurrencyUtils.renderIron(
51-
balance.confirmed,
51+
balance.available,
5252
)})`
5353

5454
const value = {

ironfish-cli/src/utils/currency.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
44

55
import { Asset } from '@ironfish/rust-nodejs'
6-
import { Assert, CurrencyUtils, RpcClient } from '@ironfish/sdk'
6+
import { CurrencyUtils, RpcClient } from '@ironfish/sdk'
77
import { CliUx } from '@oclif/core'
88

99
export async function promptCurrency(options: {
@@ -37,7 +37,7 @@ export async function promptCurrency(options: {
3737
confirmations: options.balance.confirmations,
3838
})
3939

40-
text += ` (balance ${CurrencyUtils.renderIron(balance.content.confirmed)})`
40+
text += ` (balance ${CurrencyUtils.renderIron(balance.content.available)})`
4141
}
4242

4343
// eslint-disable-next-line no-constant-condition
@@ -50,13 +50,7 @@ export async function promptCurrency(options: {
5050
return null
5151
}
5252

53-
const [amount, error] = CurrencyUtils.decodeTry(input)
54-
55-
if (error) {
56-
throw error
57-
}
58-
59-
Assert.isNotNull(amount)
53+
const amount = CurrencyUtils.decodeIron(input)
6054

6155
if (options.minimum != null && amount < options.minimum) {
6256
continue

ironfish/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ironfish/sdk",
3-
"version": "0.0.46",
3+
"version": "0.0.47",
44
"description": "SDK for running and interacting with an Iron Fish node",
55
"author": "Iron Fish <[email protected]> (https://ironfish.network)",
66
"main": "build/src/index.js",
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4+
5+
import { Logger } from '../../logger'
6+
import { IronfishNode } from '../../node'
7+
import { IDatabase, IDatabaseTransaction } from '../../storage'
8+
import { createDB } from '../../storage/utils'
9+
import { Account } from '../../wallet'
10+
import { Migration } from '../migration'
11+
import { GetStores } from './024-unspent-notes/stores'
12+
13+
export class Migration024 extends Migration {
14+
path = __filename
15+
16+
prepare(node: IronfishNode): IDatabase {
17+
return createDB({ location: node.config.walletDatabasePath })
18+
}
19+
20+
async forward(
21+
node: IronfishNode,
22+
db: IDatabase,
23+
tx: IDatabaseTransaction | undefined,
24+
logger: Logger,
25+
): Promise<void> {
26+
const stores = GetStores(db)
27+
28+
const accounts = []
29+
30+
for await (const accountValue of stores.old.accounts.getAllValuesIter()) {
31+
accounts.push(
32+
new Account({
33+
...accountValue,
34+
walletDb: node.wallet.walletDb,
35+
}),
36+
)
37+
}
38+
39+
logger.info(`Indexing unspent notes for ${accounts.length} accounts`)
40+
41+
for (const account of accounts) {
42+
let unspentNotes = 0
43+
44+
logger.info(` Indexing unspent notes for account ${account.name}`)
45+
for await (const [[, noteHash], note] of stores.old.decryptedNotes.getAllIter(
46+
undefined,
47+
account.prefixRange,
48+
)) {
49+
if (note.sequence === null || note.spent) {
50+
continue
51+
}
52+
53+
await stores.new.unspentNoteHashes.put(
54+
[
55+
account.prefix,
56+
[note.note.assetId(), [note.sequence, [note.note.value(), noteHash]]],
57+
],
58+
null,
59+
)
60+
unspentNotes++
61+
}
62+
63+
logger.info(` Indexed ${unspentNotes} unspent notes for account ${account.name}`)
64+
}
65+
}
66+
67+
async backward(node: IronfishNode, db: IDatabase): Promise<void> {
68+
const stores = GetStores(db)
69+
70+
await stores.new.unspentNoteHashes.clear()
71+
}
72+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4+
import {
5+
BigU64BEEncoding,
6+
BufferEncoding,
7+
IDatabase,
8+
IDatabaseStore,
9+
NULL_ENCODING,
10+
PrefixEncoding,
11+
U32_ENCODING_BE,
12+
} from '../../../../storage'
13+
import { Account } from '../../../../wallet'
14+
15+
export function GetNewStores(db: IDatabase): {
16+
unspentNoteHashes: IDatabaseStore<{
17+
key: [Account['prefix'], [Buffer, [number, [bigint, Buffer]]]]
18+
value: null
19+
}>
20+
} {
21+
const unspentNoteHashes: IDatabaseStore<{
22+
key: [Account['prefix'], [Buffer, [number, [bigint, Buffer]]]]
23+
value: null
24+
}> = db.addStore({
25+
name: 'un',
26+
keyEncoding: new PrefixEncoding(
27+
new BufferEncoding(), // account prefix
28+
new PrefixEncoding(
29+
new BufferEncoding(), // asset ID
30+
new PrefixEncoding(
31+
U32_ENCODING_BE, // sequence
32+
new PrefixEncoding(
33+
new BigU64BEEncoding(), // value
34+
new BufferEncoding(), // note hash
35+
8,
36+
),
37+
4,
38+
),
39+
32,
40+
),
41+
4,
42+
),
43+
valueEncoding: NULL_ENCODING,
44+
})
45+
46+
return { unspentNoteHashes }
47+
}

0 commit comments

Comments
 (0)