OSDN Git Service

Add the implementation for dppos
[bytom/vapor.git] / config / genesis.go
index 8190734..3a10ded 100644 (file)
@@ -1,15 +1,14 @@
 package config
 
 import (
+       "bytes"
        "crypto/sha256"
        "encoding/hex"
 
        log "github.com/sirupsen/logrus"
 
        "github.com/vapor/consensus"
-       "github.com/vapor/crypto"
        "github.com/vapor/crypto/ed25519"
-       "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
        "github.com/vapor/protocol/vm/vmutil"
@@ -17,20 +16,20 @@ import (
 
 func commitToArguments() (res *[32]byte) {
        var fedpegPubkeys []ed25519.PublicKey
-       var signBlockPubkeys []ed25519.PublicKey
        for _, xpub := range consensus.ActiveNetParams.FedpegXPubs {
                fedpegPubkeys = append(fedpegPubkeys, xpub.PublicKey())
        }
        fedpegScript, _ := vmutil.P2SPMultiSigProgram(fedpegPubkeys, len(fedpegPubkeys))
 
-       for _, xpub := range consensus.ActiveNetParams.SignBlockXPubs {
-               signBlockPubkeys = append(signBlockPubkeys, xpub.PublicKey())
+       var buffer bytes.Buffer
+       for _, address := range CommonConfig.Consensus.Signers {
+               redeemContract := address.ScriptAddress()
+               buffer.Write(redeemContract)
        }
-       signBlockScript, _ := vmutil.P2SPMultiSigProgram(signBlockPubkeys, len(signBlockPubkeys))
 
        hasher := sha256.New()
        hasher.Write(fedpegScript)
-       hasher.Write(signBlockScript)
+       hasher.Write(buffer.Bytes())
        resSlice := hasher.Sum(nil)
        res = new([32]byte)
        copy(res[:], resSlice)
@@ -56,6 +55,7 @@ func genesisTx() *types.Tx {
                        types.NewTxOutput(*consensus.BTMAssetID, consensus.InitialBlockSubsidy, contract),
                },
        }
+
        return types.NewTx(txData)
 }
 
@@ -87,21 +87,6 @@ func mainNetGenesisBlock() *types.Block {
                },
                Transactions: []*types.Tx{tx},
        }
-
-       var xPrv chainkd.XPrv
-       if consensus.ActiveNetParams.Signer == "" {
-               return block
-       }
-       copy(xPrv[:], []byte(consensus.ActiveNetParams.Signer))
-       msg, _ := block.MarshalText()
-       sign := xPrv.Sign(msg)
-       pubHash := crypto.Ripemd160(xPrv.XPub().PublicKey())
-       control, err := vmutil.P2WPKHProgram([]byte(pubHash))
-       if err != nil {
-               log.Panicf(err.Error())
-       }
-       block.Proof.Sign = sign
-       block.Proof.ControlProgram = control
        return block
 }
 
@@ -120,7 +105,6 @@ func testNetGenesisBlock() *types.Block {
        if err != nil {
                log.Panicf("fail on calc genesis tx merkel root")
        }
-
        block := &types.Block{
                BlockHeader: types.BlockHeader{
                        Version:   1,
@@ -156,7 +140,7 @@ func soloNetGenesisBlock() *types.Block {
                BlockHeader: types.BlockHeader{
                        Version:   1,
                        Height:    0,
-                       Timestamp: 1528945000,
+                       Timestamp: CommonConfig.Consensus.GenesisTimestamp,
                        BlockCommitment: types.BlockCommitment{
                                TransactionsMerkleRoot: merkleRoot,
                                TransactionStatusHash:  txStatusHash,