diff options
author | Wei-Ning Huang <w@cobinhood.com> | 2018-09-21 15:06:38 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:21:31 +0800 |
commit | 20d12131b5b411a35558fa13a8bc86ec66d7923a (patch) | |
tree | 1d0a89371d9b87c592f86685e04d38e6b70814e3 /dex/backend.go | |
parent | 8e483e2f87cdccd924ce2261ac3a5ec8b58aaf05 (diff) | |
download | go-tangerine-20d12131b5b411a35558fa13a8bc86ec66d7923a.tar go-tangerine-20d12131b5b411a35558fa13a8bc86ec66d7923a.tar.gz go-tangerine-20d12131b5b411a35558fa13a8bc86ec66d7923a.tar.bz2 go-tangerine-20d12131b5b411a35558fa13a8bc86ec66d7923a.tar.lz go-tangerine-20d12131b5b411a35558fa13a8bc86ec66d7923a.tar.xz go-tangerine-20d12131b5b411a35558fa13a8bc86ec66d7923a.tar.zst go-tangerine-20d12131b5b411a35558fa13a8bc86ec66d7923a.zip |
dex: make geth buildable and update interface skeleton
Diffstat (limited to 'dex/backend.go')
-rw-r--r-- | dex/backend.go | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/dex/backend.go b/dex/backend.go index 73a84c139..e374bb70f 100644 --- a/dex/backend.go +++ b/dex/backend.go @@ -17,6 +17,113 @@ package dex +import ( + "math/big" + "sync" + + dexCore "github.com/dexon-foundation/dexon-consensus-core/core" + "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" + ethCrypto "github.com/dexon-foundation/dexon-consensus-core/crypto/eth" + + "github.com/ethereum/go-ethereum/accounts" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/consensus" + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/bloombits" + "github.com/ethereum/go-ethereum/eth" + "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/event" + "github.com/ethereum/go-ethereum/internal/ethapi" + "github.com/ethereum/go-ethereum/node" + "github.com/ethereum/go-ethereum/p2p" + "github.com/ethereum/go-ethereum/params" + "github.com/ethereum/go-ethereum/rpc" +) + // Dexon implementes the DEXON fullnode service. type Dexon struct { + config *eth.Config + chainConfig *params.ChainConfig + + // Channel for shutting down the service + shutdownChan chan bool // Channel for shutting down the Ethereum + txPool *core.TxPool + blockchain *core.BlockChain + + // DB interfaces + chainDb ethdb.Database // Block chain database + + eventMux *event.TypeMux + engine consensus.Engine + accountManager *accounts.Manager + + bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests + bloomIndexer *core.ChainIndexer // Bloom indexer operating during block imports + + gasPrice *big.Int + etherbase common.Address + + // Dexon consensus. + app *DexconApp + governance *DexconGovernance + network *DexconNetwork + blockdb blockdb.BlockDatabase + consensus *dexCore.Consensus + + networkID uint64 + netRPCService *ethapi.PublicNetAPI + + lock sync.RWMutex // Protects the variadic fields (e.g. gas price and etherbase) +} + +func New(ctx *node.ServiceContext, config *eth.Config) (*Dexon, error) { + // Consensus. + db, err := blockdb.NewLevelDBBackedBlockDB("main.blockdb") + if err != nil { + panic(err) + } + app := NewDexconApp(nil) + gov := NewDexconGovernance() + network := NewDexconNetwork() + + // TODO(w): replace this with node key. + privKey, err := ethCrypto.NewPrivateKey() + if err != nil { + panic(err) + } + consensus := dexCore.NewConsensus( + app, gov, db, network, privKey, ethCrypto.SigToPub) + + dex := &Dexon{ + config: config, + eventMux: ctx.EventMux, + accountManager: ctx.AccountManager, + shutdownChan: make(chan bool), + networkID: config.NetworkId, + gasPrice: config.MinerGasPrice, + etherbase: config.Etherbase, + bloomRequests: make(chan chan *bloombits.Retrieval), + app: app, + governance: gov, + network: network, + blockdb: db, + consensus: consensus, + } + return dex, nil +} + +func (s *Dexon) Protocols() []p2p.Protocol { + return nil +} + +func (s *Dexon) APIs() []rpc.API { + return nil +} + +func (s *Dexon) Start(server *p2p.Server) error { + return nil +} + +func (s *Dexon) Stop() error { + return nil } |