@@ -26,6 +26,7 @@ import (
26
26
"github.com/elastos/Elastos.ELA.SideChain.ESC/crypto"
27
27
"github.com/elastos/Elastos.ELA.SideChain.ESC/dpos"
28
28
"github.com/elastos/Elastos.ELA.SideChain.ESC/log"
29
+ "github.com/elastos/Elastos.ELA.SideChain.ESC/node"
29
30
"github.com/elastos/Elastos.ELA.SideChain.ESC/rpc"
30
31
"github.com/elastos/Elastos.ELA.SideChain.ESC/spv"
31
32
@@ -85,13 +86,13 @@ func APIs(engine *pbft.Pbft) []rpc.API {
85
86
}}
86
87
}
87
88
88
- func Init (engine * pbft.Pbft , accountPath , accountPassword string ) {
89
+ func Init (engine * pbft.Pbft , stack * node. Node , accountPath , accountPassword string ) {
89
90
pbftEngine = engine
90
91
if MsgReleayer != nil {
91
92
log .Warn ("chain bridge is started" )
92
93
return
93
94
}
94
- err := initRelayer (engine , accountPath , accountPassword )
95
+ err := initRelayer (engine , stack , accountPath , accountPassword )
95
96
if err != nil {
96
97
bridgelog .Error ("chain bridge started error" , "error" , err )
97
98
return
@@ -645,13 +646,14 @@ func onProducersChanged(e *events.Event) {
645
646
bridgelog .Info ("SetManualArbiters" , "total" , total , "error" , err , "arbiterCount" , len (addresses ))
646
647
}
647
648
648
- func initRelayer (engine * pbft.Pbft , accountPath , accountPassword string ) error {
649
+ func initRelayer (engine * pbft.Pbft , stack * node. Node , accountPath , accountPassword string ) error {
649
650
if MsgReleayer != nil {
650
651
return nil
651
652
}
652
653
cfg , err := config .GetConfig (config .DefaultConfigDir )
653
654
if err != nil {
654
655
log .Info ("engine.GetBlockChain().Config().BridgeContractAddr" , "address" , engine .GetBlockChain ().Config ().BridgeContractAddr )
656
+ err = createSelfChain (engine , stack )
655
657
return err
656
658
}
657
659
db , err := lvldb .NewLvlDB (config .BlockstoreFlagName )
@@ -675,6 +677,24 @@ func initRelayer(engine *pbft.Pbft, accountPath, accountPassword string) error {
675
677
return nil
676
678
}
677
679
680
+ func createSelfChain (engine * pbft.Pbft , stack * node.Node ) error {
681
+ escChainID = engine .GetBlockChain ().Config ().ChainID .Uint64 ()
682
+ rpc := fmt .Sprintf ("http://localhost:%d" , stack .Config ().HTTPPort )
683
+ generalConfig := config.GeneralChainConfig {
684
+ Name : "ESC" ,
685
+ Id : escChainID ,
686
+ Endpoint : rpc ,
687
+ }
688
+ layer , errMsg := createChain (& generalConfig , nil , engine , "" , "" )
689
+ if errMsg != nil {
690
+ return errors .New (fmt .Sprintf ("evm createSelfChain is error:%s, chainid:%d" , errMsg .Error (), escChainID ))
691
+ }
692
+ chains := make ([]relayer.RelayedChain , 1 )
693
+ chains [0 ] = layer
694
+ MsgReleayer = relayer .NewRelayer (chains , escChainID )
695
+ return nil
696
+ }
697
+
678
698
func Stop (msg string ) {
679
699
if isRequireArbiter {
680
700
errChn <- fmt .Errorf (msg )
0 commit comments