Skip to content

Commit 4dda599

Browse files
authored
Upgrade to be on latest version of IF SDK 2.0.0 (#55)
1 parent 9a4ea51 commit 4dda599

File tree

6 files changed

+109
-85
lines changed

6 files changed

+109
-85
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
"oclif:version": "oclif readme && git add README.md"
5656
},
5757
"dependencies": {
58-
"@ironfish/rust-nodejs": "1.13.0",
59-
"@ironfish/sdk": "1.16.0",
58+
"@ironfish/rust-nodejs": "2.0.0",
59+
"@ironfish/sdk": "2.0.0",
6060
"@oclif/core": "1.23.1",
6161
"@oclif/plugin-help": "5.1.12",
6262
"@oclif/plugin-not-found": "2.3.1",
@@ -92,4 +92,4 @@
9292
"url": "https://github.com/iron-fish/ironfish-wallet-cli/issues"
9393
},
9494
"homepage": "https://ironfish.network"
95-
}
95+
}

src/commands/export.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class ExportCommand extends IronfishCommand {
6767
? AccountFormat.Mnemonic
6868
: flags.json
6969
? AccountFormat.JSON
70-
: AccountFormat.Bech32
70+
: AccountFormat.Base64Json
7171

7272
const client = await connectRpcWallet(this.sdk, this.walletConfig, {
7373
connectNodeClient: false,

src/utils/block.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
BlockHashSerdeInstance,
6+
GraffitiSerdeInstance,
7+
NetworkDefinition,
8+
Target,
9+
} from '@ironfish/sdk'
10+
import { RawBlockHeader } from '@ironfish/sdk/build/src/primitives/blockheader'
11+
12+
// TODO: This copies code from BlockHeaderSerde (https://github.com/iron-fish/ironfish/blob/master/ironfish/src/primitives/blockheader.ts)
13+
// Refactor to use the same code once it is exported by the SDK
14+
export function headerDefinitionToHeader(
15+
headerDefinition: NetworkDefinition['genesis']['header'],
16+
): RawBlockHeader {
17+
return {
18+
sequence: Number(headerDefinition.sequence),
19+
previousBlockHash: Buffer.from(
20+
BlockHashSerdeInstance.deserialize(headerDefinition.previousBlockHash),
21+
),
22+
noteCommitment: headerDefinition.noteCommitment,
23+
transactionCommitment: headerDefinition.transactionCommitment,
24+
target: new Target(headerDefinition.target),
25+
randomness: BigInt(headerDefinition.randomness),
26+
timestamp: new Date(headerDefinition.timestamp),
27+
graffiti: Buffer.from(
28+
GraffitiSerdeInstance.deserialize(headerDefinition.graffiti),
29+
),
30+
}
31+
}

src/utils/fees.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import {
77
Assert,
88
CreateTransactionRequest,
99
CurrencyUtils,
10-
ERROR_CODES,
1110
Logger,
1211
RawTransaction,
1312
RawTransactionSerde,
13+
RPC_ERROR_CODES,
1414
RpcClient,
1515
RpcRequestError,
1616
} from '@ironfish/sdk'
@@ -104,7 +104,7 @@ async function getTxWithFee(
104104
const response = await promise.catch((e) => {
105105
if (
106106
e instanceof RpcRequestError &&
107-
e.code === ERROR_CODES.INSUFFICIENT_BALANCE
107+
e.code === RPC_ERROR_CODES.INSUFFICIENT_BALANCE
108108
) {
109109
return null
110110
} else {

src/walletNode.ts

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
Logger,
1818
MetricsMonitor,
1919
Migrator,
20+
Network,
2021
Package,
2122
PromiseUtils,
2223
RpcHttpAdapter,
@@ -28,18 +29,17 @@ import {
2829
RpcTlsAdapter,
2930
RpcTlsClient,
3031
SetTimeoutToken,
31-
Strategy,
32-
TestnetConsensus,
3332
VerifiedAssetsCacheStore,
3433
Wallet,
3534
WalletDB,
3635
} from '@ironfish/sdk'
37-
import { BlockHeaderSerde } from '@ironfish/sdk/build/src/primitives/blockheader'
36+
import { BlockHasher } from '@ironfish/sdk/build/src/blockHasher'
3837
import { RpcIpcClient } from '@ironfish/sdk/build/src/rpc/clients/ipcClient'
3938
import {
4039
calculateWorkers,
4140
WorkerPool,
4241
} from '@ironfish/sdk/build/src/workerPool'
42+
import { headerDefinitionToHeader } from './utils/block'
4343
import { WalletConfig } from './walletConfig'
4444

4545
export enum Database {
@@ -48,7 +48,7 @@ export enum Database {
4848
}
4949

5050
export class WalletNode {
51-
strategy: Strategy
51+
network: Network
5252
config: WalletConfig
5353
internal: InternalStore
5454
wallet: Wallet
@@ -75,7 +75,7 @@ export class WalletNode {
7575
config,
7676
internal,
7777
wallet,
78-
strategy,
78+
network,
7979
metrics,
8080
workerPool,
8181
logger,
@@ -87,7 +87,7 @@ export class WalletNode {
8787
config: WalletConfig
8888
internal: InternalStore
8989
wallet: Wallet
90-
strategy: Strategy
90+
network: Network
9191
metrics: MetricsMonitor
9292
workerPool: WorkerPool
9393
logger: Logger
@@ -98,7 +98,7 @@ export class WalletNode {
9898
this.config = config
9999
this.internal = internal
100100
this.wallet = wallet
101-
this.strategy = strategy
101+
this.network = network
102102
this.metrics = metrics
103103
this.workerPool = workerPool
104104
this.rpc = new RpcServer(this, internal)
@@ -129,7 +129,6 @@ export class WalletNode {
129129
logger = createRootLogger(),
130130
metrics,
131131
files,
132-
strategyClass,
133132
nodeClient,
134133
}: {
135134
pkg: Package
@@ -139,7 +138,6 @@ export class WalletNode {
139138
logger?: Logger
140139
metrics?: MetricsMonitor
141140
files: FileSystem
142-
strategyClass: typeof Strategy | null
143141
nodeClient: RpcSocketClient | null
144142
}): Promise<WalletNode> {
145143
logger = logger.withTag('walletnode')
@@ -179,10 +177,7 @@ export class WalletNode {
179177
files,
180178
)
181179

182-
const consensus = new TestnetConsensus(networkDefinition.consensus)
183-
184-
strategyClass = strategyClass || Strategy
185-
const strategy = new strategyClass({ workerPool, consensus })
180+
const network = new Network(networkDefinition)
186181

187182
const walletDB = new WalletDB({
188183
location: config.walletDatabasePath,
@@ -194,13 +189,13 @@ export class WalletNode {
194189
config,
195190
database: walletDB,
196191
workerPool,
197-
consensus,
192+
consensus: network.consensus,
198193
nodeClient,
199194
})
200195

201196
return new WalletNode({
202197
pkg,
203-
strategy,
198+
network,
204199
files,
205200
config,
206201
internal,
@@ -261,12 +256,6 @@ export class WalletNode {
261256
}
262257

263258
async verifyGenesisBlockHash(): Promise<void> {
264-
const networkDefinition = await getNetworkDefinition(
265-
this.config,
266-
this.internal,
267-
this.files,
268-
)
269-
270259
Assert.isNotNull(this.nodeClient)
271260

272261
const response = await this.nodeClient.chain.getChainInfo()
@@ -275,18 +264,23 @@ export class WalletNode {
275264
response.content.genesisBlockIdentifier.hash,
276265
'hex',
277266
)
278-
const walletGenesisHeader = BlockHeaderSerde.deserialize(
279-
networkDefinition.genesis.header,
280-
this.strategy,
267+
268+
const blockHasher = new BlockHasher({
269+
consensus: this.network.consensus,
270+
})
271+
272+
const rawGenesisHeader = headerDefinitionToHeader(
273+
this.network.genesis.header,
281274
)
275+
const walletGenesisHash = blockHasher.hashHeader(rawGenesisHeader)
282276

283-
if (walletGenesisHeader.hash.equals(nodeGenesisHash)) {
277+
if (walletGenesisHash.equals(nodeGenesisHash)) {
284278
this.logger.info('Verified genesis block hash')
285279
} else {
286280
throw new Error(
287281
`Cannot sync from this node because the node's genesis block hash ${nodeGenesisHash.toString(
288282
'hex',
289-
)} does not match the wallet's genesis block hash ${walletGenesisHeader.hash.toString(
283+
)} does not match the wallet's genesis block hash ${walletGenesisHash.toString(
290284
'hex',
291285
)}`,
292286
)
@@ -471,7 +465,6 @@ Use 'ironfish config:set' to connect to a node via TCP, TLS, or IPC.\n`)
471465
files: options.sdk.fileSystem,
472466
logger: options.sdk.logger,
473467
metrics: options.sdk.metrics,
474-
strategyClass: options.sdk.strategyClass,
475468
dataDir: options.sdk.dataDir,
476469
nodeClient,
477470
})

yarn.lock

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -405,62 +405,62 @@
405405
resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45"
406406
integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==
407407

408-
"@ironfish/rust-nodejs-darwin-arm64@1.13.0":
409-
version "1.13.0"
410-
resolved "https://registry.yarnpkg.com/@ironfish/rust-nodejs-darwin-arm64/-/rust-nodejs-darwin-arm64-1.13.0.tgz#0a0343c05ce669e245115677c64b3a4c1eae3369"
411-
integrity sha512-UCAIPnzgVLqjtk9PaXnqTpu7//vc4YEyG8Mij8I37Qs7l2U8SwQV0bAfi/DulY7TzEOKd2/OGvnLHP93k+JOpA==
412-
413-
"@ironfish/rust-nodejs-darwin-x64@1.13.0":
414-
version "1.13.0"
415-
resolved "https://registry.yarnpkg.com/@ironfish/rust-nodejs-darwin-x64/-/rust-nodejs-darwin-x64-1.13.0.tgz#394e6c5d90c646df0ef94889942bf5d4e29a0691"
416-
integrity sha512-fEN+L3iNUMTj5dgbnuMdDp6cGAwEzcuSeC5n00i/v1IBEbcimcMKWEl94cjZUOYVvYKDUYelvJ5OLZi8Rkat7w==
417-
418-
"@ironfish/rust-nodejs-linux-arm64-gnu@1.13.0":
419-
version "1.13.0"
420-
resolved "https://registry.yarnpkg.com/@ironfish/rust-nodejs-linux-arm64-gnu/-/rust-nodejs-linux-arm64-gnu-1.13.0.tgz#ba21c5cab7cbcafa7810e369602b372c51c242a8"
421-
integrity sha512-GAFV+8c9UdG/c3g38eaNCjOvFMdyYZcWfIuuJiMWIavaOliZxyMqjAFHCdDB4XFGQl6xwfI8nQpZzIiCzrZ5Ng==
422-
423-
"@ironfish/rust-nodejs-linux-arm64-musl@1.13.0":
424-
version "1.13.0"
425-
resolved "https://registry.yarnpkg.com/@ironfish/rust-nodejs-linux-arm64-musl/-/rust-nodejs-linux-arm64-musl-1.13.0.tgz#cb6b8bc302c10ff2f55fc42eac4a637363361543"
426-
integrity sha512-MyBKm1K1/RsfpV0x+jMuBfJmjq8kPCYrzaRhyqkLuWKdeAa8zCBiBe9ntM6DQrcdWq0Z/dGEWCxrE2wiMnW4Ww==
427-
428-
"@ironfish/rust-nodejs-linux-x64-gnu@1.13.0":
429-
version "1.13.0"
430-
resolved "https://registry.yarnpkg.com/@ironfish/rust-nodejs-linux-x64-gnu/-/rust-nodejs-linux-x64-gnu-1.13.0.tgz#dc567aff7e883890015e4473f78e11d094aa7518"
431-
integrity sha512-r5Pyn5KpzRLjyxTg7f7OSjqQXGRxnOG56Jvkcz6lVRCFCiikYqfUnT6T6Qf6Uwm72mrr3cO1AVx2eobB6PKIDQ==
432-
433-
"@ironfish/rust-nodejs-linux-x64-musl@1.13.0":
434-
version "1.13.0"
435-
resolved "https://registry.yarnpkg.com/@ironfish/rust-nodejs-linux-x64-musl/-/rust-nodejs-linux-x64-musl-1.13.0.tgz#b98de9d134ac57ae8a79cd605b429adda90fd533"
436-
integrity sha512-l2zNeQkYBpH85skFZfDrcV/yORMKnYlieND9rU7+8DVkQigZM4kuRNX8spO7MHp0cyzwAML6Npvx3AoC81IyuQ==
437-
438-
"@ironfish/rust-nodejs-win32-x64-msvc@1.13.0":
439-
version "1.13.0"
440-
resolved "https://registry.yarnpkg.com/@ironfish/rust-nodejs-win32-x64-msvc/-/rust-nodejs-win32-x64-msvc-1.13.0.tgz#8d553131a93d6b3952fd3c4ff7ca2e3755cce792"
441-
integrity sha512-2ZLAHBu+HfJ3K4VXexTzcnsykBxfQe70OCE+nRMZuuS4KrM+LAJhfoMcDfJ3WzM/99Lt3wRsQmcFxUyHHm71eA==
442-
443-
"@ironfish/rust-nodejs@1.13.0":
444-
version "1.13.0"
445-
resolved "https://registry.yarnpkg.com/@ironfish/rust-nodejs/-/rust-nodejs-1.13.0.tgz#04bd984347ba249c51795dfd520d2a7217bbff02"
446-
integrity sha512-qjR8+qQwa0C9IxPcDutIyVa8ko5AIY6RM5N2kxU8+OygbP5o6uv/iIHMkntAai6bbbq3BjYFlppP4HdoyOwOvQ==
408+
"@ironfish/rust-nodejs-darwin-arm64@2.0.0":
409+
version "2.0.0"
410+
resolved "https://registry.yarnpkg.com/@ironfish/rust-nodejs-darwin-arm64/-/rust-nodejs-darwin-arm64-2.0.0.tgz#05294f9e01ea1536235b7aff9c7732d78ec224ea"
411+
integrity sha512-ZnR9Aj6h1Og03OAFBJwY0twlzHCmn/+uhHlgl6pCVkpT3YveX4qMSxtMpb879ReN28lSFalbdy5rYOEccfqTbg==
412+
413+
"@ironfish/rust-nodejs-darwin-x64@2.0.0":
414+
version "2.0.0"
415+
resolved "https://registry.yarnpkg.com/@ironfish/rust-nodejs-darwin-x64/-/rust-nodejs-darwin-x64-2.0.0.tgz#bc5a3999fd4906bc547121fa8ce34b453c567c95"
416+
integrity sha512-5ZjUDao1A5V+qsATDA6Qig28Xd5RniuCQe5hDzD0SInXDjPHvOMVcU05FiN9aMI7qKjkjAzji2LO8LZip3Lagg==
417+
418+
"@ironfish/rust-nodejs-linux-arm64-gnu@2.0.0":
419+
version "2.0.0"
420+
resolved "https://registry.yarnpkg.com/@ironfish/rust-nodejs-linux-arm64-gnu/-/rust-nodejs-linux-arm64-gnu-2.0.0.tgz#7675762606796cb46225aa102cbb35575fb02a81"
421+
integrity sha512-INy+5v/XVZFSdKVfzmlnKil3k/T+46883g8gXQ5tV0Dmm123bDOJpXxyQPcokpLnfuB6txRiFfAE9smaGZm6ew==
422+
423+
"@ironfish/rust-nodejs-linux-arm64-musl@2.0.0":
424+
version "2.0.0"
425+
resolved "https://registry.yarnpkg.com/@ironfish/rust-nodejs-linux-arm64-musl/-/rust-nodejs-linux-arm64-musl-2.0.0.tgz#2c72e1b4f272b2de1bb16d3ea8712fcba8ed1969"
426+
integrity sha512-7AGfURdo2gK0EPY256Jur2PXuTGhD5I582z3I53yqeABAtMkxm4Wx5kELiomuTG0ls+TPizurZbEV9pFh8sa8A==
427+
428+
"@ironfish/rust-nodejs-linux-x64-gnu@2.0.0":
429+
version "2.0.0"
430+
resolved "https://registry.yarnpkg.com/@ironfish/rust-nodejs-linux-x64-gnu/-/rust-nodejs-linux-x64-gnu-2.0.0.tgz#59de14299b18a2bfc58ae667a68ca9aa94bcaaec"
431+
integrity sha512-M2RSiVp7/A+omnD55xiWuXFVrIW6E8k/68686S+DsrqKLecfnrzkQqpj9jltNnkLeG88J51X0hG/orfMuuqbzg==
432+
433+
"@ironfish/rust-nodejs-linux-x64-musl@2.0.0":
434+
version "2.0.0"
435+
resolved "https://registry.yarnpkg.com/@ironfish/rust-nodejs-linux-x64-musl/-/rust-nodejs-linux-x64-musl-2.0.0.tgz#9d98a0d7b7757d361b96c6754e0ff2eb87d67fc8"
436+
integrity sha512-nW3Ryx6GMSkLkly20le0s0oaLgDC2Kr1ThRFtgG7YjfnuE15X4QVh6q8DE9izgc1CCY64QwMHeAMJoOyLC+y0w==
437+
438+
"@ironfish/rust-nodejs-win32-x64-msvc@2.0.0":
439+
version "2.0.0"
440+
resolved "https://registry.yarnpkg.com/@ironfish/rust-nodejs-win32-x64-msvc/-/rust-nodejs-win32-x64-msvc-2.0.0.tgz#1bb7369222863d7d3cc524f60c485a6a594061b0"
441+
integrity sha512-fqeqaJnSwpcTh8qaRJ4LM5tLkD1YPi1GS1LmKSgperPfg5EHF546VWX6HZg/wd7kPdwtV53qeqQNnrzStRtPZw==
442+
443+
"@ironfish/rust-nodejs@2.0.0":
444+
version "2.0.0"
445+
resolved "https://registry.yarnpkg.com/@ironfish/rust-nodejs/-/rust-nodejs-2.0.0.tgz#de99f7a2690194f7cfb58061dc16fa1818ff78ca"
446+
integrity sha512-XGdXS8L8R7SdL88sTZFB72CrtS5cn6Crq04ZdvP9wwmV+gEwEAUlRYAB9FPW8qZcjvmdCbVnOPULjKcN3e5vyg==
447447
optionalDependencies:
448-
"@ironfish/rust-nodejs-darwin-arm64" "1.13.0"
449-
"@ironfish/rust-nodejs-darwin-x64" "1.13.0"
450-
"@ironfish/rust-nodejs-linux-arm64-gnu" "1.13.0"
451-
"@ironfish/rust-nodejs-linux-arm64-musl" "1.13.0"
452-
"@ironfish/rust-nodejs-linux-x64-gnu" "1.13.0"
453-
"@ironfish/rust-nodejs-linux-x64-musl" "1.13.0"
454-
"@ironfish/rust-nodejs-win32-x64-msvc" "1.13.0"
455-
456-
"@ironfish/sdk@1.16.0":
457-
version "1.16.0"
458-
resolved "https://registry.yarnpkg.com/@ironfish/sdk/-/sdk-1.16.0.tgz#11e0896780b4db707a6685ffa3d8a01df1c3c9f3"
459-
integrity sha512-uQ3JbSvazCqmYgmLYVYrT8VTxoiirjAWSzG1tGjn+30x5HcHvzolkSY7VaTRK3YFf3zOAROzEyn6UK7uGw2VVw==
448+
"@ironfish/rust-nodejs-darwin-arm64" "2.0.0"
449+
"@ironfish/rust-nodejs-darwin-x64" "2.0.0"
450+
"@ironfish/rust-nodejs-linux-arm64-gnu" "2.0.0"
451+
"@ironfish/rust-nodejs-linux-arm64-musl" "2.0.0"
452+
"@ironfish/rust-nodejs-linux-x64-gnu" "2.0.0"
453+
"@ironfish/rust-nodejs-linux-x64-musl" "2.0.0"
454+
"@ironfish/rust-nodejs-win32-x64-msvc" "2.0.0"
455+
456+
"@ironfish/sdk@2.0.0":
457+
version "2.0.0"
458+
resolved "https://registry.yarnpkg.com/@ironfish/sdk/-/sdk-2.0.0.tgz#b47cd324e4f4df62dd83750f09010b65879c7e74"
459+
integrity sha512-UWl4GeJ+JMW+ocPsw7D3QYF1itCq1A9IeS1hhY42+fgpFFxQkA06sX5XBAjJgiUr0QW+YOLcqC1S2b/vxjciIg==
460460
dependencies:
461461
"@ethersproject/bignumber" "5.7.0"
462462
"@fast-csv/format" "4.3.5"
463-
"@ironfish/rust-nodejs" "1.13.0"
463+
"@ironfish/rust-nodejs" "2.0.0"
464464
"@napi-rs/blake-hash" "1.3.3"
465465
axios "0.21.4"
466466
bech32 "2.0.0"

0 commit comments

Comments
 (0)