-
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): stronger types for account paths
- Loading branch information
Showing
24 changed files
with
180 additions
and
78 deletions.
There are no files selected for viewing
12 changes: 9 additions & 3 deletions
12
packages/app-node/src/backend/accounting/computed/total-owner-balance.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
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
11 changes: 7 additions & 4 deletions
11
packages/app-node/src/backend/accounting/functions/get-ledger-id-from-path.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,9 +1,12 @@ | ||
import assert from "node:assert" | ||
|
||
export const getLedgerIdFromPath = (path: string) => { | ||
const firstSlash = path.indexOf("/") | ||
import { AccountPath } from "../types/accounts" | ||
import { LedgerId } from "../types/ledger-id" | ||
|
||
assert(firstSlash !== -1, "account paths must contain at least one slash") | ||
export const getLedgerIdFromPath = (path: AccountPath): LedgerId => { | ||
const colonPosition = path.indexOf(":") | ||
|
||
return path.slice(0, firstSlash) | ||
assert(colonPosition !== -1, "account paths must contain a colon") | ||
|
||
return path.slice(0, colonPosition) as LedgerId | ||
} |
6 changes: 3 additions & 3 deletions
6
packages/app-node/src/backend/accounting/functions/manage-common-accounts.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,9 +1,9 @@ | ||
import { SettlementSchemeId } from "../../peer-protocol/types/settlement-scheme-id" | ||
import { Ledger } from "../stores/ledger" | ||
import { LedgerId } from "../types/ledger-id" | ||
|
||
export const initializeCommonAccounts = ( | ||
ledger: Ledger, | ||
settlementSchemeId: SettlementSchemeId, | ||
ledgerId: LedgerId, | ||
) => { | ||
ledger.createAccount(`${settlementSchemeId}/internal/connector`) | ||
ledger.createAccount(`${ledgerId}:internal/connector`) | ||
} |
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
11 changes: 8 additions & 3 deletions
11
packages/app-node/src/backend/accounting/functions/process-settlement.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
11 changes: 6 additions & 5 deletions
11
packages/app-node/src/backend/accounting/manage-builtin-accounts.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,15 +1,16 @@ | ||
import { createActor } from "@dassie/lib-reactive" | ||
|
||
import { SettlementSchemeId } from "../peer-protocol/types/settlement-scheme-id" | ||
import { initializeCommonAccounts } from "./functions/manage-common-accounts" | ||
import { OwnerLedgerIdSignal } from "./signals/owner-ledger-id" | ||
import { LedgerStore } from "./stores/ledger" | ||
|
||
export const ManageBuiltinAccountsActor = () => | ||
createActor((sig) => { | ||
const ledger = sig.reactor.use(LedgerStore) | ||
const ledgerId = sig.read(OwnerLedgerIdSignal) | ||
|
||
initializeCommonAccounts(ledger, "builtin" as SettlementSchemeId) | ||
ledger.createAccount(`builtin/owner/spsp`) | ||
ledger.createAccount(`builtin/owner/btp`) | ||
ledger.createAccount(`builtin/owner/http`) | ||
initializeCommonAccounts(ledger, ledgerId) | ||
ledger.createAccount(`${ledgerId}:owner/spsp`) | ||
ledger.createAccount(`${ledgerId}:owner/btp`) | ||
ledger.createAccount(`${ledgerId}:owner/http`) | ||
}) |
16 changes: 16 additions & 0 deletions
16
packages/app-node/src/backend/accounting/signals/owner-ledger-id.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { createSignal } from "@dassie/lib-reactive" | ||
|
||
import { LedgerId } from "../types/ledger-id" | ||
|
||
/** | ||
* Determines which internal ledger the owner accounts are on. | ||
* | ||
* @remarks | ||
* | ||
* Dassie aims for multi-currency support but in this current version, the owner accounts are only on one ledger. This | ||
* signal determines which ledger that is. | ||
* | ||
* Owner accounts are the accounts that are used when the node's owner sends or receives money or connects a client via | ||
* BTP etc. | ||
*/ | ||
export const OwnerLedgerIdSignal = () => createSignal("stub" as LedgerId) |
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
36 changes: 36 additions & 0 deletions
36
packages/app-node/src/backend/accounting/types/accounts.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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { NodeId } from "../../peer-protocol/types/node-id" | ||
import { LedgerId } from "./ledger-id" | ||
|
||
// Ledger Account Structure | ||
// ------------------------ | ||
// | ||
// internal/… -> Own accounts | ||
// internal/connector -> Connector account | ||
// peer/… -> Peer accounts | ||
// peer/<nodeId> -> Accounts for a specific peer | ||
// peer/<nodeId>/interledger -> Interledger packets | ||
// peer/<nodeId>/settlement -> Underlying settlement account | ||
// peer/<nodeId>/trust -> Trust extended or revoked | ||
// owner/… -> Owner accounts | ||
// owner/spsp/<spspAccountId> -> SPSP accounts | ||
// owner/btp/<btpAccountId> -> BTP accounts | ||
// owner/http/<httpAccountId> -> ILP-HTTP accounts | ||
|
||
export type ConnectorAccount = `${LedgerId}:internal/connector` | ||
|
||
export type PeerInterledgerAccount = `${LedgerId}:peer/${NodeId}/interledger` | ||
export type PeerSettlementAccount = `${LedgerId}:peer/${NodeId}/settlement` | ||
export type PeerTrustAccount = `${LedgerId}:peer/${NodeId}/trust` | ||
|
||
export type OwnerSpspAccount = `${LedgerId}:owner/spsp` | ||
export type OwnerBtpAccount = `${LedgerId}:owner/btp` | ||
export type OwnerHttpAccount = `${LedgerId}:owner/http` | ||
|
||
export type AccountPath = | ||
| ConnectorAccount | ||
| PeerInterledgerAccount | ||
| PeerSettlementAccount | ||
| PeerTrustAccount | ||
| OwnerSpspAccount | ||
| OwnerBtpAccount | ||
| OwnerHttpAccount |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { Opaque } from "type-fest" | ||
|
||
export type LedgerId = Opaque<string, "LedgerId"> |
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
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
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
Oops, something went wrong.