Skip to content

Commit

Permalink
fix(ironfish): Use CLI flag option for name (#4903)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanjadvani authored Apr 17, 2024
1 parent 1ec3e61 commit 60beae3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions ironfish/src/rpc/routes/wallet/importAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,14 @@ describe('Route wallet/importAccount', () => {
name: testCaseFile,
})

const name = 'new-account-name'
const response = await routeTest.client.wallet.importAccount({
account: testCase,
name: testCaseFile,
name,
})

expect(response.status).toBe(200)
expect(response.content.name).not.toBeNull()
expect(response.content.name).toEqual(name)
}
})
})
Expand Down
1 change: 1 addition & 0 deletions ironfish/src/rpc/routes/wallet/importAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ routes.register<typeof ImportAccountRequestSchema, ImportResponse>(
accountImport = await tryDecodeAccountWithMultisigSecrets(
context.wallet,
request.data.account,
{ name },
)
}

Expand Down
3 changes: 2 additions & 1 deletion ironfish/src/rpc/routes/wallet/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,13 @@ export async function serializeRpcAccountStatus(
export async function tryDecodeAccountWithMultisigSecrets(
wallet: Wallet,
value: string,
options?: { name?: string },
): Promise<AccountImport | undefined> {
const encoder = new Base64JsonEncoder()

for await (const { name, secret } of wallet.walletDb.getMultisigSecrets()) {
try {
return encoder.decode(value, { name, multisigSecret: secret })
return encoder.decode(value, { name: options?.name ?? name, multisigSecret: secret })
} catch (e: unknown) {
continue
}
Expand Down
3 changes: 1 addition & 2 deletions ironfish/src/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ export class Wallet {

async importAccount(accountValue: AccountImport): Promise<Account> {
let multisigKeys = accountValue.multisigKeys
let name = accountValue.name
const name = accountValue.name

if (
accountValue.multisigKeys &&
Expand All @@ -1539,7 +1539,6 @@ export class Wallet {
throw new Error('Cannot import identity without a corresponding multisig secret')
}

name = multisigSecret.name
multisigKeys = {
keyPackage: accountValue.multisigKeys.keyPackage,
publicKeyPackage: accountValue.multisigKeys.publicKeyPackage,
Expand Down

0 comments on commit 60beae3

Please sign in to comment.