本文整理匯總了Golang中github.com/NebulousLabs/Sia/modules.ConsensusSet.ConsensusSetSubscribe方法的典型用法代碼示例。如果您正苦於以下問題:Golang ConsensusSet.ConsensusSetSubscribe方法的具體用法?Golang ConsensusSet.ConsensusSetSubscribe怎麽用?Golang ConsensusSet.ConsensusSetSubscribe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/NebulousLabs/Sia/modules.ConsensusSet
的用法示例。
在下文中一共展示了ConsensusSet.ConsensusSetSubscribe方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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 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{
blocksDifficulty: types.RootDepth,
blockHashes: make(map[types.BlockID]types.BlockHeight),
blockTargets: make(map[types.BlockID]types.Target),
transactionHashes: make(map[types.TransactionID]types.BlockHeight),
unlockHashes: make(map[types.UnlockHash]map[types.TransactionID]struct{}),
siacoinOutputIDs: make(map[types.SiacoinOutputID]map[types.TransactionID]struct{}),
siacoinOutputs: make(map[types.SiacoinOutputID]types.SiacoinOutput),
fileContractIDs: make(map[types.FileContractID]map[types.TransactionID]struct{}),
fileContractHistories: make(map[types.FileContractID]*fileContractHistory),
siafundOutputIDs: make(map[types.SiafundOutputID]map[types.TransactionID]struct{}),
siafundOutputs: make(map[types.SiafundOutputID]types.SiafundOutput),
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
}
示例3: New
// New creates a transaction pool that is ready to receive transactions.
func New(cs modules.ConsensusSet, g modules.Gateway) (*TransactionPool, error) {
// Check that the input modules are non-nil.
if cs == nil {
return nil, errNilCS
}
if g == nil {
return nil, errNilGateway
}
// Initialize a transaction pool.
tp := &TransactionPool{
consensusSet: cs,
gateway: g,
knownObjects: make(map[ObjectID]TransactionSetID),
transactionSets: make(map[TransactionSetID][]types.Transaction),
transactionSetDiffs: make(map[TransactionSetID]modules.ConsensusChange),
// The consensus change index is intialized to '-1', which indicates
// that no consensus changes have been sent yet. The first consensus
// change will then have an index of '0'.
consensusChangeIndex: -1,
mu: sync.New(modules.SafeMutexDelay, 5),
}
// Register RPCs
g.RegisterRPC("RelayTransactionSet", tp.RelayTransactionSet)
g.RegisterRPC("RelayTransaction", tp.RelayTransaction) // COMPAT v0.3.3.3
// Subscribe the transaction pool to the consensus set.
cs.ConsensusSetSubscribe(tp)
return tp, nil
}
示例4: 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{
cs: cs,
persistDir: persistDir,
}
// Initialize the persistent structures, including the database.
err := e.initPersist()
if err != nil {
return nil, err
}
// retrieve the current ConsensusChangeID
var recentChange modules.ConsensusChangeID
err = e.db.View(dbGetInternal(internalRecentChange, &recentChange))
if err != nil {
return nil, err
}
err = cs.ConsensusSetSubscribe(e, recentChange)
if err != nil {
// TODO: restart from 0
return nil, errors.New("explorer subscription failed: " + err.Error())
}
return e, nil
}
示例5: newAnnouncementFinder
// newAnnouncementFinder will create and return an announcement finder.
func newAnnouncementFinder(cs modules.ConsensusSet) (*announcementFinder, error) {
af := &announcementFinder{
cs: cs,
}
err := cs.ConsensusSetSubscribe(af, modules.ConsensusChangeBeginning)
if err != nil {
return nil, err
}
return af, nil
}
示例6: New
// New returns an empty renter.
func New(cs modules.ConsensusSet, hdb modules.HostDB, wallet modules.Wallet, tpool modules.TransactionPool, persistDir string) (*Renter, error) {
if cs == nil {
return nil, ErrNilCS
}
if hdb == nil {
return nil, ErrNilHostDB
}
if wallet == nil {
return nil, ErrNilWallet
}
if tpool == nil {
return nil, ErrNilTpool
}
r := &Renter{
cs: cs,
hostDB: hdb,
wallet: wallet,
tpool: tpool,
files: make(map[string]*file),
contracts: make(map[types.FileContractID]types.FileContract),
repairSet: make(map[string]string),
persistDir: persistDir,
mu: sync.New(modules.SafeMutexDelay, 1),
}
_, err := rand.Read(r.entropy[:])
if err != nil {
return nil, err
}
err = r.initPersist()
if err != nil {
return nil, err
}
cs.ConsensusSetSubscribe(r)
go r.threadedRepairUploads()
return r, nil
}
示例7: New
// New creates and starts up a hostdb. The hostdb that gets returned will not
// have finished scanning the network or blockchain.
func New(cs modules.ConsensusSet, wallet modules.Wallet, tpool modules.TransactionPool, persistDir string) (*HostDB, error) {
if cs == nil {
return nil, errNilCS
}
if wallet == nil {
return nil, errNilWallet
}
if tpool == nil {
return nil, errNilTpool
}
hdb := &HostDB{
cs: cs,
wallet: wallet,
tpool: tpool,
contracts: make(map[types.FileContractID]hostContract),
activeHosts: make(map[modules.NetAddress]*hostNode),
allHosts: make(map[modules.NetAddress]*hostEntry),
scanPool: make(chan *hostEntry, scanPoolSize),
persistDir: persistDir,
}
err := hdb.initPersist()
if err != nil {
return nil, err
}
// Begin listening to consensus and looking for hosts.
for i := 0; i < scanningThreads; i++ {
go hdb.threadedProbeHosts()
}
go hdb.threadedScan()
cs.ConsensusSetSubscribe(hdb)
return hdb, nil
}
示例8: 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
}
示例9: New
// New creates a transaction pool that is ready to receive transactions.
func New(cs modules.ConsensusSet, g modules.Gateway) (tp *TransactionPool, err error) {
// Check that the input modules are non-nil.
if cs == nil {
err = errors.New("transaction pool cannot use a nil state")
return
}
if g == nil {
err = errors.New("transaction pool cannot use a nil gateway")
return
}
// Initialize a transaction pool.
tp = &TransactionPool{
consensusSet: cs,
gateway: g,
transactions: make(map[crypto.Hash]struct{}),
siacoinOutputs: make(map[types.SiacoinOutputID]types.SiacoinOutput),
fileContracts: make(map[types.FileContractID]types.FileContract),
siafundOutputs: make(map[types.SiafundOutputID]types.SiafundOutput),
referenceSiacoinOutputs: make(map[types.SiacoinOutputID]types.SiacoinOutput),
referenceFileContracts: make(map[types.FileContractID]types.FileContract),
referenceSiafundOutputs: make(map[types.SiafundOutputID]types.SiafundOutput),
mu: sync.New(modules.SafeMutexDelay, 1),
}
// Register RPCs
g.RegisterRPC("RelayTransaction", tp.RelayTransaction)
// Subscribe the transaction pool to the consensus set.
cs.ConsensusSetSubscribe(tp)
return
}
示例10: New
// New creates and starts up a hostdb. The hostdb that gets returned will not
// have finished scanning the network or blockchain.
func New(cs modules.ConsensusSet, g modules.Gateway, persistDir string) (*HostDB, error) {
// Check for nil dependencies.
if cs == nil {
return nil, errNilConsensusSet
}
if g == nil {
return nil, errNilGateway
}
// Build an empty hostdb.
hdb := &HostDB{
consensusSet: cs,
gateway: g,
activeHosts: make(map[modules.NetAddress]*hostNode),
allHosts: make(map[modules.NetAddress]*hostEntry),
scanPool: make(chan *hostEntry, scanPoolSize),
persistDir: persistDir,
mu: sync.New(modules.SafeMutexDelay, 1),
}
err := hdb.initPersist()
if err != nil {
return nil, err
}
// Begin listening to consensus and looking for hosts.
for i := 0; i < scanningThreads; i++ {
go hdb.threadedProbeHosts()
}
go hdb.threadedScan()
cs.ConsensusSetSubscribe(hdb)
return hdb, nil
}