当前位置: 首页>>代码示例>>Golang>>正文


Golang TicketDB.DumpMapsPointer方法代码示例

本文整理汇总了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
}
开发者ID:alexlyp,项目名称:dcrd,代码行数:20,代码来源:ticketdb_test.go

示例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
开发者ID:alexlyp,项目名称:dcrd,代码行数:67,代码来源:ticketdb_test.go


注:本文中的github.com/decred/dcrd/blockchain/stake.TicketDB.DumpMapsPointer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。