-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds Create Account flow; Snapshot Download updates #28
Changes from 6 commits
9fcc077
387f72f
491daba
5b3c0db
a616e6e
edbf0f3
6739f24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { AccountFormat } from "@ironfish/sdk"; | ||
|
||
import { manager } from "../manager"; | ||
|
||
export async function handleCreateAccount({ name }: { name: string }) { | ||
const ironfish = await manager.getIronfish(); | ||
const rpcClient = await ironfish.rpcClient(); | ||
|
||
const createResponse = await rpcClient.wallet.createAccount({ | ||
name, | ||
}); | ||
|
||
const exportResponse = await rpcClient.wallet.exportAccount({ | ||
account: createResponse.content.name, | ||
viewOnly: false, | ||
format: AccountFormat.Mnemonic, | ||
}); | ||
|
||
const mnemonic = exportResponse.content.account?.toString(); | ||
|
||
if (!mnemonic) { | ||
throw new Error("Failed to get mnemonic phrase"); | ||
} | ||
|
||
return { | ||
name: createResponse.content.name, | ||
publicAddress: createResponse.content.publicAddress, | ||
mnemonic, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { AccountFormat } from "@ironfish/sdk"; | ||
import * as z from "zod"; | ||
|
||
import { manager } from "../manager"; | ||
|
||
export const handleExportAccountInputs = z.object({ | ||
name: z.string(), | ||
format: z.custom<`${AccountFormat}`>((format) => { | ||
return typeof format === "string" && format in AccountFormat; | ||
}), | ||
viewOnly: z.boolean().optional(), | ||
}); | ||
|
||
export async function handleExportAccount({ | ||
name, | ||
format, | ||
viewOnly = false, | ||
}: z.infer<typeof handleExportAccountInputs>) { | ||
const ironfish = await manager.getIronfish(); | ||
const rpcClient = await ironfish.rpcClient(); | ||
|
||
const exportResponse = await rpcClient.wallet.exportAccount({ | ||
account: name, | ||
format: AccountFormat[format], | ||
viewOnly, | ||
}); | ||
|
||
return exportResponse.content; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as z from "zod"; | ||
|
||
import { manager } from "../manager"; | ||
|
||
export const handleRenameAccountInputs = z.object({ | ||
account: z.string(), | ||
newName: z.string(), | ||
}); | ||
|
||
export async function handleRenameAccount({ | ||
account, | ||
newName, | ||
}: z.infer<typeof handleRenameAccountInputs>) { | ||
const ironfish = await manager.getIronfish(); | ||
const rpcClient = await ironfish.rpcClient(); | ||
|
||
const renameResponse = await rpcClient.wallet.renameAccount({ | ||
account, | ||
newName, | ||
}); | ||
|
||
return renameResponse.content; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import fsAsync from "fs/promises"; | ||
|
||
import { Event, IronfishSdk, Meter, NodeUtils } from "@ironfish/sdk"; | ||
import { Event, FullNode, IronfishSdk, Meter } from "@ironfish/sdk"; | ||
import log from "electron-log"; | ||
|
||
import { | ||
|
@@ -16,15 +16,15 @@ export class SnapshotManager { | |
snapshotPromise: SplitPromise<void> = splitPromise(); | ||
started = false; | ||
|
||
async run(sdk: IronfishSdk): Promise<void> { | ||
async run(sdk: IronfishSdk, node: FullNode): Promise<void> { | ||
if (this.started) { | ||
return; | ||
} | ||
|
||
this.started = true; | ||
|
||
try { | ||
await this._run(sdk); | ||
await this._run(sdk, node); | ||
this.snapshotPromise.resolve(); | ||
} catch (e) { | ||
this.snapshotPromise.reject(e); | ||
|
@@ -35,9 +35,7 @@ export class SnapshotManager { | |
return this.snapshotPromise.promise; | ||
} | ||
|
||
async _run(sdk: IronfishSdk): Promise<void> { | ||
const node = await sdk.node(); | ||
await NodeUtils.waitForOpen(node); | ||
async _run(sdk: IronfishSdk, node: FullNode): Promise<void> { | ||
const nodeChainDBVersion = await node.chain.blockchainDb.getVersion(); | ||
await node.closeDB(); | ||
|
||
|
@@ -112,5 +110,6 @@ export class SnapshotManager { | |
|
||
await downloadedSnapshot.replaceDatabase(); | ||
await fsAsync.rm(downloadedSnapshot.file); | ||
await node.openDB(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking about the pattern we want here for the node. There's 2 steps that require the node database to be open before we start the node: snapshot and getAccounts. In this PR we open the node initially in Personally a process opening its own node and making sure to close down at the end makes a little more sense to me than getting an open node and then making sure it remains open at the end. Wdyt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If each step opened their own node we could remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I might want to refactor Since the DB can only be held by one node at a time, I think the node instance naturally tends towards being a singleton, vs having per-process nodes in e.g. snapshot and getAccounts. As an aside, we end up needing the fullNode promise for shutting down the node (and I think it’s generally worthwhile to hold an explicit handle to the node, since it’s running in the background anyway) TL;DR, I think you're right that each step should make sure the node is in the necessary state, rather than the prior step needing to leave the node in a particular state. But I don't really want to slow this PR down unless it's causing bugs -- I figure I can go refactor it pretty easily if we run into issues at that point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea agreed. Talked about this and I think keeping the fullNode as a singleton on Ironfish makes sense |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the start command so that
init
creates the Ironfish FullNode, so we can query for accounts on startup.Now,
start
just starts the node.