feat(v2): crypto 孤儿到账发现——OrphanScanner 扫链核对 + orphan_payments 落表告警(对账兜底)
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
|
||||
"github.com/wangjia/pay/internal/model"
|
||||
)
|
||||
|
||||
type OrphanStore struct{ db *gorm.DB }
|
||||
|
||||
func NewOrphanStore(db *gorm.DB) *OrphanStore { return &OrphanStore{db: db} }
|
||||
|
||||
// Record 幂等落一条孤儿(tx_id 冲突 no-op)。返回是否新记(供告警只喊一次)。
|
||||
func (s *OrphanStore) Record(o *model.OrphanPayment) (bool, error) {
|
||||
res := s.db.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "tx_id"}},
|
||||
DoNothing: true,
|
||||
}).Create(o)
|
||||
if res.Error != nil {
|
||||
return false, fmt.Errorf("store.OrphanStore.Record: %w", res.Error)
|
||||
}
|
||||
return res.RowsAffected > 0, nil
|
||||
}
|
||||
Reference in New Issue
Block a user