chaincfg

package
Version: v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2018 License: ISC Imports: 9 Imported by: 40

README

chaincfg

ISC License GoDoc

Package chaincfg defines chain configuration parameters for the three standard Hcd networks and provides the ability for callers to define their own custom Hcd networks.

Although this package was primarily written for hcd, it has intentionally been designed so it can be used as a standalone package for any projects needing to use parameters for the standard Hcd networks or for projects needing to define their own network.

Sample Use

package main

import (
	"flag"
	"fmt"
	"log"

	"github.com/coolsnady/hcutil"
	"github.com/coolsnady/hcd/chaincfg"
)

var testnet = flag.Bool("testnet", false, "operate on the testnet Hcd network")

// By default (without -testnet), use mainnet.
var chainParams = &chaincfg.MainNetParams

func main() {
	flag.Parse()

	// Modify active network parameters if operating on testnet.
	if *testnet {
		chainParams = &chaincfg.TestNetParams
	}

	// later...

	// Create and print new payment address, specific to the active network.
	pubKeyHash := make([]byte, 20)
	addr, err := btcutil.NewAddressPubKeyHash(pubKeyHash, chainParams)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(addr)
}

Installation and Updating

$ go get -u github.com/coolsnady/hcd/chaincfg

License

Package chaincfg is licensed under the copyfree ISC License.

Documentation

Overview

Package chaincfg defines chain configuration parameters.

In addition to the main Hcd network, which is intended for the transfer of monetary value, there also exists two currently active standard networks: regression test and testnet (version 0). These networks are incompatible with each other (each sharing a different genesis block) and software should handle errors where input intended for one network is used on an application instance running on a different network.

For library packages, chaincfg provides the ability to lookup chain parameters and encoding magics when passed a *Params. Older APIs not updated to the new convention of passing a *Params may lookup the parameters for a wire.DecredNet using ParamsForNet, but be aware that this usage is deprecated and will be removed from chaincfg in the future.

For main packages, a (typically global) var may be assigned the address of one of the standard Param vars for use as the application's "active" network. When a network parameter is needed, it may then be looked up through this variable (either directly, or hidden in a library call).

package main

import (
        "flag"
        "fmt"
        "log"

        "github.com/coolsnady/hcutil"
        "github.com/coolsnady/hcd/chaincfg"
)

var testnet = flag.Bool("testnet", false, "operate on the testnet Hcd network")

// By default (without -testnet), use mainnet.
var chainParams = &chaincfg.MainNetParams

func main() {
        flag.Parse()

        // Modify active network parameters if operating on testnet.
        if *testnet {
                chainParams = &chaincfg.TestNetParams
        }

        // later...

        // Create and print new payment address, specific to the active network.
        pubKeyHash := make([]byte, 20)
        addr, err := hcutil.NewAddressPubKeyHash(pubKeyHash, chainParams)
        if err != nil {
                log.Fatal(err)
        }
        fmt.Println(addr)
}

If an application does not use one of the three standard Hcd networks, a new Params struct may be created which defines the parameters for the non-standard network. As a general rule of thumb, all network parameters should be unique to the network, but parameter collisions can still occur (unfortunately, this is the case with regtest and testnet sharing magics).

Index

Constants

View Source
const (
	// VoteIDMaxBlockSize is the vote ID for the the maximum block size
	// increase agenda used for the hard fork demo.
	VoteIDMaxBlockSize = "maxblocksize"
)

Variables

View Source
var (
	ErrDuplicateVoteId  = errors.New("duplicate vote id")
	ErrInvalidMask      = errors.New("invalid mask")
	ErrNotConsecutive   = errors.New("choices not consecutive")
	ErrTooManyChoices   = errors.New("too many choices")
	ErrInvalidAbstain   = errors.New("invalid abstain bits")
	ErrInvalidBits      = errors.New("invalid vote bits")
	ErrInvalidIsAbstain = errors.New("one and only one IsAbstain rule " +
		"violation")
	ErrInvalidIsNo      = errors.New("one and only one IsNo rule violation")
	ErrInvalidBothFlags = errors.New("IsNo and IsAbstain may not be both " +
		"set to true")
	ErrDuplicateChoiceId = errors.New("duplicate choice ID")
)
View Source
var (
	// ErrDuplicateNet describes an error where the parameters for a Hcd
	// network could not be set due to the network already being a standard
	// network or previously-registered into this package.
	ErrDuplicateNet = errors.New("duplicate Hc network")

	// ErrUnknownHDKeyID describes an error where the provided id which
	// is intended to identify the network for a hierarchical deterministic
	// private extended key is not registered.
	ErrUnknownHDKeyID = errors.New("unknown hd private extended key bytes")
)
View Source
var BlockOneLedgerMainNet = []*TokenPayout{
	{"HsJwqHsbVjb4SdgdYQBDxcWQCsyJxiJMqda", 4000000 * 1e8},
	{"HsH2U86zVmqT6p17fsfxhx7CP5w73XhHcs3", 4000000 * 1e8},
	{"HsLhsSN5ziYgK9XQosx8VjM59wEZjXAuzZC", 4000000 * 1e8},
	{"HsPo3AJrYgtvHwpqQKNCEkrTPrLcY1irMqe", 4000000 * 1e8},
	{"HsKrJGTiQKERFQmTu3UPN8c8toUgquMiY2i", 4000000 * 1e8},
	{"HsJvzUrW3fcDbxCskspHYCj6zbRS6aDcDw1", 4000000 * 1e8},
	{"HsFf124jsfwNaUwbrDU22BcuKJjim7nF6Y3", 4000000 * 1e8},
	{"HsMJiuGD5afsr37yKrHUtkXoZTCCoj5sPMb", 4000000 * 1e8},
	{"HsGXZUDR3L35TXH7UNXMhCTuRpNVHF6BsNr", 4000000 * 1e8},
	{"HsNRWXPC7bRrfCakNNXF3izJoyQXTTNg8ik", 4000000 * 1e8},
	{"HsLBVmVQ3RhdrqFJWJoFY8qEH31iKwtuapL", 4478231 * 1e8},
}

BlockOneLedgerMainNet is the block one output ledger for the main network.

View Source
var BlockOneLedgerSimNet = []*TokenPayout{
	{"Sshw6S86G2bV6W32cbc7EhtFy8f93rU6pae", 100000 * 1e8},
	{"SsjXRK6Xz6CFuBt6PugBvrkdAa4xGbcZ18w", 100000 * 1e8},
	{"SsfXiYkYkCoo31CuVQw428N6wWKus2ZEw5X", 100000 * 1e8},
}

BlockOneLedgerSimNet is the block one output ledger for the simulation network. See under "Hcd organization related parameters" in params.go for information on how to spend these outputs.

View Source
var BlockOneLedgerTestNet = []*TokenPayout{
	{"TspAtg3jUAieeHhR9wgWso5CET3tZxQmvLq", 40000000 * 1e8},
}

BlockOneLedgerTestNet is the block one output ledger for the test network.

View Source
var BlockOneLedgerTestNet2 = []*TokenPayout{
	{"TspAtg3jUAieeHhR9wgWso5CET3tZxQmvLq", 40000000 * 1e8},
}

BlockOneLedgerTestNet2 is the block one output ledger for the 2nd test network.

View Source
var CPUMinerThreads = 1

CPUMinerThreads is the default number of threads to utilize with the CPUMiner when mining.

View Source
var CheckForDuplicateHashes = false

CheckForDuplicateHashes checks for duplicate hashes when validating blocks. Because of the rule inserting the height into the second (nonce) txOut, there should never be a duplicate transaction hash that overwrites another. However, because there is a 2^128 chance of a collision, the paranoid user may wish to turn this feature on.

View Source
var MainNetParams = Params{
	Name:        "mainnet",
	Net:         wire.MainNet,
	DefaultPort: "14008",
	DNSSeeds:    []string{},

	GenesisBlock:             &genesisBlock,
	GenesisHash:              &genesisHash,
	PowLimit:                 mainPowLimit,
	PowLimitBits:             0x1d00ffff,
	ReduceMinDifficulty:      false,
	MinDiffReductionTime:     0,
	GenerateSupported:        false,
	MaximumBlockSizes:        []int{393216},
	MaxTxSize:                393216,
	TargetTimePerBlock:       time.Second * 150,
	WorkDiffAlpha:            1,
	WorkDiffWindowSize:       144,
	WorkDiffWindows:          20,
	TargetTimespan:           time.Minute * 360,
	RetargetAdjustmentFactor: 4,

	BaseSubsidy:              640000000,
	MulSubsidy:               999,
	DivSubsidy:               1000,
	SubsidyReductionInterval: 12288,
	WorkRewardProportion:     6,
	StakeRewardProportion:    3,
	BlockTaxProportion:       1,

	Checkpoints: []Checkpoint{},

	RuleChangeActivationQuorum:     4032,
	RuleChangeActivationMultiplier: 3,
	RuleChangeActivationDivisor:    4,
	RuleChangeActivationInterval:   2016 * 4,
	Deployments:                    map[uint32][]ConsensusDeployment{},

	BlockEnforceNumRequired: 750,
	BlockRejectNumRequired:  950,
	BlockUpgradeNumToCheck:  1000,

	RelayNonStdTxs: false,

	NetworkAddressPrefix: "H",
	PubKeyAddrID:         [2]byte{0x19, 0xa4},
	PubKeyBlissAddrID:    [2]byte{0x07, 0xc3},
	PubKeyHashAddrID:     [2]byte{0x09, 0x7f},
	PKHEdwardsAddrID:     [2]byte{0x09, 0x60},
	PKHSchnorrAddrID:     [2]byte{0x09, 0x41},
	PKHBlissAddrID:       [2]byte{0x09, 0x58},
	ScriptHashAddrID:     [2]byte{0x09, 0x5a},
	PrivateKeyID:         [2]byte{0x19, 0xab},

	HDPrivateKeyID: [4]byte{0x02, 0xfd, 0xa4, 0xe8},
	HDPublicKeyID:  [4]byte{0x02, 0xfd, 0xa9, 0x26},

	HDCoinType: uint32(171),

	MinimumStakeDiff:        2 * 1e8,
	TicketPoolSize:          8192,
	TicketsPerBlock:         5,
	TicketMaturity:          256,
	TicketExpiry:            40960,
	CoinbaseMaturity:        256,
	SStxChangeMaturity:      1,
	TicketPoolSizeWeight:    4,
	StakeDiffAlpha:          1,
	StakeDiffWindowSize:     144,
	StakeDiffWindows:        20,
	StakeVersionInterval:    144 * 2 * 7,
	MaxFreshStakePerBlock:   20,
	StakeEnabledHeight:      256 + 256,
	StakeValidationHeight:   4096,
	StakeBaseSigScript:      []byte{0x00, 0x00},
	StakeMajorityMultiplier: 3,
	StakeMajorityDivisor:    4,

	OrganizationPkScript:        hexDecode("a914f5916158e3e2c4551c1796708db8367207ed13bb87"),
	OrganizationPkScriptVersion: 0,
	BlockOneLedger:              BlockOneLedgerMainNet,
}

MainNetParams defines the network parameters for the main Hcd network.

View Source
var SigHashOptimization = false

SigHashOptimization is an optimization for verification of transactions that do CHECKSIG operations with hashType SIGHASH_ALL. Although there should be no consequences to daemons that are simply running a node, it may be the case that you could cause database corruption if you turn this code on, create and manipulate your own MsgTx, then include them in blocks. For safety, if you're using the daemon with wallet or mining with the daemon this should be disabled. If you believe that any MsgTxs in your daemon will be used mutably, do NOT turn on this feature. It is disabled by default. This feature is considered EXPERIMENTAL, enable at your own risk!

View Source
var SimNetParams = Params{
	Name:        "simnet",
	Net:         wire.SimNet,
	DefaultPort: "13008",
	DNSSeeds:    []string{},

	GenesisBlock:             &simNetGenesisBlock,
	GenesisHash:              &simNetGenesisHash,
	PowLimit:                 simNetPowLimit,
	PowLimitBits:             0x207fffff,
	ReduceMinDifficulty:      false,
	MinDiffReductionTime:     0,
	GenerateSupported:        true,
	MaximumBlockSizes:        []int{1000000, 1310720},
	MaxTxSize:                2048000,
	TargetTimePerBlock:       time.Second,
	WorkDiffAlpha:            1,
	WorkDiffWindowSize:       8,
	WorkDiffWindows:          4,
	TargetTimespan:           time.Second * 8,
	RetargetAdjustmentFactor: 4,

	BaseSubsidy:              640000000,
	MulSubsidy:               999,
	DivSubsidy:               1000,
	SubsidyReductionInterval: 128,
	WorkRewardProportion:     6,
	StakeRewardProportion:    3,
	BlockTaxProportion:       1,

	Checkpoints: nil,

	RuleChangeActivationQuorum:     160,
	RuleChangeActivationMultiplier: 3,
	RuleChangeActivationDivisor:    4,
	RuleChangeActivationInterval:   320,
	Deployments: map[uint32][]ConsensusDeployment{
		4: {{
			Vote: Vote{
				Id:          VoteIDMaxBlockSize,
				Description: "Change maximum allowed block size from 1MiB to 1.25MB",
				Mask:        0x0006,
				Choices: []Choice{{
					Id:          "abstain",
					Description: "abstain voting for change",
					Bits:        0x0000,
					IsAbstain:   true,
					IsNo:        false,
				}, {
					Id:          "no",
					Description: "reject changing max allowed block size",
					Bits:        0x0002,
					IsAbstain:   false,
					IsNo:        true,
				}, {
					Id:          "yes",
					Description: "accept changing max allowed block size",
					Bits:        0x0004,
					IsAbstain:   false,
					IsNo:        false,
				}},
			},
			StartTime:  0,
			ExpireTime: math.MaxInt64,
		}},
	},

	BlockEnforceNumRequired: 51,
	BlockRejectNumRequired:  75,
	BlockUpgradeNumToCheck:  100,

	RelayNonStdTxs: true,

	NetworkAddressPrefix: "S",
	PubKeyAddrID:         [2]byte{0x27, 0x6f},
	PubKeyBlissAddrID:    [2]byte{0x0b, 0xef},
	PubKeyHashAddrID:     [2]byte{0x0e, 0x91},
	PKHEdwardsAddrID:     [2]byte{0x0e, 0x71},
	PKHSchnorrAddrID:     [2]byte{0x0e, 0x53},
	PKHBlissAddrID:       [2]byte{0x0e, 0x68},
	ScriptHashAddrID:     [2]byte{0x0e, 0x6c},
	PrivateKeyID:         [2]byte{0x23, 0x07},

	HDPrivateKeyID: [4]byte{0x04, 0x20, 0xb9, 0x03},
	HDPublicKeyID:  [4]byte{0x04, 0x20, 0xbd, 0x3d},

	HDCoinType: uint32(171),

	MinimumStakeDiff:        20000,
	TicketPoolSize:          64,
	TicketsPerBlock:         5,
	TicketMaturity:          16,
	TicketExpiry:            384,
	CoinbaseMaturity:        16,
	SStxChangeMaturity:      1,
	TicketPoolSizeWeight:    4,
	StakeDiffAlpha:          1,
	StakeDiffWindowSize:     8,
	StakeDiffWindows:        8,
	StakeVersionInterval:    8 * 2 * 7,
	MaxFreshStakePerBlock:   20,
	StakeEnabledHeight:      16 + 16,
	StakeValidationHeight:   16 + (64 * 2),
	StakeBaseSigScript:      []byte{0xDE, 0xAD, 0xBE, 0xEF},
	StakeMajorityMultiplier: 3,
	StakeMajorityDivisor:    4,

	OrganizationPkScript:        hexDecode("a914cbb08d6ca783b533b2c7d24a51fbca92d937bf9987"),
	OrganizationPkScriptVersion: 0,
	BlockOneLedger:              BlockOneLedgerSimNet,
}

SimNetParams defines the network parameters for the simulation test Hcd network. This network is similar to the normal test network except it is intended for private use within a group of individuals doing simulation testing. The functionality is intended to differ in that the only nodes which are specifically specified are used to create the network rather than following normal discovery rules. This is important as otherwise it would just turn into another public testnet.

View Source
var TestNet2Params = Params{
	Name:        "testnet2",
	Net:         wire.TestNet2,
	DefaultPort: "12008",
	DNSSeeds: []string{
		"testnet1.h.cash",
		"testnet2.h.cash",
		"testnet3.h.cash",
	},

	GenesisBlock:             &testNet2GenesisBlock,
	GenesisHash:              &testNet2GenesisHash,
	PowLimit:                 testNetPowLimit,
	PowLimitBits:             0x1e00ffff,
	ReduceMinDifficulty:      false,
	MinDiffReductionTime:     0,
	GenerateSupported:        true,
	MaximumBlockSizes:        []int{1310720},
	MaxTxSize:                1000000,
	TargetTimePerBlock:       time.Minute,
	WorkDiffAlpha:            1,
	WorkDiffWindowSize:       144,
	WorkDiffWindows:          20,
	TargetTimespan:           time.Minute * 144,
	RetargetAdjustmentFactor: 4,

	BaseSubsidy:              640000000,
	MulSubsidy:               999,
	DivSubsidy:               1000,
	SubsidyReductionInterval: 2048,
	WorkRewardProportion:     6,
	StakeRewardProportion:    3,
	BlockTaxProportion:       1,

	Checkpoints: []Checkpoint{},

	RuleChangeActivationQuorum:     2520,
	RuleChangeActivationMultiplier: 3,
	RuleChangeActivationDivisor:    4,
	RuleChangeActivationInterval:   5040,
	Deployments:                    map[uint32][]ConsensusDeployment{},

	BlockEnforceNumRequired: 51,
	BlockRejectNumRequired:  75,
	BlockUpgradeNumToCheck:  100,

	RelayNonStdTxs: true,

	NetworkAddressPrefix: "T",
	PubKeyAddrID:         [2]byte{0x28, 0xf7},
	PubKeyBlissAddrID:    [2]byte{0x0b, 0xf0},
	PubKeyHashAddrID:     [2]byte{0x0f, 0x21},
	PKHEdwardsAddrID:     [2]byte{0x0f, 0x01},
	PKHSchnorrAddrID:     [2]byte{0x0e, 0xe3},
	PKHBlissAddrID:       [2]byte{0x0e, 0xf9},
	ScriptHashAddrID:     [2]byte{0x0e, 0xfc},
	PrivateKeyID:         [2]byte{0x23, 0x0e},

	HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x97},
	HDPublicKeyID:  [4]byte{0x04, 0x35, 0x87, 0xd1},

	HDCoinType: uint32(171),

	MinimumStakeDiff:        20000000,
	TicketPoolSize:          1024,
	TicketsPerBlock:         5,
	TicketMaturity:          16,
	TicketExpiry:            6144,
	CoinbaseMaturity:        16,
	SStxChangeMaturity:      1,
	TicketPoolSizeWeight:    4,
	StakeDiffAlpha:          1,
	StakeDiffWindowSize:     144,
	StakeDiffWindows:        20,
	StakeVersionInterval:    144 * 2 * 7,
	MaxFreshStakePerBlock:   20,
	StakeEnabledHeight:      16 + 16,
	StakeValidationHeight:   775,
	StakeBaseSigScript:      []byte{0x00, 0x00},
	StakeMajorityMultiplier: 3,
	StakeMajorityDivisor:    4,

	OrganizationPkScript:        hexDecode("5221031377eb7eb294ba8d0c81bb64a047c9b36561f3899507679b38cfcbf59e016f9421036806c694f4d5d617259b5fabaf9ad84c20c2bf57b1a171fb6048215d6d71e13e52ae"),
	OrganizationPkScriptVersion: 0,
	BlockOneLedger:              BlockOneLedgerTestNet2,
}

TestNet2Params defines the network parameters for the test currency network. This network is sometimes simply called "testnet". This is the second public iteration of testnet.

View Source
var (
	VoteBitsNotFound = fmt.Errorf("vote bits not found")
)

These variables are the chain proof-of-work limit parameters for each default network.

Functions

func HDPrivateKeyToPublicKeyID

func HDPrivateKeyToPublicKeyID(id []byte) ([]byte, error)

HDPrivateKeyToPublicKeyID accepts a private hierarchical deterministic extended key id and returns the associated public key id. When the provided id is not registered, the ErrUnknownHDKeyID error will be returned.

func IsPKHEdwardsAddrID

func IsPKHEdwardsAddrID(id [2]byte) bool

IsPKHEdwardsAddrID returns whether the id is an identifier know to prefix a pay-to-pubkey-hash Edwards address.

func IsPKHSchnorrAddrID

func IsPKHSchnorrAddrID(id [2]byte) bool

IsPKHSchnorrAddrID returns whether the id is an identifier know to prefix a pay-to-pubkey-hash secp256k1 Schnorr address.

func IsPubKeyAddrID

func IsPubKeyAddrID(id [2]byte) bool

IsPubKeyAddrID returns whether the id is an identifier known to prefix a pay-to-pubkey address on any default or registered network.

func IsPubKeyHashAddrID

func IsPubKeyHashAddrID(id [2]byte) bool

IsPubKeyHashAddrID returns whether the id is an identifier known to prefix a pay-to-pubkey-hash address on any default or registered network. This is used when decoding an address string into a specific address type. It is up to the caller to check both this and IsScriptHashAddrID and decide whether an address is a pubkey hash address, script hash address, neither, or undeterminable (if both return true).

func IsScriptHashAddrID

func IsScriptHashAddrID(id [2]byte) bool

IsScriptHashAddrID returns whether the id is an identifier known to prefix a pay-to-script-hash address on any default or registered network. This is used when decoding an address string into a specific address type. It is up to the caller to check both this and IsPubKeyHashAddrID and decide whether an address is a pubkey hash address, script hash address, neither, or undeterminable (if both return true).

func Register

func Register(params *Params) error

Register registers the network parameters for a Hcd network. This may error with ErrDuplicateNet if the network is already registered (either due to a previous Register call, or the network being one of the default networks).

Network parameters should be registered into this package by a main package as early as possible. Then, library packages may lookup networks or network parameters based on inputs and work regardless of the network being standard or not.

Types

type Checkpoint

type Checkpoint struct {
	Height int64
	Hash   *chainhash.Hash
}

Checkpoint identifies a known good point in the block chain. Using checkpoints allows a few optimizations for old blocks during initial download and also prevents forks from old blocks.

Each checkpoint is selected based upon several factors. See the documentation for chain.IsCheckpointCandidate for details on the selection criteria.

type Choice

type Choice struct {
	// Single unique word identifying vote (e.g. yes)
	Id string

	// Longer description of the vote.
	Description string

	// Bits used for this vote.
	Bits uint16

	// This is the abstain choice.  By convention this must be the 0 vote
	// (abstain) and exist only once in the Vote.Choices array.
	IsAbstain bool

	// This coince indicates a hard No Vote.  By convention this must exist
	// only once in the Vote.Choices array.
	IsNo bool
}

Choice defines one of the possible Choices that make up a vote. The 0 value in Bits indicates the default choice. Care should be taken not to bias a vote with the default choice.

type ConsensusDeployment

type ConsensusDeployment struct {
	// Vote describes the what is being voted on and what the choices are.
	// This is sitting in a struct in order to make merging between btcd
	// easier.
	Vote Vote

	// StartTime is the median block time after which voting on the
	// deployment starts.
	StartTime uint64

	// ExpireTime is the median block time after which the attempted
	// deployment expires.
	ExpireTime uint64
}

ConsensusDeployment defines details related to a specific consensus rule change that is voted in. This is part of BIP0009.

type Params

type Params struct {
	// Name defines a human-readable identifier for the network.
	Name string

	// Net defines the magic bytes used to identify the network.
	Net wire.CurrencyNet

	// DefaultPort defines the default peer-to-peer port for the network.
	DefaultPort string

	// DNSSeeds defines a list of DNS seeds for the network that are used
	// as one method to discover peers.
	DNSSeeds []string

	// GenesisBlock defines the first block of the chain.
	GenesisBlock *wire.MsgBlock

	// GenesisHash is the starting block hash.
	GenesisHash *chainhash.Hash

	// PowLimit defines the highest allowed proof of work value for a block
	// as a uint256.
	PowLimit *big.Int

	// PowLimitBits defines the highest allowed proof of work value for a
	// block in compact form.
	PowLimitBits uint32

	// ReduceMinDifficulty defines whether the network should reduce the
	// minimum required difficulty after a long enough period of time has
	// passed without finding a block.  This is really only useful for test
	// networks and should not be set on a main network.
	ReduceMinDifficulty bool

	// MinDiffReductionTime is the amount of time after which the minimum
	// required difficulty should be reduced when a block hasn't been found.
	//
	// NOTE: This only applies if ReduceMinDifficulty is true.
	MinDiffReductionTime time.Duration

	// GenerateSupported specifies whether or not CPU mining is allowed.
	GenerateSupported bool

	// MaximumBlockSizes are the maximum sizes of a block that can be
	// generated on the network.  It is an array because the max block size
	// can be different values depending on the results of a voting agenda.
	// The first entry is the initial block size for the network, while the
	// other entries are potential block size changes which take effect when
	// the vote for the associated agenda succeeds.
	MaximumBlockSizes []int

	// MaxTxSize is the maximum number of bytes a serialized transaction can
	// be in order to be considered valid by consensus.
	MaxTxSize int

	// TargetTimePerBlock is the desired amount of time to generate each
	// block.
	TargetTimePerBlock time.Duration

	// WorkDiffAlpha is the stake difficulty EMA calculation alpha (smoothing)
	// value. It is different from a normal EMA alpha. Closer to 1 --> smoother.
	WorkDiffAlpha int64

	// WorkDiffWindowSize is the number of windows (intervals) used for calculation
	// of the exponentially weighted average.
	WorkDiffWindowSize int64

	// WorkDiffWindows is the number of windows (intervals) used for calculation
	// of the exponentially weighted average.
	WorkDiffWindows int64

	// TargetTimespan is the desired amount of time that should elapse
	// before the block difficulty requirement is examined to determine how
	// it should be changed in order to maintain the desired block
	// generation rate.  This value should correspond to the product of
	// WorkDiffWindowSize and TimePerBlock above.
	TargetTimespan time.Duration

	// RetargetAdjustmentFactor is the adjustment factor used to limit
	// the minimum and maximum amount of adjustment that can occur between
	// difficulty retargets.
	RetargetAdjustmentFactor int64

	// BaseSubsidy is the starting subsidy amount for mined blocks.
	BaseSubsidy int64

	// Subsidy reduction multiplier.
	MulSubsidy int64

	// Subsidy reduction divisor.
	DivSubsidy int64

	// SubsidyReductionInterval is the reduction interval in blocks.
	SubsidyReductionInterval int64

	// WorkRewardProportion is the comparative amount of the subsidy given for
	// creating a block.
	WorkRewardProportion uint16

	// StakeRewardProportion is the comparative amount of the subsidy given for
	// casting stake votes (collectively, per block).
	StakeRewardProportion uint16

	// BlockTaxProportion is the inverse of the percentage of funds for each
	// block to allocate to the developer organization.
	// e.g. 10% --> 10 (or 1 / (1/10))
	// Special case: disable taxes with a value of 0
	BlockTaxProportion uint16

	// Checkpoints ordered from oldest to newest.
	Checkpoints []Checkpoint

	// These fields are related to voting on consensus rule changes as
	// defined by BIP0009.
	//
	// RuleChangeActivationQurom is the number of votes required for a vote
	// to take effect.
	//
	// RuleChangeActivationInterval is the number of blocks in each threshold
	// state retarget window.
	//
	// Deployments define the specific consensus rule changes to be voted
	// on for the stake version (the map key).
	RuleChangeActivationQuorum     uint32
	RuleChangeActivationMultiplier uint32
	RuleChangeActivationDivisor    uint32
	RuleChangeActivationInterval   uint32
	Deployments                    map[uint32][]ConsensusDeployment

	// Enforce current block version once network has upgraded.
	BlockEnforceNumRequired uint64

	// Reject previous block versions once network has upgraded.
	BlockRejectNumRequired uint64

	// The number of nodes to check.
	BlockUpgradeNumToCheck uint64

	// Mempool parameters
	RelayNonStdTxs bool

	// NetworkAddressPrefix is the first letter of the network
	// for any given address encoded as a string.
	NetworkAddressPrefix string

	// Address encoding magics
	PubKeyAddrID      [2]byte // First 2 bytes of a P2PK address
	PubKeyBlissAddrID [2]byte // First 2 bytes of a P2PK bliss address
	PubKeyHashAddrID  [2]byte // First 2 bytes of a P2PKH address
	PKHEdwardsAddrID  [2]byte // First 2 bytes of an Edwards P2PKH address
	PKHSchnorrAddrID  [2]byte // First 2 bytes of a secp256k1 Schnorr P2PKH address
	PKHBlissAddrID    [2]byte // First 2 bytes of a Bliss P2PKH address
	ScriptHashAddrID  [2]byte // First 2 bytes of a P2SH address
	PrivateKeyID      [2]byte // First 2 bytes of a WIF private key

	// BIP32 hierarchical deterministic extended key magics
	HDPrivateKeyID [4]byte
	HDPublicKeyID  [4]byte

	// BIP44 coin type used in the hierarchical deterministic path for
	// address generation.
	HDCoinType uint32

	// MinimumStakeDiff if the minimum amount of Atoms required to purchase a
	// stake ticket.
	MinimumStakeDiff int64

	// Ticket pool sizes for Hcd PoS. This denotes the number of possible
	// buckets/number of different ticket numbers. It is also the number of
	// possible winner numbers there are.
	TicketPoolSize uint16

	// Average number of tickets per block for Hcd PoS.
	TicketsPerBlock uint16

	// Number of blocks for tickets to mature (spendable at TicketMaturity+1).
	TicketMaturity uint16

	// Number of blocks for tickets to expire after they have matured. This MUST
	// be >= (StakeEnabledHeight + StakeValidationHeight).
	TicketExpiry uint32

	// CoinbaseMaturity is the number of blocks required before newly mined
	// coins (coinbase transactions) can be spent.
	CoinbaseMaturity uint16

	// Maturity for spending SStx change outputs.
	SStxChangeMaturity uint16

	// TicketPoolSizeWeight is the multiplicative weight applied to the
	// ticket pool size difference between a window period and its target
	// when determining the stake system.
	TicketPoolSizeWeight uint16

	// StakeDiffAlpha is the stake difficulty EMA calculation alpha (smoothing)
	// value. It is different from a normal EMA alpha. Closer to 1 --> smoother.
	StakeDiffAlpha int64

	// StakeDiffWindowSize is the number of blocks used for each interval in
	// exponentially weighted average.
	StakeDiffWindowSize int64

	// StakeDiffWindows is the number of windows (intervals) used for calculation
	// of the exponentially weighted average.
	StakeDiffWindows int64

	// StakeVersionInterval determines the interval where the stake version
	// is calculated.
	StakeVersionInterval int64

	// MaxFreshStakePerBlock is the maximum number of new tickets that may be
	// submitted per block.
	MaxFreshStakePerBlock uint8

	// StakeEnabledHeight is the height in which the first ticket could possibly
	// mature.
	StakeEnabledHeight int64

	// StakeValidationHeight is the height at which votes (SSGen) are required
	// to add a new block to the top of the blockchain. This height is the
	// first block that will be voted on, but will include in itself no votes.
	StakeValidationHeight int64

	// StakeBaseSigScript is the consensus stakebase signature script for all
	// votes on the network. This isn't signed in any way, so without forcing
	// it to be this value miners/daemons could freely change it.
	StakeBaseSigScript []byte

	// StakeMajorityMultiplier and StakeMajorityDivisor are used
	// to calculate the super majority of stake votes using integer math as
	// such: X*StakeMajorityMultiplier/StakeMajorityDivisor
	StakeMajorityMultiplier int32
	StakeMajorityDivisor    int32

	// OrganizationPkScript is the output script for block taxes to be
	// distributed to in every block's coinbase. It should ideally be a P2SH
	// multisignature address.  OrganizationPkScriptVersion is the version
	// of the output script.  Until PoS hardforking is implemented, this
	// version must always match for a block to validate.
	OrganizationPkScript        []byte
	OrganizationPkScriptVersion uint16

	// BlockOneLedger specifies the list of payouts in the coinbase of
	// block height 1. If there are no payouts to be given, set this
	// to an empty slice.
	BlockOneLedger []*TokenPayout
}

Params defines a Hcd network by its parameters. These parameters may be used by Hcd applications to differentiate networks as well as addresses and keys for one network from those intended for use on another network.

func (*Params) BlockOneSubsidy

func (p *Params) BlockOneSubsidy() int64

BlockOneSubsidy returns the total subsidy of block height 1 for the network.

func (*Params) LatestCheckpointHeight

func (p *Params) LatestCheckpointHeight() int64

LatestCheckpointHeight is the height of the latest checkpoint block in the parameters.

func (*Params) TotalSubsidyProportions

func (p *Params) TotalSubsidyProportions() uint16

TotalSubsidyProportions is the sum of WorkReward, StakeReward, and BlockTax proportions.

type TokenPayout

type TokenPayout struct {
	Address string
	Amount  int64
}

TokenPayout is a payout for block 1 which specifies an address and an amount to pay to that address in a transaction output.

type Vote

type Vote struct {
	// Single unique word identifying the vote.
	Id string

	// Longer description of what the vote is about.
	Description string

	// Usable bits for this vote.
	Mask uint16

	Choices []Choice
}

Vote describes a voting instance. It is self-describing so that the UI can be directly implemented using the fields. Mask determines which bits can be used. Bits are enumerated and must be consecutive. Each vote requires one and only one abstain (bits = 0) and reject vote (IsNo = true).

For example, change block height from int64 to uint64. Vote {

Id:          "blockheight",
Description: "Change block height from int64 to uint64"
Mask:        0x0006,
Choices:     []Choice{
	{
		Id:          "abstain",
		Description: "abstain voting for change",
		Bits:        0x0000,
		IsAbstain:   true,
		IsNo:        false,
	},
	{
		Id:          "no",
		Description: "reject changing block height to uint64",
		Bits:        0x0002,
		IsAbstain:   false,
		IsNo:        false,
	},
	{
		Id:          "yes",
		Description: "accept changing block height to uint64",
		Bits:        0x0004,
		IsAbstain:   false,
		IsNo:        true,
	},
},

}

func (*Vote) VoteIndex

func (v *Vote) VoteIndex(vote uint16) int

VoteIndex compares vote to Choice.Bits and returns the index into the Choices array. If the vote is invalid it returns -1.

Directories

Path Synopsis
Package chainec provides wrapper functions to abstract the ec functions.
Package chainec provides wrapper functions to abstract the ec functions.
Package chainhash provides abstracted hash functionality.
Package chainhash provides abstracted hash functionality.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL