Skip to content

Commit e9c265d

Browse files
Merge branch 'master' of github.com:interledgerjs/ilp-account-service
2 parents fb35d80 + a0f9a92 commit e9c265d

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/middlewares/balance.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Balance {
3030
add (amount: BigNumber | string | number) {
3131
const newBalance = this.balance.plus(amount)
3232
if (newBalance.gt(this.maximum)) {
33-
console.log('rejected balance update. oldBalance=%s newBalance=%s amount=%s', this.balance, newBalance, amount)
33+
log.error('rejected balance update. oldBalance=%s newBalance=%s amount=%s', this.balance, newBalance, amount)
3434
throw new InsufficientLiquidityError('exceeded maximum balance.')
3535
}
3636

@@ -40,7 +40,7 @@ class Balance {
4040
subtract (amount: BigNumber | string | number) {
4141
const newBalance = this.balance.minus(amount)
4242
if (newBalance.lt(this.minimum)) {
43-
console.log('rejected balance update. oldBalance=%s newBalance=%s amount=%s', this.balance, newBalance, amount)
43+
log.error('rejected balance update. oldBalance=%s newBalance=%s amount=%s', this.balance, newBalance, amount)
4444
throw new Error(`insufficient funds. oldBalance=${this.balance} proposedBalance=${newBalance}`)
4545
}
4646

@@ -87,7 +87,7 @@ export default class BalanceMiddleware implements Middleware {
8787
})
8888
this.balance = balance
8989

90-
console.log('initializing balance for account. accountId=%s minimumBalance=%s maximumBalance=%s', account.id, minimum, maximum)
90+
log.info('initializing balance for account. accountId=%s minimumBalance=%s maximumBalance=%s', account.id, minimum, maximum)
9191

9292
pipelines.startup.insertLast({
9393
name: 'balance',
@@ -112,7 +112,7 @@ export default class BalanceMiddleware implements Middleware {
112112

113113
// Increase balance on prepare
114114
balance.add(amount)
115-
console.log('balance increased due to incoming ilp prepare. accountId=%s amount=%s newBalance=%s', this.getInfo().id, amount, balance.getValue())
115+
log.info('balance increased due to incoming ilp prepare. accountId=%s amount=%s newBalance=%s', this.getInfo().id, amount, balance.getValue())
116116
this.stats.balance.setValue(account, {}, balance.getValue().toNumber())
117117

118118
let result
@@ -121,19 +121,19 @@ export default class BalanceMiddleware implements Middleware {
121121
} catch (err) {
122122
// Refund on error
123123
balance.subtract(amount)
124-
console.log('incoming packet refunded due to error. accountId=%s amount=%s newBalance=%s', account.id, amount, balance.getValue())
124+
log.info('incoming packet refunded due to error. accountId=%s amount=%s newBalance=%s', account.id, amount, balance.getValue())
125125
this.stats.balance.setValue(account, {}, balance.getValue().toNumber())
126126
this.stats.incomingDataPacketValue.increment(account, { result : 'failed' }, + amount)
127127
throw err
128128
}
129129

130130
if (isFulfill(result)) {
131-
this.maybeSettle().catch(console.log)
131+
this.maybeSettle().catch(log.error)
132132
this.stats.incomingDataPacketValue.increment(account, { result : 'fulfilled' }, + amount)
133133
} else {
134134
// Refund on reject
135135
balance.subtract(amount)
136-
console.log('incoming packet refunded due to ilp reject. accountId=%s amount=%s newBalance=%s', account.id, amount, balance.getValue())
136+
log.info('incoming packet refunded due to ilp reject. accountId=%s amount=%s newBalance=%s', account.id, amount, balance.getValue())
137137
this.stats.balance.setValue(account, {}, balance.getValue().toNumber())
138138
this.stats.incomingDataPacketValue.increment(account, { result : 'rejected' }, + amount)
139139
}
@@ -146,7 +146,7 @@ export default class BalanceMiddleware implements Middleware {
146146
name: 'balance',
147147
method: (amount: string, next: MiddlewareCallback<string, void>) => {
148148
balance.subtract(amount)
149-
console.log('balance reduced due to incoming settlement. accountId=%s amount=%s newBalance=%s', account.id, amount, balance.getValue())
149+
log.info('balance reduced due to incoming settlement. accountId=%s amount=%s newBalance=%s', account.id, amount, balance.getValue())
150150
this.stats.balance.setValue(account, {}, balance.getValue().toNumber())
151151
return next(amount)
152152
}
@@ -169,20 +169,20 @@ export default class BalanceMiddleware implements Middleware {
169169
try {
170170
result = await next(packet)
171171
} catch (err) {
172-
console.log('outgoing packet not applied due to error. accountId=%s amount=%s newBalance=%s', account.id, amount, balance.getValue())
172+
log.error('outgoing packet not applied due to error. accountId=%s amount=%s newBalance=%s', account.id, amount, balance.getValue())
173173
this.stats.outgoingDataPacketValue.increment(account, { result : 'failed' }, + amount)
174174
throw err
175175
}
176176

177177
if (isFulfill(result)) {
178178
// Decrease balance on prepare
179179
balance.subtract(amount)
180-
this.maybeSettle().catch(console.log)
181-
console.log('balance decreased due to outgoing ilp fulfill. accountId=%s amount=%s newBalance=%s', account.id, amount, balance.getValue())
180+
this.maybeSettle().catch(log.error)
181+
log.info('balance decreased due to outgoing ilp fulfill. accountId=%s amount=%s newBalance=%s', account.id, amount, balance.getValue())
182182
this.stats.balance.setValue(account, {}, balance.getValue().toNumber())
183183
this.stats.outgoingDataPacketValue.increment(account, { result : 'fulfilled' }, + amount)
184184
} else {
185-
console.log('outgoing packet not applied due to ilp reject. accountId=%s amount=%s newBalance=%s', account.id, amount, balance.getValue())
185+
log.info('outgoing packet not applied due to ilp reject. accountId=%s amount=%s newBalance=%s', account.id, amount, balance.getValue())
186186
this.stats.outgoingDataPacketValue.increment(account, { result : 'rejected' }, + amount)
187187
}
188188

@@ -194,14 +194,14 @@ export default class BalanceMiddleware implements Middleware {
194194
name: 'balance',
195195
method: (amount: string, next: MiddlewareCallback<string, void>) => {
196196
balance.add(amount)
197-
console.log('balance increased due to outgoing settlement. accountId=%s amount=%s newBalance=%s', account.id, amount, balance.getValue())
197+
log.info('balance increased due to outgoing settlement. accountId=%s amount=%s newBalance=%s', account.id, amount, balance.getValue())
198198
this.stats.balance.setValue(account, {}, balance.getValue().toNumber())
199199

200200
return next(amount)
201201
}
202202
})
203203
} else {
204-
console.log('(!!!) balance middleware NOT enabled for account, this account can spend UNLIMITED funds. accountId=%s', account.id)
204+
log.info('(!!!) balance middleware NOT enabled for account, this account can spend UNLIMITED funds. accountId=%s', account.id)
205205
}
206206
}
207207

@@ -223,12 +223,12 @@ export default class BalanceMiddleware implements Middleware {
223223
const amountDiff = new BigNumber(_amountDiff)
224224
const account = this.getInfo()
225225
const balance = this._getBalance()
226-
console.log('modifying balance accountId=%s amount=%s', account.id, amountDiff.toString())
226+
log.info('modifying balance accountId=%s amount=%s', account.id, amountDiff.toString())
227227
if (amountDiff.isPositive()) {
228228
balance.add(amountDiff)
229229
} else {
230230
balance.subtract(amountDiff.negated())
231-
this.maybeSettle().catch(console.log)
231+
this.maybeSettle().catch(log.error)
232232
}
233233
this.stats.balance.setValue(this.getInfo(), {}, balance.getValue().toNumber())
234234
return balance.getValue()
@@ -245,15 +245,15 @@ export default class BalanceMiddleware implements Middleware {
245245
if (!settle) return
246246

247247
const settleAmount = bnSettleTo.minus(balance.getValue())
248-
console.log('settlement triggered. accountId=%s balance=%s settleAmount=%s', account.id, balance.getValue(), settleAmount)
248+
log.info('settlement triggered. accountId=%s balance=%s settleAmount=%s', account.id, balance.getValue(), settleAmount)
249249

250250
await this.sendMoney(settleAmount.toString(), account.id)
251251
.catch(e => {
252252
let err = e
253253
if (!err || typeof err !== 'object') {
254254
err = new Error('Non-object thrown: ' + e)
255255
}
256-
console.log('error occurred during settlement. accountId=%s settleAmount=%s errInfo=%s', account.id, settleAmount, err.stack ? err.stack : err)
256+
log.error('error occurred during settlement. accountId=%s settleAmount=%s errInfo=%s', account.id, settleAmount, err.stack ? err.stack : err)
257257
})
258258
}
259259
}

0 commit comments

Comments
 (0)