• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: Commit

Golang implemented sidechain for Bytom


Commit MetaInfo

Revision6909cc8cbe27380866b3de360b7c3cf41b567f5b (tree)
Time2019-07-17 21:45:31
AuthorHAOYUatHZ <37070449+HAOYUatHZ@user...>
CommiterPaladz

Log Message

fix netParams for fedd (#307)

* fix network

* update doc

Change Summary

Incremental Difference

--- a/docs/federation/README-en.md
+++ b/docs/federation/README-en.md
@@ -24,6 +24,7 @@ A `fed_cfg.json` would look like this:
2424 },
2525 "log_mode" : true
2626 },
27+ "network" : "testnet",
2728 "federation_prog" : "0020305dc12c0dbec0c1dc1f30e835034c1f19094c06afb0eb953a6d1af42222a721",
2829 "mainchain" : {
2930 "name" : "btm",
--- a/toolbar/federation/config/config.go
+++ b/toolbar/federation/config/config.go
@@ -37,6 +37,7 @@ type Config struct {
3737 API API `json:"api"`
3838 MySQLConfig common.MySQLConfig `json:"mysql"`
3939 FederationProg vaporJson.HexBytes `json:"federation_prog"`
40+ Network string `json:"network"`
4041 Mainchain Chain `json:"mainchain"`
4142 Sidechain Chain `json:"sidechain"`
4243 }
--- a/toolbar/federation/synchron/mainchain_keeper.go
+++ b/toolbar/federation/synchron/mainchain_keeper.go
@@ -31,6 +31,7 @@ type mainchainKeeper struct {
3131 assetStore *database.AssetStore
3232 chainID uint64
3333 federationProg []byte
34+ vaporNetParams consensus.Params
3435 }
3536
3637 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
4647 assetStore: assetStore,
4748 federationProg: cfg.FederationProg,
4849 chainID: chain.ID,
50+ vaporNetParams: consensus.NetParams[cfg.Network],
4951 }
5052 }
5153
@@ -68,8 +70,8 @@ func (m *mainchainKeeper) Run() {
6870
6971 func (m *mainchainKeeper) createCrossChainReqs(db *gorm.DB, crossTransactionID uint64, tx *types.Tx, statusFail bool) error {
7072 prog := tx.Inputs[0].ControlProgram()
71- fromAddress := common.ProgToAddress(prog, consensus.BytomMainNetParams(&consensus.ActiveNetParams))
72- toAddress := common.ProgToAddress(prog, &consensus.MainNetParams)
73+ fromAddress := common.ProgToAddress(prog, consensus.BytomMainNetParams(&m.vaporNetParams))
74+ toAddress := common.ProgToAddress(prog, &m.vaporNetParams)
7375 for i, rawOutput := range tx.Outputs {
7476 if !bytes.Equal(rawOutput.OutputCommitment.ControlProgram, m.federationProg) {
7577 continue
--- a/toolbar/federation/synchron/sidechain_keeper.go
+++ b/toolbar/federation/synchron/sidechain_keeper.go
@@ -26,6 +26,7 @@ type sidechainKeeper struct {
2626 node *service.Node
2727 assetStore *database.AssetStore
2828 chainID uint64
29+ netParams consensus.Params
2930 }
3031
3132 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
4041 node: service.NewNode(cfg.Sidechain.Upstream),
4142 assetStore: assetStore,
4243 chainID: chain.ID,
44+ netParams: consensus.NetParams[cfg.Network],
4345 }
4446 }
4547
@@ -61,7 +63,7 @@ func (s *sidechainKeeper) Run() {
6163 }
6264
6365 func (s *sidechainKeeper) createCrossChainReqs(db *gorm.DB, crossTransactionID uint64, tx *types.Tx, statusFail bool) error {
64- fromAddress := common.ProgToAddress(tx.Inputs[0].ControlProgram(), &consensus.MainNetParams)
66+ fromAddress := common.ProgToAddress(tx.Inputs[0].ControlProgram(), &s.netParams)
6567 for i, rawOutput := range tx.Outputs {
6668 if rawOutput.OutputType() != types.CrossChainOutputType {
6769 continue
@@ -84,7 +86,7 @@ func (s *sidechainKeeper) createCrossChainReqs(db *gorm.DB, crossTransactionID u
8486 AssetAmount: rawOutput.OutputCommitment().AssetAmount.Amount,
8587 Script: hex.EncodeToString(prog),
8688 FromAddress: fromAddress,
87- ToAddress: common.ProgToAddress(prog, consensus.BytomMainNetParams(&consensus.ActiveNetParams)),
89+ ToAddress: common.ProgToAddress(prog, consensus.BytomMainNetParams(&s.netParams)),
8890 }
8991
9092 if err := db.Create(req).Error; err != nil {
Show on old repository browser