Skip to content

Commit 3176b71

Browse files
authored
Add transaction type to accountTransaction (#38)
1 parent c447cad commit 3176b71

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

packages/mobile-app/data/facades/wallet/handlers.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
AccountSettings,
66
Output,
77
Transaction,
8-
TransactionType,
98
WalletHandlers,
109
WalletStatus,
1110
} from "./types";
@@ -215,8 +214,7 @@ export const walletHandlers = f.facade<WalletHandlers>({
215214
burns: [],
216215
mints: [],
217216
spends: [],
218-
// TODO: Implement transaction type
219-
type: TransactionType.RECEIVE,
217+
type: txn.type,
220218
};
221219
},
222220
),
@@ -273,8 +271,7 @@ export const walletHandlers = f.facade<WalletHandlers>({
273271
burns: [],
274272
mints: [],
275273
spends: [],
276-
// TODO: Implement transaction type when accountName is implemented
277-
type: TransactionType.RECEIVE,
274+
type: txn.type,
278275
}));
279276
},
280277
),

packages/mobile-app/data/facades/wallet/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ export type AccountBalance = {
2424
export enum TransactionType {
2525
SEND = "send",
2626
RECEIVE = "receive",
27-
MULTI = "multi",
28-
MINER = "miner",
2927
}
3028

3129
export type AssetBalanceDelta = {

packages/mobile-app/data/wallet/db.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as FileSystem from "expo-file-system";
66
import { AccountFormat, encodeAccount, Note } from "@ironfish/sdk";
77
import { Network } from "../constants";
88
import * as Uint8ArrayUtils from "../../utils/uint8Array";
9+
import { TransactionType } from "../facades/wallet/types";
910
interface AccountsTable {
1011
id: Generated<number>;
1112
name: string;
@@ -34,8 +35,7 @@ interface AccountTransactionsTable {
3435
id: Generated<number>;
3536
accountId: number;
3637
transactionHash: Uint8Array;
37-
// TODO: narrow this further, like Network
38-
transactionType: string;
38+
type: TransactionType;
3939
}
4040

4141
interface TransactionBalanceDeltasTable {
@@ -215,8 +215,8 @@ export class WalletDb {
215215
.addColumn("accountId", SQLiteType.Integer, (col) =>
216216
col.notNull().references("accounts.id"),
217217
)
218-
.addColumn("transactionType", SQLiteType.String, (col) =>
219-
col.notNull(),
218+
.addColumn("type", SQLiteType.String, (col) =>
219+
col.notNull().check(sql`type IN ("receive", "send")`),
220220
)
221221
.execute();
222222
console.log("created account transactions");
@@ -575,6 +575,14 @@ export class WalletDb {
575575
balanceDeltas.add(note.note.assetId(), note.note.value());
576576
}
577577

578+
// Intended to match the logic in ironfish sdk's getTransactionType
579+
const allNotes = [...values.ownerNotes, ...values.spenderNotes];
580+
const transactionType =
581+
values.foundNullifiers.length !== 0 ||
582+
allNotes[0].note.sender() === address
583+
? TransactionType.SEND
584+
: TransactionType.RECEIVE;
585+
578586
await this.db.transaction().execute(async (db) => {
579587
// One transaction could apply to multiple accounts
580588
await db
@@ -594,8 +602,7 @@ export class WalletDb {
594602
.values({
595603
accountId: values.accountId,
596604
transactionHash: values.hash,
597-
// TODO: implement transaction type
598-
transactionType: "receive",
605+
type: transactionType,
599606
})
600607
.executeTakeFirst();
601608

@@ -749,6 +756,7 @@ export class WalletDb {
749756
}
750757

751758
async getUnspentNotes(accountId: number, network: Network) {
759+
// TODO: Consider the confirmation range
752760
return await this.db
753761
.selectFrom("notes")
754762
.leftJoin("nullifiers", "nullifiers.noteId", "notes.id")

packages/mobile-app/data/wallet/wallet.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,8 @@ class Wallet {
500500
const txn = transactionMap.get(hash);
501501
if (txn) {
502502
// TODO: Only decrypt notes that haven't already been decrypted
503+
// If making this change, make sure to update balance delta calculation
504+
// in saveTransaction.
503505
const ownerSet = new Set(
504506
txn.ownerNotes.map((n) =>
505507
Uint8ArrayUtils.toHex(n.note.serialize()),

0 commit comments

Comments
 (0)