-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
122 lines (92 loc) · 2.79 KB
/
server.go
File metadata and controls
122 lines (92 loc) · 2.79 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package transaction
import (
"context"
"errors"
"sync"
"go.uber.org/zap"
transactionpb "github.com/code-payments/ocp-protobuf-api/generated/go/transaction/v1"
"github.com/code-payments/ocp-server/ocp/aml"
"github.com/code-payments/ocp-server/ocp/antispam"
auth_util "github.com/code-payments/ocp-server/ocp/auth"
"github.com/code-payments/ocp-server/ocp/common"
ocp_data "github.com/code-payments/ocp-server/ocp/data"
"github.com/code-payments/ocp-server/ocp/data/nonce"
"github.com/code-payments/ocp-server/ocp/transaction"
)
type transactionServer struct {
conf *conf
log *zap.Logger
data ocp_data.Provider
auth *auth_util.RPCSignatureVerifier
submitIntentIntegration SubmitIntentIntegration
airdropIntegration AirdropIntegration
antispamGuard *antispam.Guard
amlGuard *aml.Guard
noncePools []*transaction.LocalNoncePool
localAccountLocksMu sync.Mutex
localAccountLocks map[string]*sync.Mutex
airdropperLock sync.Mutex
airdropper *common.TimelockAccounts
feeCollector *common.Account
transactionpb.UnimplementedTransactionServer
}
func NewTransactionServer(
log *zap.Logger,
data ocp_data.Provider,
submitIntentIntegration SubmitIntentIntegration,
airdropIntegration AirdropIntegration,
antispamGuard *antispam.Guard,
amlGuard *aml.Guard,
noncePools []*transaction.LocalNoncePool,
configProvider ConfigProvider,
) (transactionpb.TransactionServer, error) {
ctx := context.Background()
conf := configProvider()
if !conf.disableSubmitIntent.Get(ctx) {
_, err := transaction.SelectNoncePool(
nonce.EnvironmentVm,
common.CoreMintVmAccount.PublicKey().ToBase58(),
nonce.PurposeClientIntent,
noncePools...,
)
if err != nil {
return nil, errors.New("nonce pool for core mint intent operations is not provided")
}
}
if !conf.disableSwaps.Get(ctx) {
_, err := transaction.SelectNoncePool(
nonce.EnvironmentSolana,
nonce.EnvironmentInstanceSolanaMainnet,
nonce.PurposeClientSwap,
noncePools...,
)
if err != nil {
return nil, errors.New("nonce pool for swap operations is not provided")
}
}
s := &transactionServer{
conf: conf,
log: log,
data: data,
auth: auth_util.NewRPCSignatureVerifier(log, data),
submitIntentIntegration: submitIntentIntegration,
airdropIntegration: airdropIntegration,
antispamGuard: antispamGuard,
amlGuard: amlGuard,
noncePools: noncePools,
localAccountLocks: make(map[string]*sync.Mutex),
}
var err error
s.feeCollector, err = common.NewAccountFromPublicKeyString(s.conf.feeCollectorOwnerPublicKey.Get(ctx))
if err != nil {
return nil, err
}
airdropper := s.conf.airdropperOwnerPublicKey.Get(ctx)
if len(airdropper) > 0 && airdropper != defaultAirdropperOwnerPublicKey {
err := s.loadAirdropper(ctx)
if err != nil {
return nil, err
}
}
return s, nil
}