Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion src/lib/nodes/btc-indexer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function normalizeTransaction(
const recipients = tx.vout.map((vout) => vout.scriptpubkey_address)

const direction = senders.includes(ownerAddress) ? 'from' : 'to'
const isSelfTransfer = senders.includes(ownerAddress) && recipients.includes(ownerAddress)

if (direction === 'from') {
// Disregard our address for an outgoing transaction unless it's the only address (i.e. we're sending to ourselves)
Expand All @@ -31,9 +32,10 @@ export function normalizeTransaction(
// Calculate amount from outputs:
// * for the outgoing transactions take outputs that DO NOT target us
// * for the incoming transactions take outputs that DO target us
// * for self-transfers take outputs that DO target us
const amount = tx.vout.reduce(
(sum, t) =>
(direction === 'to') === (t.scriptpubkey_address === ownerAddress)
(isSelfTransfer || direction === 'to') === (t.scriptpubkey_address === ownerAddress)
? sum + Number(t.value)
: sum,
0
Expand Down
4 changes: 3 additions & 1 deletion src/lib/nodes/dash/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function normalizeTransaction(tx: Transaction, ownerAddress: string): Das
const recipients = tx.vout.flatMap((vout) => vout.scriptPubKey.addresses).filter(onlyUnique)

const direction = senders.includes(ownerAddress) ? 'from' : 'to'
const isSelfTransfer = senders.includes(ownerAddress) && recipients.includes(ownerAddress)

if (direction === 'from') {
// Disregard our address for an outgoing transaction unless it's the only address (i.e. we're sending to ourselves)
Expand All @@ -29,9 +30,10 @@ export function normalizeTransaction(tx: Transaction, ownerAddress: string): Das
// Calculate amount from outputs:
// * for the outgoing transactions take outputs that DO NOT target us
// * for the incoming transactions take outputs that DO target us
// * for self-transfers take outputs that DO target us
const amount = tx.vout.reduce(
(sum, t) =>
(direction === 'to') === t.scriptPubKey.addresses.includes(ownerAddress)
(isSelfTransfer || direction === 'to') === t.scriptPubKey.addresses.includes(ownerAddress)
? sum + Number(t.value)
: sum,
0
Expand Down
4 changes: 3 additions & 1 deletion src/lib/nodes/doge-indexer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function normalizeTransaction(tx: Transaction, ownerAddress: string): Dog
const recipients = tx.vout.flatMap((vout) => vout.scriptPubKey.addresses).filter(onlyUnique)

const direction = senders.includes(ownerAddress) ? 'from' : 'to'
const isSelfTransfer = senders.includes(ownerAddress) && recipients.includes(ownerAddress)

if (direction === 'from') {
// Disregard our address for an outgoing transaction unless it's the only address (i.e. we're sending to ourselves)
Expand All @@ -31,9 +32,10 @@ export function normalizeTransaction(tx: Transaction, ownerAddress: string): Dog
// Calculate amount from outputs:
// * for the outgoing transactions take outputs that DO NOT target us
// * for the incoming transactions take outputs that DO target us
// * for self-transfers take outputs that DO target us
const amount = tx.vout.reduce(
(sum, t) =>
(direction === 'to') === t.scriptPubKey.addresses.includes(ownerAddress)
(isSelfTransfer || direction === 'to') === t.scriptPubKey.addresses.includes(ownerAddress)
? sum + Number(t.value)
: sum,
0
Expand Down