-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(node): simplify code for prepare packet accounting
- Loading branch information
Showing
2 changed files
with
42 additions
and
70 deletions.
There are no files selected for viewing
45 changes: 31 additions & 14 deletions
45
packages/app-node/src/backend/accounting/functions/apply-interledger-packet.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,39 @@ | ||
import { IlpPreparePacket } from "../../ilp-connector/schemas/ilp-packet-codec" | ||
import { CreateTransferParameters, Ledger } from "../stores/ledger" | ||
import { CreateTransferParameters } from "../stores/ledger" | ||
import { getLedgerIdFromPath } from "./get-ledger-id-from-path" | ||
|
||
export const applyPacketPrepareToLedger = ( | ||
ledger: Ledger, | ||
accountPath: string, | ||
packet: IlpPreparePacket, | ||
direction: "incoming" | "outgoing", | ||
sourceAccountPath: string, | ||
destinationAccountPath: string, | ||
amount: bigint, | ||
) => { | ||
const ledgerId = getLedgerIdFromPath(accountPath) | ||
const connectorPath = `${ledgerId}/internal/connector` | ||
const transfers = [] | ||
|
||
const transfer: CreateTransferParameters = { | ||
debitAccountPath: direction === "incoming" ? accountPath : connectorPath, | ||
creditAccountPath: direction === "incoming" ? connectorPath : accountPath, | ||
amount: packet.amount, | ||
pending: true, | ||
{ | ||
const ledgerId = getLedgerIdFromPath(sourceAccountPath) | ||
const connectorPath = `${ledgerId}/internal/connector` | ||
|
||
const transfer: CreateTransferParameters = { | ||
debitAccountPath: sourceAccountPath, | ||
creditAccountPath: connectorPath, | ||
amount, | ||
pending: true, | ||
} | ||
|
||
transfers.push(transfer) | ||
} | ||
{ | ||
const ledgerId = getLedgerIdFromPath(destinationAccountPath) | ||
const connectorPath = `${ledgerId}/internal/connector` | ||
|
||
const transfer: CreateTransferParameters = { | ||
debitAccountPath: connectorPath, | ||
creditAccountPath: destinationAccountPath, | ||
amount, | ||
pending: true, | ||
} | ||
|
||
transfers.push(transfer) | ||
} | ||
|
||
return ledger.createTransfer(transfer) | ||
return transfers | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters