OSDN Git Service

Native segwit (#283)
[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(1048576)
13         MaxBlockSzie = uint64(10485760)
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         PayToWitnessPubKeyHashDataSize = 20
27         PayToWitnessScriptHashDataSize = 32
28 )
29
30 // BTMAssetID is BTM's asset id, the soul asset of Bytom
31 var BTMAssetID = &bc.AssetID{
32         V0: uint64(18446744073709551615),
33         V1: uint64(18446744073709551615),
34         V2: uint64(18446744073709551615),
35         V3: uint64(18446744073709551615),
36 }
37
38 // BlockSubsidy calculate the coinbase rewards on given block height
39 func BlockSubsidy(height uint64) uint64 {
40         if height == 0 {
41                 return InitialBlockSubsidy
42         }
43         return baseSubsidy >> uint(height/subsidyReductionInterval)
44 }
45
46 // IsBech32SegwitPrefix returns whether the prefix is a known prefix for segwit
47 // addresses on any default or registered network.  This is used when decoding
48 // an address string into a specific address type.
49 func IsBech32SegwitPrefix(prefix string, params *Params) bool {
50         prefix = strings.ToLower(prefix)
51         return prefix == params.Bech32HRPSegwit+"1"
52 }
53
54 // Params store the config for different network
55 type Params struct {
56         // Name defines a human-readable identifier for the network.
57         Name            string
58         Bech32HRPSegwit string
59 }
60
61 // MainNetParams is the config for production
62 var MainNetParams = Params{
63         Name:            "main",
64         Bech32HRPSegwit: "bm",
65 }
66
67 // TestNetParams is the config for test-net
68 var TestNetParams = Params{
69         Name:            "test",
70         Bech32HRPSegwit: "tm",
71 }