X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=config%2Fgenesis.go;h=f714e7b505c770406d4fc3e554d817e8bd595ed0;hb=4c43de6c51c2f266b6671cf6ff724aae4ca6c8fa;hp=3a10ded0f891c39a737a9cbe5bccf682895667db;hpb=369882c62ed2ccfe13f9d0ff918076a52ed7b91b;p=bytom%2Fvapor.git diff --git a/config/genesis.go b/config/genesis.go index 3a10ded0..f714e7b5 100644 --- a/config/genesis.go +++ b/config/genesis.go @@ -1,66 +1,49 @@ package config import ( - "bytes" - "crypto/sha256" "encoding/hex" log "github.com/sirupsen/logrus" "github.com/vapor/consensus" - "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" ) -func commitToArguments() (res *[32]byte) { - var fedpegPubkeys []ed25519.PublicKey - for _, xpub := range consensus.ActiveNetParams.FedpegXPubs { - fedpegPubkeys = append(fedpegPubkeys, xpub.PublicKey()) - } - fedpegScript, _ := vmutil.P2SPMultiSigProgram(fedpegPubkeys, len(fedpegPubkeys)) - - var buffer bytes.Buffer - for _, address := range CommonConfig.Consensus.Signers { - redeemContract := address.ScriptAddress() - buffer.Write(redeemContract) +func FederationProgrom(c *Config) []byte { + xpubs := c.Federation.Xpubs + fedpegScript, err := vmutil.P2SPMultiSigProgram(chainkd.XPubKeys(xpubs), c.Federation.Quorum) + if err != nil { + log.Panicf("fail to generate federation scirpt for federation: %v", err) } - hasher := sha256.New() - hasher.Write(fedpegScript) - hasher.Write(buffer.Bytes()) - resSlice := hasher.Sum(nil) - res = new([32]byte) - copy(res[:], resSlice) - return + return fedpegScript } -func genesisTx() *types.Tx { - +func GenesisTx() *types.Tx { contract, err := hex.DecodeString("00148c9d063ff74ee6d9ffa88d83aeb038068366c4c4") if err != nil { log.Panicf("fail on decode genesis tx output control program") } - coinbaseInput := commitToArguments() + coinbaseInput := FederationProgrom(CommonConfig) + txData := types.TxData{ Version: 1, Inputs: []*types.TxInput{ - // Any consensus-related values that are command-line set can be added here for anti-footgun types.NewCoinbaseInput(coinbaseInput[:]), - //types.NewCoinbaseInput([]byte("Information is power. -- Jan/11/2013. Computing is power. -- Apr/24/2018.")), }, Outputs: []*types.TxOutput{ - types.NewTxOutput(*consensus.BTMAssetID, consensus.InitialBlockSubsidy, contract), + types.NewIntraChainOutput(*consensus.BTMAssetID, consensus.BlockSubsidy(0), contract), }, } - return types.NewTx(txData) } func mainNetGenesisBlock() *types.Block { - tx := genesisTx() + tx := GenesisTx() txStatus := bc.NewTransactionStatus() if err := txStatus.SetStatus(0, false); err != nil { log.Panicf(err.Error()) @@ -79,7 +62,7 @@ func mainNetGenesisBlock() *types.Block { BlockHeader: types.BlockHeader{ Version: 1, Height: 0, - Timestamp: 1524549600, + Timestamp: 1524549600000, BlockCommitment: types.BlockCommitment{ TransactionsMerkleRoot: merkleRoot, TransactionStatusHash: txStatusHash, @@ -91,7 +74,7 @@ func mainNetGenesisBlock() *types.Block { } func testNetGenesisBlock() *types.Block { - tx := genesisTx() + tx := GenesisTx() txStatus := bc.NewTransactionStatus() if err := txStatus.SetStatus(0, false); err != nil { log.Panicf(err.Error()) @@ -105,11 +88,12 @@ func testNetGenesisBlock() *types.Block { if err != nil { log.Panicf("fail on calc genesis tx merkel root") } + block := &types.Block{ BlockHeader: types.BlockHeader{ Version: 1, Height: 0, - Timestamp: 1528945000, + Timestamp: 1528945000000, BlockCommitment: types.BlockCommitment{ TransactionsMerkleRoot: merkleRoot, TransactionStatusHash: txStatusHash, @@ -121,7 +105,7 @@ func testNetGenesisBlock() *types.Block { } func soloNetGenesisBlock() *types.Block { - tx := genesisTx() + tx := GenesisTx() txStatus := bc.NewTransactionStatus() if err := txStatus.SetStatus(0, false); err != nil { log.Panicf(err.Error()) @@ -140,7 +124,7 @@ func soloNetGenesisBlock() *types.Block { BlockHeader: types.BlockHeader{ Version: 1, Height: 0, - Timestamp: CommonConfig.Consensus.GenesisTimestamp, + Timestamp: 1528945000000, BlockCommitment: types.BlockCommitment{ TransactionsMerkleRoot: merkleRoot, TransactionStatusHash: txStatusHash, @@ -154,8 +138,9 @@ func soloNetGenesisBlock() *types.Block { // GenesisBlock will return genesis block func GenesisBlock() *types.Block { return map[string]func() *types.Block{ - "main": mainNetGenesisBlock, - "test": testNetGenesisBlock, - "solo": soloNetGenesisBlock, + "main": mainNetGenesisBlock, + "test": testNetGenesisBlock, + "solo": soloNetGenesisBlock, + "vapor": soloNetGenesisBlock, }[consensus.ActiveNetParams.Name]() }