-
Notifications
You must be signed in to change notification settings - Fork 38
/
signer_options.go
124 lines (115 loc) · 4.85 KB
/
signer_options.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
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
123
124
package signer
import (
"fmt"
"os"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/bnb-chain/greenfield-storage-provider/base/gfspapp"
"github.com/bnb-chain/greenfield-storage-provider/base/gfspconfig"
coremodule "github.com/bnb-chain/greenfield-storage-provider/core/module"
"github.com/bnb-chain/greenfield/sdk/types"
)
const (
DefaultSealGasLimit = 1200 // fix gas limit for MsgSealObject is 1200
DefaultSealFeeAmount = 6000000000000
DefaultRejectSealGasLimit = 12000 // fix gas limit for MsgRejectSealObject is 12000
DefaultRejectSealFeeAmount = 60000000000000
DefaultDiscontinueBucketGasLimit = 2400 // fix gas limit for MsgDiscontinueBucket is 2400
DefaultDiscontinueBucketFeeAmount = 12000000000000
DefaultCreateGlobalVirtualGroupGasLimit = 1200 // fix gas limit for MsgCreateGlobalVirtualGroup is 1200
DefaultCreateGlobalVirtualGroupFeeAmount = 6000000000000
DefaultCompleteMigrateBucketGasLimit = 1200 // fix gas limit for MsgCompleteMigrateBucket is 1200
DefaultCompleteMigrateBucketFeeAmount = 6000000000000
// SpOperatorPrivKey defines env variable name for sp operator private key
SpOperatorPrivKey = "SIGNER_OPERATOR_PRIV_KEY"
// SpApprovalPrivKey defines env variable name for sp approval private key
SpApprovalPrivKey = "SIGNER_APPROVAL_PRIV_KEY"
// SpSealPrivKey defines env variable name for sp seal private key
SpSealPrivKey = "SIGNER_SEAL_PRIV_KEY"
// SpBlsPrivKey defines env variable name for sp bls private key
SpBlsPrivKey = "SIGNER_BLS_PRIV_KEY"
// SpGcPrivKey defines env variable name for sp gc private key
SpGcPrivKey = "SIGNER_GC_PRIV_KEY"
)
func NewSignModular(app *gfspapp.GfSpBaseApp, cfg *gfspconfig.GfSpConfig) (coremodule.Modular, error) {
signer := &SignModular{baseApp: app}
if err := DefaultSignerOptions(signer, cfg); err != nil {
return nil, err
}
return signer, nil
}
func DefaultSignerOptions(signer *SignModular, cfg *gfspconfig.GfSpConfig) error {
if len(cfg.Chain.ChainAddress) == 0 {
return fmt.Errorf("chain address missing")
}
if cfg.Chain.SealGasLimit == 0 {
cfg.Chain.SealGasLimit = DefaultSealGasLimit
}
if cfg.Chain.SealFeeAmount == 0 {
cfg.Chain.SealFeeAmount = DefaultSealFeeAmount
}
if cfg.Chain.RejectSealGasLimit == 0 {
cfg.Chain.RejectSealGasLimit = DefaultRejectSealGasLimit
}
if cfg.Chain.RejectSealFeeAmount == 0 {
cfg.Chain.RejectSealFeeAmount = DefaultRejectSealFeeAmount
}
if cfg.Chain.DiscontinueBucketGasLimit == 0 {
cfg.Chain.DiscontinueBucketGasLimit = DefaultDiscontinueBucketGasLimit
}
if cfg.Chain.DiscontinueBucketFeeAmount == 0 {
cfg.Chain.DiscontinueBucketFeeAmount = DefaultDiscontinueBucketFeeAmount
}
if cfg.Chain.CreateGlobalVirtualGroupGasLimit == 0 {
cfg.Chain.CreateGlobalVirtualGroupGasLimit = DefaultCreateGlobalVirtualGroupGasLimit
}
if cfg.Chain.CreateGlobalVirtualGroupFeeAmount == 0 {
cfg.Chain.CreateGlobalVirtualGroupFeeAmount = DefaultCreateGlobalVirtualGroupFeeAmount
}
if cfg.Chain.CompleteMigrateBucketGasLimit == 0 {
cfg.Chain.CompleteMigrateBucketGasLimit = DefaultCompleteMigrateBucketGasLimit
}
if cfg.Chain.CompleteMigrateBucketFeeAmount == 0 {
cfg.Chain.CompleteMigrateBucketFeeAmount = DefaultCompleteMigrateBucketFeeAmount
}
if val, ok := os.LookupEnv(SpOperatorPrivKey); ok {
cfg.SpAccount.OperatorPrivateKey = val
}
if val, ok := os.LookupEnv(SpSealPrivKey); ok {
cfg.SpAccount.SealPrivateKey = val
}
if val, ok := os.LookupEnv(SpBlsPrivKey); ok {
cfg.SpAccount.BlsPrivateKey = val
}
if val, ok := os.LookupEnv(SpApprovalPrivKey); ok {
cfg.SpAccount.ApprovalPrivateKey = val
}
if val, ok := os.LookupEnv(SpGcPrivKey); ok {
cfg.SpAccount.GcPrivateKey = val
}
gasInfo := make(map[GasInfoType]GasInfo)
gasInfo[Seal] = GasInfo{
GasLimit: cfg.Chain.SealGasLimit,
FeeAmount: sdk.NewCoins(sdk.NewCoin(types.Denom, sdk.NewInt(int64(cfg.Chain.SealFeeAmount)))),
}
gasInfo[RejectSeal] = GasInfo{
GasLimit: cfg.Chain.RejectSealGasLimit,
FeeAmount: sdk.NewCoins(sdk.NewCoin(types.Denom, sdk.NewInt(int64(cfg.Chain.RejectSealFeeAmount)))),
}
gasInfo[DiscontinueBucket] = GasInfo{
GasLimit: cfg.Chain.DiscontinueBucketGasLimit,
FeeAmount: sdk.NewCoins(sdk.NewCoin(types.Denom, sdk.NewInt(int64(cfg.Chain.DiscontinueBucketFeeAmount)))),
}
gasInfo[CreateGlobalVirtualGroup] = GasInfo{
GasLimit: cfg.Chain.CreateGlobalVirtualGroupGasLimit,
FeeAmount: sdk.NewCoins(sdk.NewCoin(types.Denom, sdk.NewInt(int64(cfg.Chain.CreateGlobalVirtualGroupFeeAmount)))),
}
client, err := NewGreenfieldChainSignClient(cfg.Chain.ChainAddress[0], cfg.Chain.ChainID,
gasInfo, cfg.SpAccount.OperatorPrivateKey, cfg.SpAccount.FundingPrivateKey,
cfg.SpAccount.SealPrivateKey, cfg.SpAccount.ApprovalPrivateKey, cfg.SpAccount.GcPrivateKey, cfg.SpAccount.BlsPrivateKey)
if err != nil {
return err
}
signer.client = client
client.signer = signer
return nil
}