-
Notifications
You must be signed in to change notification settings - Fork 0
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
refactor entropy register so CLI/TUI are similar #242
Changes from 1 commit
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 |
---|---|---|
|
@@ -66,6 +66,7 @@ export class EntropyAccount extends EntropyBase { | |
} | ||
: undefined | ||
|
||
this.logger.debug(`registering with params: ${registerParams}`, 'REGISTER') | ||
return this.entropy.register(registerParams) | ||
// NOTE: if "register" fails for any reason, core currently leaves the chain in a "polluted" | ||
// state. To fix this we manually "prune" the dirty registration transaction. | ||
|
@@ -75,28 +76,6 @@ export class EntropyAccount extends EntropyBase { | |
}) | ||
} | ||
|
||
// WATCH: should this be extracted to interaction.ts? | ||
async registerAccount (account: EntropyAccountConfig, registerParams?: AccountRegisterParams): Promise<EntropyAccountConfig> { | ||
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. All this function is is I have pulled this out into the verbosely named util which
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. it's also the lgger correct? |
||
this.logger.debug( | ||
[ | ||
`registering account: ${account.address}`, | ||
// @ts-expect-error Type export of ChildKey still not available from SDK | ||
`to keyring: ${this.entropy.keyring.getLazyLoadAccountProxy('registration').pair.address}` | ||
].join(', '), | ||
'REGISTER' | ||
) | ||
// Register params to be defined from user input (arguments/options or inquirer prompts) | ||
try { | ||
const verifyingKey = await this.register(registerParams) | ||
// NOTE: this mutation triggers events in Keyring | ||
account.data.registration.verifyingKeys.push(verifyingKey) | ||
return account | ||
} catch (error) { | ||
this.logger.error('There was a problem registering', error) | ||
throw error | ||
} | ||
} | ||
|
||
/* PRIVATE */ | ||
|
||
private async pruneRegistration () { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { ACCOUNTS_CONTENT } from './constants'; | ||
import { EntropyAccountConfig } from "../config/types"; | ||
import * as config from "../config"; | ||
import { ACCOUNTS_CONTENT } from './constants'; | ||
import { generateAccountChoices } from '../common/utils'; | ||
import { generateAccountChoices, findAccountByAddressOrName } from '../common/utils'; | ||
|
||
export async function selectAndPersistNewAccount (newAccount) { | ||
export async function selectAndPersistNewAccount (newAccount: EntropyAccountConfig) { | ||
const storedConfig = await config.get() | ||
const { accounts } = storedConfig | ||
|
||
|
@@ -19,11 +19,22 @@ export async function selectAndPersistNewAccount (newAccount) { | |
accounts.push(newAccount) | ||
await config.set({ | ||
...storedConfig, | ||
accounts, | ||
selectedAccount: newAccount.address | ||
}) | ||
} | ||
|
||
export async function addVerifyingKeyToAccountAndSelect (verifyingKey: string, accountNameOrAddress: string) { | ||
const storedConfig = await config.get() | ||
const account = findAccountByAddressOrName(storedConfig.accounts, accountNameOrAddress) | ||
account.data.registration.verifyingKeys.push(verifyingKey) | ||
|
||
// persist to config, set selectedAccount | ||
await config.set({ | ||
...storedConfig, | ||
selectedAccount: account.address | ||
}) | ||
Comment on lines
+34
to
+37
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. Check my working. We don't need to any of the fancy slicing or inserting
|
||
} | ||
|
||
function validateSeedInput (seed) { | ||
if (seed.includes('#debug')) return true | ||
if (seed.length === 66 && seed.startsWith('0x')) return true | ||
|
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.