Skip to content

Commit

Permalink
feat(2712): introduce BasicAccountingService.
Browse files Browse the repository at this point in the history
  • Loading branch information
koekiebox committed May 22, 2024
1 parent d64f57a commit 1005c26
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 65 deletions.
7 changes: 5 additions & 2 deletions packages/backend/src/accounting/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ export interface Transaction {
void: () => Promise<void | TransferError>
}

export interface AccountingService {
export interface BasicAccountingService {
createTransfer(options: TransferOptions): Promise<Transaction | TransferError>
createLiquidityAccount(
account: LiquidityAccount,
accountType: LiquidityAccountType,
trx?: TransactionOrKnex
): Promise<LiquidityAccount>
}

export interface AccountingService extends BasicAccountingService {
createSettlementAccount(
ledger: number,
trx?: TransactionOrKnex
Expand All @@ -73,7 +77,6 @@ export interface AccountingService {
getTotalReceived(id: string): Promise<bigint | undefined>
getAccountsTotalReceived(ids: string[]): Promise<(bigint | undefined)[]>
getSettlementBalance(ledger: number): Promise<bigint | undefined>
createTransfer(options: TransferOptions): Promise<Transaction | TransferError>
createDeposit(
deposit: Deposit,
trx?: TransactionOrKnex
Expand Down
13 changes: 3 additions & 10 deletions packages/backend/src/payment-method/ilp/connector/core/rafiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,9 @@ import { Errors } from 'ilp-packet'
import { Redis } from 'ioredis'
import Koa, { Middleware } from 'koa'
import { Logger } from 'pino'
//import { Router } from './services/router'
import {
CreateAccountError,
TransferError
} from '../../../../accounting/errors'
import {
LiquidityAccount,
AccountingService,
LiquidityAccountType,
Transaction
BasicAccountingService
} from '../../../../accounting/service'
import { AssetOptions } from '../../../../asset/service'
import { IncomingPaymentService } from '../../../../open_payments/payment/incoming/service'
Expand Down Expand Up @@ -64,7 +57,7 @@ export interface TransferOptions {

export interface RafikiServices {
//router: Router
accounting: AccountingService
accounting: BasicAccountingService
telemetry?: TelemetryService
walletAddresses: WalletAddressService
logger: Logger
Expand Down Expand Up @@ -148,7 +141,7 @@ export class Rafiki<T = any> {
get streamServer(): StreamServer {
return streamServer
},
get accounting(): AccountingService {
get accounting(): BasicAccountingService {
return config.accounting
},
get walletAddresses(): WalletAddressService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { IncomingAccount, OutgoingAccount } from '../../rafiki'

import { TransactionOrKnex } from 'objection'
import {
Transaction,
AccountingService,
Withdrawal,
Deposit
BasicAccountingService,
} from '../../../../../../accounting/service'
import {
CreateAccountError,
Expand Down Expand Up @@ -39,7 +36,7 @@ type MockIlpAccount = MockIncomingAccount | MockOutgoingAccount
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
const isIncomingPeer = (o: any): o is MockIncomingAccount => o.http?.incoming

export class MockAccountingService implements AccountingService {
export class MockAccountingService implements BasicAccountingService {
private accounts: Map<string, MockIlpAccount> = new Map()

async _getIncomingPayment(
Expand Down Expand Up @@ -135,50 +132,4 @@ export class MockAccountingService implements AccountingService {
}
return account
}

createDeposit(
deposit: Deposit,
trx?: TransactionOrKnex
): Promise<void | TransferError> {
return Promise.resolve(undefined)
}

createSettlementAccount(
ledger: number,
trx?: TransactionOrKnex
): Promise<void> {
return Promise.resolve(undefined)
}

createWithdrawal(withdrawal: Withdrawal): Promise<void | TransferError> {
return Promise.resolve(undefined)
}

getAccountsTotalReceived(ids: string[]): Promise<(bigint | undefined)[]> {
return Promise.resolve([])
}

getAccountsTotalSent(ids: string[]): Promise<(bigint | undefined)[]> {
return Promise.resolve([])
}

getSettlementBalance(ledger: number): Promise<bigint | undefined> {
return Promise.resolve(undefined)
}

getTotalReceived(id: string): Promise<bigint | undefined> {
return Promise.resolve(undefined)
}

getTotalSent(id: string): Promise<bigint | undefined> {
return Promise.resolve(undefined)
}

postWithdrawal(id: string): Promise<void | TransferError> {
return Promise.resolve(undefined)
}

voidWithdrawal(id: string): Promise<void | TransferError> {
return Promise.resolve(undefined)
}
}
4 changes: 2 additions & 2 deletions packages/backend/src/payment-method/ilp/connector/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { StreamServer } from '@interledger/stream-receiver'
import { Redis } from 'ioredis'

//TODO @jason, make use of the accounting service from src/accounting
import { AccountingService } from '../../../accounting/service'
import { BasicAccountingService } from '../../../accounting/service'
import { IncomingPaymentService } from '../../../open_payments/payment/incoming/service'
import { WalletAddressService } from '../../../open_payments/wallet_address/service'
import { RatesService } from '../../../rates/service'
Expand Down Expand Up @@ -35,7 +35,7 @@ import { createTelemetryMiddleware } from './core/middleware/telemetry'
interface ServiceDependencies extends BaseService {
redis: Redis
ratesService: RatesService
accountingService: AccountingService
accountingService: BasicAccountingService
telemetry?: TelemetryService
walletAddressService: WalletAddressService
incomingPaymentService: IncomingPaymentService
Expand Down

0 comments on commit 1005c26

Please sign in to comment.