OSDN Git Service

fix netParams for fedd (#307)
authorHAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
Wed, 17 Jul 2019 12:45:31 +0000 (20:45 +0800)
committerPaladz <yzhu101@uottawa.ca>
Wed, 17 Jul 2019 12:45:31 +0000 (20:45 +0800)
* fix network

* update doc

docs/federation/README-en.md
toolbar/federation/config/config.go
toolbar/federation/synchron/mainchain_keeper.go
toolbar/federation/synchron/sidechain_keeper.go

index 7d5c747..e2195fe 100644 (file)
@@ -24,6 +24,7 @@ A `fed_cfg.json` would look like this:
         },
         "log_mode" : true
     },
+    "network" : "testnet",
     "federation_prog" : "0020305dc12c0dbec0c1dc1f30e835034c1f19094c06afb0eb953a6d1af42222a721",
     "mainchain" : {
         "name" : "btm",
index 5cf4edd..45db1ba 100644 (file)
@@ -37,6 +37,7 @@ type Config struct {
        API            API                `json:"api"`
        MySQLConfig    common.MySQLConfig `json:"mysql"`
        FederationProg vaporJson.HexBytes `json:"federation_prog"`
+       Network        string             `json:"network"`
        Mainchain      Chain              `json:"mainchain"`
        Sidechain      Chain              `json:"sidechain"`
 }
index 37cb747..030aa37 100644 (file)
@@ -31,6 +31,7 @@ type mainchainKeeper struct {
        assetStore     *database.AssetStore
        chainID        uint64
        federationProg []byte
+       vaporNetParams consensus.Params
 }
 
 func NewMainchainKeeper(db *gorm.DB, assetStore *database.AssetStore, cfg *config.Config) *mainchainKeeper {
@@ -46,6 +47,7 @@ func NewMainchainKeeper(db *gorm.DB, assetStore *database.AssetStore, cfg *confi
                assetStore:     assetStore,
                federationProg: cfg.FederationProg,
                chainID:        chain.ID,
+               vaporNetParams: consensus.NetParams[cfg.Network],
        }
 }
 
@@ -68,8 +70,8 @@ func (m *mainchainKeeper) Run() {
 
 func (m *mainchainKeeper) createCrossChainReqs(db *gorm.DB, crossTransactionID uint64, tx *types.Tx, statusFail bool) error {
        prog := tx.Inputs[0].ControlProgram()
-       fromAddress := common.ProgToAddress(prog, consensus.BytomMainNetParams(&consensus.ActiveNetParams))
-       toAddress := common.ProgToAddress(prog, &consensus.MainNetParams)
+       fromAddress := common.ProgToAddress(prog, consensus.BytomMainNetParams(&m.vaporNetParams))
+       toAddress := common.ProgToAddress(prog, &m.vaporNetParams)
        for i, rawOutput := range tx.Outputs {
                if !bytes.Equal(rawOutput.OutputCommitment.ControlProgram, m.federationProg) {
                        continue
index 9cb22be..f576e62 100644 (file)
@@ -26,6 +26,7 @@ type sidechainKeeper struct {
        node       *service.Node
        assetStore *database.AssetStore
        chainID    uint64
+       netParams  consensus.Params
 }
 
 func NewSidechainKeeper(db *gorm.DB, assetStore *database.AssetStore, cfg *config.Config) *sidechainKeeper {
@@ -40,6 +41,7 @@ func NewSidechainKeeper(db *gorm.DB, assetStore *database.AssetStore, cfg *confi
                node:       service.NewNode(cfg.Sidechain.Upstream),
                assetStore: assetStore,
                chainID:    chain.ID,
+               netParams:  consensus.NetParams[cfg.Network],
        }
 }
 
@@ -61,7 +63,7 @@ func (s *sidechainKeeper) Run() {
 }
 
 func (s *sidechainKeeper) createCrossChainReqs(db *gorm.DB, crossTransactionID uint64, tx *types.Tx, statusFail bool) error {
-       fromAddress := common.ProgToAddress(tx.Inputs[0].ControlProgram(), &consensus.MainNetParams)
+       fromAddress := common.ProgToAddress(tx.Inputs[0].ControlProgram(), &s.netParams)
        for i, rawOutput := range tx.Outputs {
                if rawOutput.OutputType() != types.CrossChainOutputType {
                        continue
@@ -84,7 +86,7 @@ func (s *sidechainKeeper) createCrossChainReqs(db *gorm.DB, crossTransactionID u
                        AssetAmount:        rawOutput.OutputCommitment().AssetAmount.Amount,
                        Script:             hex.EncodeToString(prog),
                        FromAddress:        fromAddress,
-                       ToAddress:          common.ProgToAddress(prog, consensus.BytomMainNetParams(&consensus.ActiveNetParams)),
+                       ToAddress:          common.ProgToAddress(prog, consensus.BytomMainNetParams(&s.netParams)),
                }
 
                if err := db.Create(req).Error; err != nil {