-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
50 lines (42 loc) · 1.5 KB
/
context.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
package govern_token
import (
"fmt"
xledger "github.com/superconsensus-chain/xupercore/bcs/ledger/xledger/ledger"
"github.com/superconsensus-chain/xupercore/kernel/common/xcontext"
"github.com/superconsensus-chain/xupercore/kernel/contract"
"github.com/superconsensus-chain/xupercore/kernel/contract/proposal/utils"
"github.com/superconsensus-chain/xupercore/kernel/ledger"
"github.com/superconsensus-chain/xupercore/lib/logs"
"github.com/superconsensus-chain/xupercore/lib/timer"
)
type LedgerRely interface {
// 从创世块获取创建合约账户消耗gas
GetNewGovGas() (int64, error)
// 从创世块获取创建合约账户消耗gas
GetGenesisPreDistribution() ([]xledger.Predistribution, error)
// 获取状态机最新确认快照
GetTipXMSnapshotReader() (ledger.XMSnapshotReader, error)
}
type GovCtx struct {
// 基础上下文
xcontext.BaseCtx
BcName string
Ledger LedgerRely
Contract contract.Manager
}
func NewGovCtx(bcName string, leg LedgerRely, contract contract.Manager) (*GovCtx, error) {
if bcName == "" || leg == nil || contract == nil {
return nil, fmt.Errorf("new gov ctx failed because param error")
}
log, err := logs.NewLogger("", utils.GovernTokenKernelContract)
if err != nil {
return nil, fmt.Errorf("new gov ctx failed because new logger error. err:%v", err)
}
ctx := new(GovCtx)
ctx.XLog = log
ctx.Timer = timer.NewXTimer()
ctx.BcName = bcName
ctx.Ledger = leg
ctx.Contract = contract
return ctx, nil
}