OSDN Git Service

edit the address prefix (#2056)
[bytom/bytom.git] / config / genesis_tx.go
1 package config
2
3 import (
4         "encoding/hex"
5
6         log "github.com/sirupsen/logrus"
7
8         "github.com/bytom/bytom/consensus"
9         "github.com/bytom/bytom/protocol/bc"
10         "github.com/bytom/bytom/protocol/bc/types"
11 )
12
13 // AssetIssue asset issue params
14 type AssetIssue struct {
15         NonceStr           string
16         IssuanceProgramStr string
17         AssetDefinitionStr string
18         AssetIDStr         string
19         Amount             uint64
20 }
21
22 func (a *AssetIssue) nonce() []byte {
23         bs, err := hex.DecodeString(a.NonceStr)
24         if err != nil {
25                 panic(err)
26         }
27
28         return bs
29 }
30
31 func (a *AssetIssue) issuanceProgram() []byte {
32         bs, err := hex.DecodeString(a.IssuanceProgramStr)
33         if err != nil {
34                 panic(err)
35         }
36
37         return bs
38 }
39
40 func (a *AssetIssue) assetDefinition() []byte {
41         bs, err := hex.DecodeString(a.AssetDefinitionStr)
42         if err != nil {
43                 panic(err)
44         }
45
46         return bs
47 }
48
49 func (a *AssetIssue) id() bc.AssetID {
50         var bs [32]byte
51         bytes, err := hex.DecodeString(a.AssetIDStr)
52         if err != nil {
53                 panic(err)
54         }
55
56         copy(bs[:], bytes)
57         return bc.NewAssetID(bs)
58 }
59
60 // GenesisTxs make genesis block txs
61 func GenesisTxs() []*types.Tx {
62         contract, err := hex.DecodeString("00148dea804c8f5a27518be2696e43dca0352b9a93cc")
63         if err != nil {
64                 log.Panicf("fail on decode genesis tx output control program")
65         }
66
67         var txs []*types.Tx
68         firstTxData := types.TxData{
69                 Version: 1,
70                 Inputs:  []*types.TxInput{types.NewCoinbaseInput([]byte("Information is power. -- Jan/11/2013. Computing is power. -- Apr/24/2018."))},
71                 Outputs: []*types.TxOutput{types.NewOriginalTxOutput(*consensus.BTMAssetID, consensus.InitBTMSupply, contract, nil)},
72         }
73         txs = append(txs, types.NewTx(firstTxData))
74
75         inputs := []*types.TxInput{}
76         outputs := []*types.TxOutput{}
77         for _, asset := range assetIssues {
78                 inputs = append(inputs, types.NewIssuanceInput(asset.nonce(), asset.Amount, asset.issuanceProgram(), nil, asset.assetDefinition()))
79                 outputs = append(outputs, types.NewOriginalTxOutput(asset.id(), asset.Amount, contract, nil))
80         }
81
82         secondTxData := types.TxData{Version: 1, Inputs: inputs, Outputs: outputs}
83         txs = append(txs, types.NewTx(secondTxData))
84         return txs
85 }
86
87 var assetIssues = []*AssetIssue{
88         {
89                 NonceStr:           "f57f15fbbdf5f70d",
90                 IssuanceProgramStr: "0354df07cda069ae203c939b7ba615a49adf57b5b4c9c37e80666436970f8507d56a272539cabcb9e15151ad",
91                 AssetDefinitionStr: "7b0a202022646563696d616c73223a20382c0a2020226465736372697074696f6e223a207b7d2c0a2020226e616d65223a2022535550222c0a20202271756f72756d223a20312c0a20202272656973737565223a202266616c7365222c0a20202273796d626f6c223a2022535550220a7d",
92                 AssetIDStr:         "47fcd4d7c22d1d38931a6cd7767156babbd5f05bbbb3f7d3900635b56eb1b67e",
93                 Amount:             9877601291045,
94         },
95         {
96                 NonceStr:           "8e972359c6441299",
97                 IssuanceProgramStr: "ae20d66ab117eca2bba6aefed569e52d6bf68a7a4ad7d775cbc01f7b2cfcd798f7b22031ab3c2147c330c5e360b4e585047d1dea5f529476ad5aff475ecdd55541923120851b4a24975df6dbeb4f8e5348542764f85bed67b763875325aa5e45116751b35253ad",
98                 AssetDefinitionStr: "7b0a202022646563696d616c73223a20382c0a2020226465736372697074696f6e223a207b7d2c0a2020226e616d65223a20224d4147222c0a20202271756f72756d223a20322c0a20202272656973737565223a202274727565222c0a20202273796d626f6c223a20224d4147220a7d",
99                 AssetIDStr:         "a0a71c215764e342d10d003be6369baf4145d9c7977f7b8f6bf446e628d8b8b8",
100                 Amount:             100000000000000,
101         },
102 }