@@ -47,7 +47,10 @@ export function buildDistributor(treasury, bank, epochTimer, timer, params) {
47
47
let lastWallTimeUpdate ;
48
48
const timerNotifier = E ( timer ) . makeNotifier ( 0n , updateInterval ) ;
49
49
50
- async function scheduleDeposits ( ) {
50
+ /**
51
+ * @param {(pmt: Payment[]) => void } disposeRejectedPayments
52
+ */
53
+ async function scheduleDeposits ( disposeRejectedPayments ) {
51
54
if ( ! queuedPayments . length ) {
52
55
return ;
53
56
}
@@ -60,12 +63,22 @@ export function buildDistributor(treasury, bank, epochTimer, timer, params) {
60
63
if ( ! queuedPayments . length ) {
61
64
return ;
62
65
}
63
- E ( bank ) . depositMultiple (
64
- queuedAccounts . splice ( 0 , depositsPerUpdate ) ,
65
- queuedPayments . splice ( 0 , depositsPerUpdate ) ,
66
- ) ;
67
66
68
- scheduleDeposits ( ) ;
67
+ const accounts = queuedAccounts . splice ( 0 , depositsPerUpdate ) ;
68
+ const payments = queuedPayments . splice ( 0 , depositsPerUpdate ) ;
69
+ E ( bank )
70
+ . depositMultiple ( runBrand , accounts , payments )
71
+ . then ( settledResults => {
72
+ const rejectedPayments = payments . filter (
73
+ ( _pmt , i ) =>
74
+ settledResults [ i ] && settledResults [ i ] . status === 'rejected' ,
75
+ ) ;
76
+
77
+ // Redeposit the payments.
78
+ disposeRejectedPayments ( rejectedPayments ) ;
79
+ } )
80
+ . catch ( e => console . error ( `distributeFees cannot depositMultiple` , e ) ) ;
81
+ scheduleDeposits ( disposeRejectedPayments ) ;
69
82
}
70
83
71
84
async function schedulePayments ( ) {
@@ -95,7 +108,9 @@ export function buildDistributor(treasury, bank, epochTimer, timer, params) {
95
108
queuedPayments . push ( ...manyPayments . slice ( 0 , manyPayments . length - 1 ) ) ;
96
109
queuedAccounts . push ( ...accounts ) ;
97
110
98
- scheduleDeposits ( ) ;
111
+ scheduleDeposits ( _pmts => {
112
+ // TODO: Somehow reclaim the rejected payments.
113
+ } ) ;
99
114
}
100
115
101
116
const timeObserver = {
@@ -109,5 +124,5 @@ export function buildDistributor(treasury, bank, epochTimer, timer, params) {
109
124
} ;
110
125
111
126
const epochNotifier = E ( epochTimer ) . makeNotifier ( 0n , epochInterval ) ;
112
- observeNotifier ( epochNotifier , timeObserver ) ;
127
+ return observeNotifier ( epochNotifier , timeObserver ) ;
113
128
}
0 commit comments