本文整理匯總了Golang中github.com/NebulousLabs/Sia/modules.ConsensusSet.GenesisBlock方法的典型用法代碼示例。如果您正苦於以下問題:Golang ConsensusSet.GenesisBlock方法的具體用法?Golang ConsensusSet.GenesisBlock怎麽用?Golang ConsensusSet.GenesisBlock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/NebulousLabs/Sia/modules.ConsensusSet
的用法示例。
在下文中一共展示了ConsensusSet.GenesisBlock方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: New
// New creates the internal data structures, and subscribes to
// consensus for changes to the blockchain
func New(cs modules.ConsensusSet, persistDir string) (*Explorer, error) {
// Check that input modules are non-nil
if cs == nil {
return nil, errNilCS
}
// Initialize the explorer.
e := &Explorer{
currentBlock: cs.GenesisBlock(),
genesisBlockID: cs.GenesisBlock().ID(),
seenTimes: make([]time.Time, types.MaturityDelay+1),
startTime: time.Now(),
cs: cs,
persistDir: persistDir,
}
e.blockchainHeight-- // Set to -1 so the genesis block sets the height to 0.
// Intialize the persistent structures, including the database.
err := e.initPersist()
if err != nil {
return nil, err
}
cs.ConsensusSetSubscribe(e)
return e, nil
}
示例2: New
// New returns a ready-to-go miner that is not mining.
func New(cs modules.ConsensusSet, tpool modules.TransactionPool, w modules.Wallet, persistDir string) (*Miner, error) {
// Create the miner and its dependencies.
if cs == nil {
return nil, errors.New("miner cannot use a nil state")
}
if tpool == nil {
return nil, errors.New("miner cannot use a nil transaction pool")
}
if w == nil {
return nil, errors.New("miner cannot use a nil wallet")
}
// Grab some starting block variables.
currentBlock := cs.GenesisBlock().ID()
currentTarget, exists1 := cs.ChildTarget(currentBlock)
earliestTimestamp, exists2 := cs.EarliestChildTimestamp(currentBlock)
if build.DEBUG {
if !exists1 {
panic("could not get child target")
}
if !exists2 {
panic("could not get child earliest timestamp")
}
}
addr, _, err := w.CoinAddress(false) // false indicates that the address should not be visible to the user.
if err != nil {
return nil, err
}
// Assemble the miner.
m := &Miner{
cs: cs,
tpool: tpool,
wallet: w,
parent: currentBlock,
target: currentTarget,
earliestTimestamp: earliestTimestamp,
address: addr,
blockMem: make(map[types.BlockHeader]types.Block),
headerMem: make([]types.BlockHeader, headerForWorkMemory),
persistDir: persistDir,
mu: sync.New(modules.SafeMutexDelay, 1),
}
err = m.initPersist()
if err != nil {
return nil, err
}
m.tpool.TransactionPoolSubscribe(m)
return m, nil
}
示例3: New
// New returns a ready-to-go miner that is not mining.
func New(cs modules.ConsensusSet, tpool modules.TransactionPool, w modules.Wallet, persistDir string) (*Miner, error) {
// Create the miner and its dependencies.
if cs == nil {
return nil, errors.New("miner cannot use a nil state")
}
if tpool == nil {
return nil, errors.New("miner cannot use a nil transaction pool")
}
if w == nil {
return nil, errors.New("miner cannot use a nil wallet")
}
// Grab some starting block variables.
currentBlock := cs.GenesisBlock().ID()
currentTarget, exists1 := cs.ChildTarget(currentBlock)
earliestTimestamp, exists2 := cs.EarliestChildTimestamp(currentBlock)
if build.DEBUG {
if !exists1 {
panic("could not get child target")
}
if !exists2 {
panic("could not get child earliest timestamp")
}
}
// Assemble the miner. The miner is assembled without an address because
// the wallet is likely not unlocked yet. The miner will grab an address
// after the miner is unlocked (this must be coded manually for each
// function that potentially requires the miner to have an address.
m := &Miner{
cs: cs,
tpool: tpool,
wallet: w,
parent: currentBlock,
target: currentTarget,
earliestTimestamp: earliestTimestamp,
blockMem: make(map[types.BlockHeader]*types.Block),
arbDataMem: make(map[types.BlockHeader][]byte),
headerMem: make([]types.BlockHeader, headerForWorkMemory),
persistDir: persistDir,
mu: sync.New(modules.SafeMutexDelay, 1),
}
err := m.initPersist()
if err != nil {
return nil, err
}
m.tpool.TransactionPoolSubscribe(m)
return m, nil
}
示例4: New
// New creates the internal data structures, and subscribes to
// consensus for changes to the blockchain
func New(cs modules.ConsensusSet) (be *BlockExplorer, err error) {
// Check that input modules are non-nil
if cs == nil {
err = errors.New("Blockchain explorer cannot use a nil ConsensusSet")
return
}
// Initilize the module state
be = &BlockExplorer{
currentBlock: cs.GenesisBlock(),
genesisBlockID: cs.GenesisBlock().ID(),
blockchainHeight: 0,
currencySent: types.NewCurrency64(0),
activeContractCost: types.NewCurrency64(0),
totalContractCost: types.NewCurrency64(0),
cs: cs,
mu: sync.New(modules.SafeMutexDelay, 1),
}
cs.ConsensusSetSubscribe(be)
return
}