Skip to content
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

ensures that postTransaction uses a spending account #5092

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ironfish/src/rpc/routes/wallet/postTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import * as yup from 'yup'
import { RawTransactionSerde } from '../../../primitives/rawTransaction'
import { Account } from '../../../wallet'
import { RpcValidationError } from '../../adapters'
import { ApiNamespace } from '../namespaces'
import { routes } from '../router'
Expand Down Expand Up @@ -55,7 +56,9 @@ routes.register<typeof PostTransactionRequestSchema, PostTransactionResponse>(
throw new RpcValidationError('Unable to determine sender account for raw transaction')
}

const account = context.wallet.getAccountByPublicAddress(sender)
const account = context.wallet.findAccount(
(account: Account) => account.publicAddress === sender && account.isSpendingAccount(),
)

if (account === null) {
throw new RpcValidationError(
Expand Down
14 changes: 5 additions & 9 deletions ironfish/src/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1537,22 +1537,18 @@ export class Wallet {
this.defaultAccount = nextId
}

getAccountByName(name: string): Account | null {
findAccount(predicate: (account: Account) => boolean): Account | null {
for (const account of this.accounts.values()) {
if (name === account.name) {
if (predicate(account)) {
return account
}
}

return null
}

getAccountByPublicAddress(publicAddress: string): Account | null {
for (const account of this.accounts.values()) {
if (publicAddress === account.publicAddress) {
return account
}
}
return null
getAccountByName(name: string): Account | null {
return this.findAccount((account) => account.name === name)
}

getAccount(id: string): Account | null {
Expand Down