log "github.com/sirupsen/logrus"
dbm "github.com/tendermint/tmlibs/db"
- "github.com/bytom/consensus"
"github.com/bytom/errors"
+ "github.com/bytom/config"
"github.com/bytom/protocol"
"github.com/bytom/protocol/bc"
- "github.com/bytom/protocol/bc/legacy"
"github.com/bytom/sync/idempotency"
)
accountUTXO := new(UTXO)
//temp fix for coinbase UTXO isn't add to accountUTXO db, will be remove later
- if outHash.String() == "73d1e97c7bcf2b084f936a40f4f2a72e909417f2b46699e8659fa4c4feddb98d" {
+ if outHash == *config.GenerateGenesisTx().ResultIds[0] {
return genesisBlockUTXO(), nil
}
//temp fix for coinbase UTXO isn't add to accountUTXO db, will be remove later
func genesisBlockUTXO() *utxo {
u := new(utxo)
- genesisBlock := &legacy.Block{
- BlockHeader: legacy.BlockHeader{},
- Transactions: []*legacy.Tx{},
- }
- genesisBlock.UnmarshalText(consensus.InitBlock())
- tx := genesisBlock.Transactions[0]
+ tx := config.GenerateGenesisTx()
+
out := tx.Outputs[0]
resOutID := tx.ResultIds[0]
resOut, _ := tx.Entries[*resOutID].(*bc.Output)
+ log.Infof("genesis Output:%v", resOut)
//u.AccountID =
u.OutputID = *tx.OutputID(0)
"testing"
"time"
+ dbm "github.com/tendermint/tmlibs/db"
+
"github.com/bytom/blockchain/account"
"github.com/bytom/blockchain/asset"
"github.com/bytom/blockchain/pseudohsm"
"github.com/bytom/blockchain/txbuilder"
"github.com/bytom/blockchain/txdb"
cfg "github.com/bytom/config"
- "github.com/bytom/consensus"
"github.com/bytom/crypto/ed25519/chainkd"
"github.com/bytom/protocol"
"github.com/bytom/protocol/bc"
- "github.com/bytom/protocol/bc/legacy"
-
- dbm "github.com/tendermint/tmlibs/db"
)
const dirPath = "pseudohsm/testdata/pseudo"
var accounts *account.Manager
var wallet *account.Wallet
var assets *asset.Registry
-
- genesisBlock := &legacy.Block{
- BlockHeader: legacy.BlockHeader{},
- Transactions: []*legacy.Tx{},
- }
- genesisBlock.UnmarshalText(consensus.InitBlock())
+ genesisBlock := cfg.GenerateGenesisBlock()
// tx pool init
txPool := protocol.NewTxPool()
chain, err := protocol.NewChain(genesisBlock.Hash(), store, txPool)
"github.com/bytom/blockchain/txbuilder"
"github.com/bytom/crypto/ed25519/chainkd"
"github.com/bytom/encoding/json"
+ "github.com/bytom/config"
stdjson "encoding/json"
bchain "github.com/bytom/blockchain"
{
"type":"spend_account_unspent_output",
"receiver":null,
- "output_id":"73d1e97c7bcf2b084f936a40f4f2a72e909417f2b46699e8659fa4c4feddb98d",
+ "output_id":"%v",
"reference_data":{}
},
{"type": "issue", "asset_id": "%s", "amount": 100},
{"type": "control_account", "asset_id": "%s", "amount": 100, "account_id": "%s"},
{"type": "control_account", "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "amount": 8888888888, "account_id": "%s"}
]}`
- buildReqStr := fmt.Sprintf(buildReqFmt, assets[0].ID.String(), assets[0].ID.String(), accounts[0].ID, accounts[0].ID)
+ fmt.Printf("spend_account_unspent_output:%v\n", config.GenerateGenesisTx().ResultIds[0])
+ buildReqStr := fmt.Sprintf(buildReqFmt, config.GenerateGenesisTx().ResultIds[0], assets[0].ID.String(), assets[0].ID.String(), accounts[0].ID, accounts[0].ID)
var buildReq bchain.BuildRequest
err := stdjson.Unmarshal([]byte(buildReqStr), &buildReq)
if err != nil {
"github.com/bytom/blockchain/txbuilder"
"github.com/bytom/crypto/ed25519/chainkd"
"github.com/bytom/encoding/json"
+ "github.com/bytom/config"
)
type accUTXOShort struct {
{
"type":"spend_account_unspent_output",
"receiver":null,
- "output_id":"73d1e97c7bcf2b084f936a40f4f2a72e909417f2b46699e8659fa4c4feddb98d",
+ "output_id":"%v",
"reference_data":{}
},
{"type": "issue", "asset_id": "%s", "amount": 100},
{"type": "control_account", "asset_id": "%s", "amount": 100, "account_id": "%s"},
{"type": "control_account", "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "amount": 8888888888, "account_id": "%s"}
]}`
- buildReqStr := fmt.Sprintf(buildReqFmt, assets[0].ID.String(), assets[0].ID.String(), accounts[0].ID, accounts[0].ID)
+ buildReqStr := fmt.Sprintf(buildReqFmt, config.GenerateGenesisTx().ResultIds[0], assets[0].ID.String(), assets[0].ID.String(), accounts[0].ID, accounts[0].ID)
var buildReq bchain.BuildRequest
err := stdjson.Unmarshal([]byte(buildReqStr), &buildReq)
if err != nil {
"github.com/bytom/encoding/json"
"github.com/bytom/env"
"github.com/bytom/errors"
+ "github.com/bytom/config"
)
// config vars
{
"type":"spend_account_unspent_output",
"receiver":null,
- "output_id":"73d1e97c7bcf2b084f936a40f4f2a72e909417f2b46699e8659fa4c4feddb98d",
+ "output_id":"%v",
"reference_data":{}
},
{"type": "issue", "asset_id": "%s", "amount": 100},
{"type": "control_account", "asset_id": "%s", "amount": 100, "account_id": "%s"}
]}`
- buildReqStr := fmt.Sprintf(buildReqFmt, args[1], args[1], args[0])
+ buildReqStr := fmt.Sprintf(buildReqFmt, config.GenerateGenesisTx().ResultIds[0], args[1], args[1], args[0])
var buildReq blockchain.BuildRequest
err := stdjson.Unmarshal([]byte(buildReqStr), &buildReq)
if err != nil {
{
"type":"spend_account_unspent_output",
"receiver":null,
- "output_id":"73d1e97c7bcf2b084f936a40f4f2a72e909417f2b46699e8659fa4c4feddb98d",
+ "output_id":"%v",
"reference_data":{}
},
{"type": "issue", "asset_id": "%s", "amount": %s},
{"type": "control_account", "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "amount": 8888888888, "account_id": "%s"},
{"type": "control_account", "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "amount": 8888888888, "account_id": "%s"}
]}`
- buildReqStr := fmt.Sprintf(buildReqFmt, args[2], args[4], args[2], args[4], args[0], args[0], args[1])
+ buildReqStr := fmt.Sprintf(buildReqFmt, config.GenerateGenesisTx().ResultIds[0], args[2], args[4], args[2], args[4], args[0], args[0], args[1])
var buildReq blockchain.BuildRequest
err := stdjson.Unmarshal([]byte(buildReqStr), &buildReq)
if err != nil {
--- /dev/null
+package config
+
+import (
+ log "github.com/sirupsen/logrus"
+
+ "github.com/bytom/protocol/bc/legacy"
+ "github.com/bytom/protocol/bc"
+ "github.com/bytom/consensus"
+ "github.com/bytom/protocol/state"
+ "github.com/bytom/crypto/sha3pool"
+)
+
+// Generate genesis transaction
+func GenerateGenesisTx() *legacy.Tx {
+ txData := legacy.TxData{
+ Version: 1,
+ SerializedSize: 63,
+ Inputs: []*legacy.TxInput{},
+ Outputs:[]*legacy.TxOutput{
+ &legacy.TxOutput{
+ AssetVersion: 1,
+ OutputCommitment: legacy.OutputCommitment{
+ AssetAmount: bc.AssetAmount{
+ AssetId: consensus.BTMAssetID,
+ Amount: 1470000000000000000,
+ },
+ VMVersion: 1,
+ ControlProgram: []byte{81},
+ },
+ },
+ },
+ MinTime: 0,
+ MaxTime: 1511318565142,
+ }
+
+ return legacy.NewTx(txData)
+}
+
+// Generate genesis block
+func GenerateGenesisBlock() *legacy.Block {
+ genesisCoinbaseTx := GenerateGenesisTx()
+ merkleRoot, err := bc.MerkleRoot([]*bc.Tx{genesisCoinbaseTx.Tx})
+ if err != nil {
+ log.Panicf("Fatal create merkelRoot")
+ }
+
+ snap := state.Empty()
+ if err := snap.ApplyTx(genesisCoinbaseTx.Tx); err != nil {
+ log.Panicf("Fatal ApplyTx")
+ }
+
+ var seed [32]byte
+ sha3pool.Sum256(seed[:], make([]byte, 32))
+
+ genesisBlock := &legacy.Block{
+ BlockHeader: legacy.BlockHeader{
+ Version: 1,
+ Height: 1,
+ Seed: bc.NewHash(seed),
+ TimestampMS: 1511318565142,
+ BlockCommitment: legacy.BlockCommitment{
+ TransactionsMerkleRoot: merkleRoot,
+ AssetsMerkleRoot: snap.Tree.RootHash(),
+ },
+ Bits: 2161727821138738707,
+ },
+ Transactions: []*legacy.Tx{genesisCoinbaseTx},
+ }
+
+ for i := uint64(0); i <= 10000000000000; i++ {
+ genesisBlock.Nonce = i
+ hash := genesisBlock.Hash()
+
+ if consensus.CheckProofOfWork(&hash, genesisBlock.Bits) {
+ break
+ }
+ }
+
+ log.Infof("genesisBlock:%v", genesisBlock)
+ return genesisBlock
+}
--- /dev/null
+package config
+
+import (
+ "testing"
+)
+
+// test genesis
+func TestGenesis(t *testing.T) {
+ if tx := GenerateGenesisTx(); tx == nil {
+ t.Errorf("Generate genesis tx failed")
+ }
+
+ if block := GenerateGenesisBlock(); block == nil {
+ t.Errorf("Generate genesis block failed")
+ }
+}
return baseSubsidy >> uint(height/subsidyReductionInterval)
}
-// InitBlock record the byte init block
-func InitBlock() []byte {
- return []byte("03010100000000000000000000000000000000000000000000000000000000000000009e6291970cb44dd94008c79bcaf9d86f18b4b49ba5b2a04781db7199ed3b9e4e96e2ec8cfe2b4046c8af216f53bf86a30638b13a0b7404c463b9cf8df153a22233ec23886fc5bd12553440d84371701d3d4348099f8abd59a7e7d819befa57b1de50212e5d20e3e1a4fd0193fcb680808080801e010701070096e2ec8cfe2b000001012fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8080ccdee2a69fb3140104cd57a069000000")
-}
-
// IsBech32SegwitPrefix returns whether the prefix is a known prefix for segwit
// addresses on any default or registered network. This is used when decoding
// an address string into a specific address type.
"github.com/bytom/blockchain/txdb"
"github.com/bytom/blockchain/txfeed"
cfg "github.com/bytom/config"
- "github.com/bytom/consensus"
"github.com/bytom/env"
"github.com/bytom/errors"
"github.com/bytom/p2p"
"github.com/bytom/protocol"
- "github.com/bytom/protocol/bc/legacy"
"github.com/bytom/types"
"github.com/bytom/version"
)
sw := p2p.NewSwitch(config.P2P)
- genesisBlock := &legacy.Block{
- BlockHeader: legacy.BlockHeader{},
- Transactions: []*legacy.Tx{},
- }
- genesisBlock.UnmarshalText(consensus.InitBlock())
+ genesisBlock := cfg.GenerateGenesisBlock()
txPool := protocol.NewTxPool()
chain, err := protocol.NewChain(genesisBlock.Hash(), store, txPool)