本文整理匯總了Golang中github.com/NebulousLabs/Sia/modules.ConsensusSet.ConsensusSetPersistentSubscribe方法的典型用法代碼示例。如果您正苦於以下問題:Golang ConsensusSet.ConsensusSetPersistentSubscribe方法的具體用法?Golang ConsensusSet.ConsensusSetPersistentSubscribe怎麽用?Golang ConsensusSet.ConsensusSetPersistentSubscribe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/NebulousLabs/Sia/modules.ConsensusSet
的用法示例。
在下文中一共展示了ConsensusSet.ConsensusSetPersistentSubscribe方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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,
}
// Register RPCs
g.RegisterRPC("RelayTransactionSet", tp.relayTransactionSet)
// Subscribe the transaction pool to the consensus set.
cs.ConsensusSetPersistentSubscribe(tp, modules.ConsensusChangeID{})
return tp, 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.ConsensusSetPersistentSubscribe(e, modules.ConsensusChangeID{})
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,
}
// Register RPCs
// TODO: rename RelayTransactionSet so that the conflicting RPC
// RelayTransaction calls v0.4.6 clients and earlier are ignored.
g.RegisterRPC("RelayTransactionSet", tp.relayTransactionSet)
// Subscribe the transaction pool to the consensus set.
err := cs.ConsensusSetPersistentSubscribe(tp, modules.ConsensusChangeID{})
if err != nil {
return nil, errors.New("transactionpool subscription failed: " + err.Error())
}
return tp, nil
}