OSDN Git Service

Merge pull request #132 from Bytom/dev
[bytom/bytom-spv.git] / consensus / general.go
1 package consensus
2
3 import (
4         "strings"
5
6         "github.com/bytom/protocol/bc"
7 )
8
9 //consensus variables
10 const (
11         // define the Max transaction size and Max block size
12         MaxTxSize    = uint64(1024)
13         MaxBlockSzie = uint64(16384)
14
15         //config parameter for coinbase reward
16         CoinbasePendingBlockNumber = uint64(6)
17         subsidyReductionInterval   = uint64(560640)
18         baseSubsidy                = uint64(624000000000)
19         initialBlockSubsidy        = uint64(1470000000000000000)
20
21         // config for pow mining
22         powMinBits            = uint64(2161727821138738707)
23         BlocksPerRetarget     = uint64(1024)
24         targetSecondsPerBlock = uint64(60)
25 )
26
27 // BTMAssetID is BTM's asset id, the soul asset of Bytom
28 var BTMAssetID = &bc.AssetID{
29         V0: uint64(18446744073709551615),
30         V1: uint64(18446744073709551615),
31         V2: uint64(18446744073709551615),
32         V3: uint64(18446744073709551615),
33 }
34
35 // BlockSubsidy calculate the coinbase rewards on given block height
36 func BlockSubsidy(height uint64) uint64 {
37         if height == 1 {
38                 return initialBlockSubsidy
39         }
40         return baseSubsidy >> uint(height/subsidyReductionInterval)
41 }
42
43 // IsBech32SegwitPrefix returns whether the prefix is a known prefix for segwit
44 // addresses on any default or registered network.  This is used when decoding
45 // an address string into a specific address type.
46 func IsBech32SegwitPrefix(prefix string, params *Params) bool {
47         prefix = strings.ToLower(prefix)
48         return prefix == params.Bech32HRPSegwit+"1"
49 }
50
51 // Params store the config for different network
52 type Params struct {
53         // Name defines a human-readable identifier for the network.
54         Name            string
55         Bech32HRPSegwit string
56 }
57
58 // MainNetParams is the config for production
59 var MainNetParams = Params{
60         Name:            "main",
61         Bech32HRPSegwit: "bm",
62 }
63
64 // TestNetParams is the config for test-net
65 var TestNetParams = Params{
66         Name:            "test",
67         Bech32HRPSegwit: "tm",
68 }