-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.go
99 lines (82 loc) · 2.74 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2019, Keychain Foundation Ltd.
// This file is part of the dipperin-core library.
//
// The dipperin-core library is free software: you can redistribute
// it and/or modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// The dipperin-core library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package main
import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/urfave/cli"
"os"
"github.com/dipperin/dipperin-core/core/chain-config"
"github.com/dipperin/dipperin-core/core/chain/state-processor"
"github.com/dipperin/dipperin-core/core/model"
"github.com/dipperin/dipperin-core/core/contract"
"fmt"
"github.com/dipperin/dipperin-core/third-party/log"
"reflect"
"github.com/dipperin/dipperin-core/core/cs-chain"
"github.com/dipperin/dipperin-core/core/chain"
)
const (
DataDirFName = "data_dir"
)
func main() {
app := cli.NewApp()
app.Flags = []cli.Flag{
cli.StringFlag{ Name: DataDirFName, Value: "/home/qydev/csdebug/full_chain_data" },
}
app.Action = run
fmt.Println(os.Args)
if err := app.Run(os.Args); err != nil {
panic(err)
}
}
/**/
func run(c *cli.Context) {
nContext := initContext(c)
curBlock := nContext.fullChain.CurrentBlock()
log.Info("cur block num", "num", curBlock.Number())
state, err := chain.NewBlockProcessor(nContext.fullChain, curBlock.StateRoot(), nContext.stateStorage)
if err != nil {
panic(err)
}
cb, err := state.GetContract(contract.EarlyContractAddress, reflect.TypeOf(contract.EarlyRewardContract{}))
if err != nil {
panic(err)
}
fmt.Println(cb.Interface())
}
func initContext(c *cli.Context) *nodeContext {
dataDir := c.String(DataDirFName)
db, err := ethdb.NewLDBDatabase(dataDir, 0, 0)
if err != nil {
panic(err)
}
model.SetBlockRlpHandler(&model.PBFTBlockRlpHandler{})
model.SetBlockJsonHandler(&model.PBFTBlockJsonHandler{})
context := &nodeContext{
db: db, blockDecoder: model.MakeDefaultBlockDecoder(),
chainConfig: *chain_config.GetChainConfig(),
}
context.stateStorage = state_processor.NewStateStorageWithCache(context.db)
//context.fullChain = chain.MakeFullChain(context)
return context
}
type nodeContext struct {
chainConfig chain_config.ChainConfig
blockDecoder model.BlockDecoder
db ethdb.Database
stateStorage state_processor.StateStorage
fullChain cs_chain.Chain
}