Files
pay/internal/reconcile/crypto_warm.go
T

34 lines
1.0 KiB
Go

package reconcile
import (
"context"
"github.com/wangjia/pay/internal/model"
"github.com/wangjia/pay/internal/provider/crypto"
"github.com/wangjia/pay/internal/store"
)
// CryptoReservationLoader 装配 crypto 冷启动预留源:读全部 pending attempt,
// 过滤 channel=crypto,映射为 crypto.PendingReservation。ReservedAt 取 attempt.CreatedAt
// (建单时刻,冷却窗自此算)。crypto 不 import store,故此桥在装配层。
func CryptoReservationLoader(orders *store.OrderStore) crypto.ReservationLoader {
return func(ctx context.Context) ([]crypto.PendingReservation, error) {
atts, err := orders.ListAttemptsByStatus(model.AttemptPending, 200)
if err != nil {
return nil, err
}
out := make([]crypto.PendingReservation, 0, len(atts))
for i := range atts {
a := &atts[i]
if a.Channel != "crypto" {
continue
}
out = append(out, crypto.PendingReservation{
AccountID: a.AccountID, AmountMinor: a.AmountMinor,
ProviderRef: a.ProviderRef, ReservedAt: a.CreatedAt,
})
}
return out, nil
}
}