aboutsummaryrefslogblamecommitdiff
path: root/coreth.go
blob: 04d782fb88730d3142804378bd30686f3fa92b10 (plain) (tree)
1
2
3
4
5
6
7
8
9
10


              
                      
             


            

                                                    
                                          
                                         



                                                    
                                               

                                               
                                             
                                    






                           

                                         
                                     

 
                                            
                    

 
                                                                                                                         


                                           


                                        
                                 
                                                            



                          
                                                                    
         
                                           
                                        
                                                             
                                                              







                                                     


                               
                                   
 

                              
                               

 
                                  
                                       

 








                                                       
                                                                      
                                                        


                                                                     
                                                   
 
 
                                                              
                           

 













                                                                    

 


























                                                                                            
                                                                     
                                                 
                                                       


                                                                 



                                                                          



                                                      



                                                                      















                                                                                  



                                                       
                 
                                 



                                                              




                                                                              


                                           




                                                                      
 

             


                                                                                                                                 
 
package coreth

import (
	"crypto/ecdsa"
	"fmt"
	"io"
	"os"

	"github.com/ava-labs/coreth/consensus/dummy"
	"github.com/ava-labs/coreth/eth"
	"github.com/ava-labs/coreth/miner"
	"github.com/ava-labs/coreth/node"
	"github.com/ava-labs/go-ethereum/common"
	"github.com/ava-labs/go-ethereum/core/state"
	"github.com/ava-labs/go-ethereum/core/types"
	"github.com/ava-labs/go-ethereum/crypto"
	"github.com/ava-labs/go-ethereum/ethdb"
	"github.com/ava-labs/go-ethereum/event"
	"github.com/ava-labs/go-ethereum/log"
	"github.com/ava-labs/go-ethereum/rpc"
	"github.com/mattn/go-isatty"
)

type Tx = types.Transaction
type Block = types.Block
type Hash = common.Hash

type ETHChain struct {
	backend *eth.Ethereum
	cb      *dummy.ConsensusCallbacks
	mcb     *miner.MinerCallbacks
}

func isLocalBlock(block *types.Block) bool {
	return false
}

func NewETHChain(config *eth.Config, nodecfg *node.Config, etherBase *common.Address, chainDB ethdb.Database) *ETHChain {
	if config == nil {
		config = &eth.DefaultConfig
	}
	if nodecfg == nil {
		nodecfg = &node.Config{}
	}
	mux := new(event.TypeMux)
	ctx, ep, err := node.NewServiceContext(nodecfg, mux)
	if err != nil {
		panic(err)
	}
	if ep != "" {
		log.Info(fmt.Sprintf("temporary keystore = %s", ep))
	}
	cb := new(dummy.ConsensusCallbacks)
	mcb := new(miner.MinerCallbacks)
	backend, _ := eth.New(&ctx, config, cb, mcb, chainDB)
	chain := &ETHChain{backend: backend, cb: cb, mcb: mcb}
	if etherBase == nil {
		etherBase = &common.Address{
			1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		}
	}
	backend.SetEtherbase(*etherBase)
	return chain
}

func (self *ETHChain) Start() {
	self.backend.StartMining(0)
}

func (self *ETHChain) Stop() {
	self.backend.StopPart()
}

func (self *ETHChain) GenBlock() {
	self.backend.Miner().GenBlock()
}

func (self *ETHChain) PendingSize() (int, error) {
	pending, err := self.backend.TxPool().Pending()
	count := 0
	for _, txs := range pending {
		count += len(txs)
	}
	return count, err
}

func (self *ETHChain) AddRemoteTxs(txs []*types.Transaction) []error {
	return self.backend.TxPool().AddRemotesSync(txs)
}

func (self *ETHChain) AddLocalTxs(txs []*types.Transaction) []error {
	return self.backend.TxPool().AddLocals(txs)
}

func (self *ETHChain) SetOnSeal(cb func(*types.Block) error) {
	<