-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
83 lines (67 loc) · 1.99 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package stores
import (
"github.com/axieinfinity/bridge-v2/models"
"gorm.io/gorm"
)
type TaskStore interface {
Save(task *models.Task) error
Update(task *models.Task) error
GetTasks(chain, status string, limit, retrySeconds int, before int64, excludeIds []int) ([]*models.Task, error)
UpdateTasksWithTransactionHash(txs []string, transactionStatus int, status string) error
DeleteTasks([]string, uint64) error
Count() int64
ResetTo(ids []string, status string) error
CountTasks(chain, status string) (int64, error)
}
type DepositStore interface {
Save(deposit *models.Deposit) error
}
type ProcessedReceiptStore interface {
Save(taskId int, receiptId int64) error
}
type WithdrawalStore interface {
Save(withdraw *models.Withdrawal) error
Update(withdraw *models.Withdrawal) error
GetWithdrawalById(withdrawalId int64) (*models.Withdrawal, error)
}
type BridgeStore interface {
GetDepositStore() DepositStore
GetWithdrawalStore() WithdrawalStore
GetTaskStore() TaskStore
GetProcessedReceiptStore() ProcessedReceiptStore
}
type bridgeStore struct {
*gorm.DB
DepositStore DepositStore
WithdrawalStore WithdrawalStore
TaskStore TaskStore
ProcessedReceiptStore ProcessedReceiptStore
}
func NewBridgeStore(db *gorm.DB) BridgeStore {
store := &bridgeStore{
DB: db,
TaskStore: NewTaskStore(db),
DepositStore: NewDepositStore(db),
WithdrawalStore: NewWithdrawalStore(db),
ProcessedReceiptStore: NewProcessedReceiptStore(db),
}
return store
}
func (m *bridgeStore) RelationalDatabaseCheck() error {
return m.Raw("SELECT 1").Error
}
func (m *bridgeStore) GetDB() *gorm.DB {
return m.DB
}
func (m *bridgeStore) GetDepositStore() DepositStore {
return m.DepositStore
}
func (m *bridgeStore) GetWithdrawalStore() WithdrawalStore {
return m.WithdrawalStore
}
func (m *bridgeStore) GetTaskStore() TaskStore {
return m.TaskStore
}
func (m *bridgeStore) GetProcessedReceiptStore() ProcessedReceiptStore {
return m.ProcessedReceiptStore
}