github.com/deroproject/derosuite@v2.1.6-1.0.20200307070847-0f2e589c7a2b+incompatible/blockchain/genesis.go (about) 1 // Copyright 2017-2018 DERO Project. All rights reserved. 2 // Use of this source code in any form is governed by RESEARCH license. 3 // license can be found in the LICENSE file. 4 // GPG: 0F39 E425 8C65 3947 702A 8234 08B2 0360 A03A 9DE8 5 // 6 // 7 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 8 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 9 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 10 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 11 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 12 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 13 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 14 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 15 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 16 17 package blockchain 18 19 import "encoding/hex" 20 21 import "github.com/romana/rlog" 22 23 //import "github.com/deroproject/derosuite/address" 24 import "github.com/deroproject/derosuite/crypto" 25 import "github.com/deroproject/derosuite/block" 26 import "github.com/deroproject/derosuite/globals" 27 28 //import "github.com/deroproject/derosuite/config" 29 30 /* 31 func Create_Miner_Transaction(height uint64, median_size uint64, already_generated_coins uint64, 32 current_block_size uint64, fee uint64, 33 miner_address address.Address, nonce []byte, 34 max_outs uint64, hard_fork uint64) (tx *transaction.Transaction, err error) { 35 36 return nil, nil 37 } 38 */ 39 40 // genesis transaction hash 5a18d9489bcd353aeaf4a19323d04e90353f98f0d7cc2a030cfd76e19495547d 41 // genesis amount 35184372088831 42 func Generate_Genesis_Block() (bl block.Block) { 43 44 genesis_tx_blob, err := hex.DecodeString(globals.Config.Genesis_Tx) 45 if err != nil { 46 panic("Failed to hex decode genesis Tx") 47 } 48 err = bl.Miner_TX.DeserializeHeader(genesis_tx_blob) 49 50 if err != nil { 51 panic("Failed to parse genesis tx ") 52 } 53 54 //rlog.Tracef(2, "Hash of Genesis Tx %x\n", bl.Miner_tx.GetHash()) 55 56 // verify whether tx is coinbase and valid 57 58 // setup genesis block header 59 bl.Major_Version = 1 60 bl.Minor_Version = 1 61 bl.Timestamp = 0 // first block timestamp 62 63 var zerohash crypto.Hash 64 _ = zerohash 65 //bl.Tips = append(bl.Tips,zerohash) 66 //bl.Prev_hash is automatic zero 67 bl.Nonce = globals.Config.Genesis_Nonce 68 69 rlog.Tracef(2, "Hash of genesis block is %x", bl.GetHash()) 70 71 serialized := bl.Serialize() 72 73 var bl2 block.Block 74 err = bl2.Deserialize(serialized) 75 if err != nil { 76 panic("error while serdes genesis block") 77 } 78 if bl.GetHash() != bl2.GetHash() { 79 panic("hash mismatch serdes genesis block") 80 } 81 82 //rlog.Tracef(2, "Genesis Block PoW %x\n", bl.GetPoWHash()) 83 84 return 85 }