本文整理汇总了Golang中github.com/decred/dcrd/blockchain/stake.TicketDB.DumpMapsPointer方法的典型用法代码示例。如果您正苦于以下问题:Golang TicketDB.DumpMapsPointer方法的具体用法?Golang TicketDB.DumpMapsPointer怎么用?Golang TicketDB.DumpMapsPointer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/decred/dcrd/blockchain/stake.TicketDB
的用法示例。
在下文中一共展示了TicketDB.DumpMapsPointer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: cloneTicketDB
// cloneTicketDB makes a deep copy of a ticket DB by
// serializing it to a gob and then deserializing it
// into an empty container.
func cloneTicketDB(tmdb *stake.TicketDB) (stake.TicketMaps, error) {
mapsPointer := tmdb.DumpMapsPointer()
mapsBytes, err := mapsPointer.GobEncode()
if err != nil {
return stake.TicketMaps{},
fmt.Errorf("clone db error: could not serialize ticketMaps")
}
var mapsCopy stake.TicketMaps
if err := mapsCopy.GobDecode(mapsBytes); err != nil {
return stake.TicketMaps{},
fmt.Errorf("clone db error: could not deserialize " +
"ticketMaps")
}
return mapsCopy, nil
}
示例2: TestTicketDB
//.........这里部分代码省略.........
for _, idx := range ts {
ticketsToSpendIn167 =
append(ticketsToSpendIn167, sortedTickets167[idx].SStxHash)
}
// Make sure that the tickets that were supposed to be spent or
// missed were.
spentTix, err := tmdb.DumpSpentTickets(i)
if err != nil {
t.Errorf("DumpSpentTickets failure")
}
for _, h := range ticketsToSpendIn167 {
if _, ok := spentTix[h]; !ok {
t.Errorf("missing ticket %v that should have been missed "+
"or spent in block %v", h, i)
}
}
// Create snapshot of tmdb at block 168
CopyOfMapsAtBlock168, err = cloneTicketDB(&tmdb)
if err != nil {
t.Errorf("db cloning at block 168 failure! %v", err)
}
}
}
// Remove five blocks from HEAD~1
_, _, _, err = tmdb.RemoveBlockToHeight(50)
if err != nil {
t.Errorf("error: %v", err)
}
// Test if the roll back was symmetric to the earlier snapshot
if !reflect.DeepEqual(tmdb.DumpMapsPointer(), CopyOfMapsAtBlock50) {
t.Errorf("The td did not restore to a previous block height correctly!")
}
// Test rescanning a ticket db
err = tmdb.RescanTicketDB()
if err != nil {
t.Errorf("rescanticketdb err: %v", err.Error())
}
// Test if the db file storage was symmetric to the earlier snapshot
if !reflect.DeepEqual(tmdb.DumpMapsPointer(), CopyOfMapsAtBlock168) {
t.Errorf("The td did not rescan to HEAD correctly!")
}
err = os.Mkdir("testdata/", os.FileMode(0700))
if err != nil {
t.Error(err)
}
// Store the ticket db to disk
err = tmdb.Store("testdata/", "testtmdb")
if err != nil {
t.Errorf("error: %v", err)
}
var tmdb2 stake.TicketDB
err = tmdb2.LoadTicketDBs("testdata/", "testtmdb", simNetParams, database)
if err != nil {
t.Errorf("error: %v", err)
}
// Test if the db file storage was symmetric to previously rescanned one