本文整理匯總了Golang中github.com/c-darwin/dcoin-go/packages/dcparser.Parser.TxHash方法的典型用法代碼示例。如果您正苦於以下問題:Golang Parser.TxHash方法的具體用法?Golang Parser.TxHash怎麽用?Golang Parser.TxHash使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/c-darwin/dcoin-go/packages/dcparser.Parser
的用法示例。
在下文中一共展示了Parser.TxHash方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: MakeTest
func MakeTest(txSlice [][]byte, blockData *utils.BlockData, txType string, testType string) error {
db := DbConn()
parser := new(dcparser.Parser)
parser.DCDB = db
parser.TxSlice = txSlice
parser.BlockData = blockData
parser.TxHash = []byte("111111111111111")
parser.Variables, _ = db.GetAllVariables()
// делаем снимок БД в виде хэшей до начала тестов
hashesStart, err := AllHashes(db)
if err != nil {
return err
}
//fmt.Println("dcparser."+txType+"Init")
err0 := utils.CallMethod(parser, txType+"Init")
if i, ok := err0.(error); ok {
fmt.Println(err0.(error), i)
return err0.(error)
}
if testType == "work_and_rollback" {
err0 = utils.CallMethod(parser, txType)
if i, ok := err0.(error); ok {
fmt.Println(err0.(error), i)
return err0.(error)
}
//fmt.Println("-------------------")
// узнаем, какие таблицы были затронуты в результате выполнения основного метода
hashesMiddle, err := AllHashes(db)
if err != nil {
return utils.ErrInfo(err)
}
var tables []string
//fmt.Println("hashesMiddle", hashesMiddle)
//fmt.Println("hashesStart", hashesStart)
for table, hash := range hashesMiddle {
if hash != hashesStart[table] {
tables = append(tables, table)
}
}
fmt.Println("tables", tables)
// rollback
err0 := utils.CallMethod(parser, txType+"Rollback")
if i, ok := err0.(error); ok {
fmt.Println(err0.(error), i)
return err0.(error)
}
// сраниим хэши, которые были до начала и те, что получились после роллбэка
hashesEnd, err := AllHashes(db)
if err != nil {
return utils.ErrInfo(err)
}
for table, hash := range hashesEnd {
if hash != hashesStart[table] {
fmt.Println("ERROR in table ", table)
}
}
} else if (len(os.Args) > 1 && os.Args[1] == "w") || testType == "work" {
err0 = utils.CallMethod(parser, txType)
if i, ok := err0.(error); ok {
fmt.Println(err0.(error), i)
return err0.(error)
}
} else if (len(os.Args) > 1 && os.Args[1] == "r") || testType == "rollback" {
err0 = utils.CallMethod(parser, txType+"Rollback")
if i, ok := err0.(error); ok {
fmt.Println(err0.(error), i)
return err0.(error)
}
}
return nil
}
示例2: MakeFrontTest
func MakeFrontTest(transactionArray [][]byte, time int64, dataForSign string, txType string, userId int64, MY_PREFIX string, blockId int64) error {
db := DbConn()
priv, pub := genKeys()
nodeArr := []string{"new_admin", "votes_node_new_miner", "NewPct"}
var binSign []byte
if utils.InSliceString(txType, nodeArr) {
err := db.ExecSql("UPDATE my_node_keys SET private_key = ?", priv)
if err != nil {
return utils.ErrInfo(err)
}
err = db.ExecSql("UPDATE miners_data SET node_public_key = [hex] WHERE user_id = ?", pub, userId)
if err != nil {
return utils.ErrInfo(err)
}
k, err := db.GetNodePrivateKey(MY_PREFIX)
if err != nil {
return utils.ErrInfo(err)
}
fmt.Println("k", k)
privateKey, err := utils.MakePrivateKey(k)
if err != nil {
return utils.ErrInfo(err)
}
//fmt.Println("privateKey.PublicKey", privateKey.PublicKey)
//fmt.Println("privateKey.D", privateKey.D)
//fmt.Printf("privateKey.N %x\n", privateKey.N)
//fmt.Println("privateKey.Public", privateKey.Public())
binSign, err = rsa.SignPKCS1v15(rand.Reader, privateKey, crypto.SHA1, utils.HashSha1(dataForSign))
//nodePublicKey, err := db.GetNodePublicKey(userId)
//fmt.Println("nodePublicKey", nodePublicKey)
//if err != nil {
// return utils.ErrInfo(err)
//}
//CheckSignResult, err := utils.CheckSign([][]byte{nodePublicKey}, dataForSign, binSign, true);
//fmt.Printf("binSign: %x\n", binSign)
//fmt.Println("err", err)
//fmt.Println("CheckSignResult", CheckSignResult)
} else {
err := db.ExecSql("UPDATE my_keys SET private_key = ?", priv)
if err != nil {
return utils.ErrInfo(err)
}
err = db.ExecSql("UPDATE users SET public_key_0 = [hex]", pub)
if err != nil {
return utils.ErrInfo(err)
}
k, err := db.GetPrivateKey(MY_PREFIX)
privateKey, err := utils.MakePrivateKey(k)
if err != nil {
return utils.ErrInfo(err)
}
binSign, err = rsa.SignPKCS1v15(rand.Reader, privateKey, crypto.SHA1, utils.HashSha1(dataForSign))
binSign = utils.EncodeLengthPlusData(binSign)
}
//fmt.Println("HashSha1", utils.HashSha1(dataForSign))
//fmt.Printf("binSign %x\n", binSign)
//fmt.Println("dataForSign", dataForSign)
transactionArray = append(transactionArray, binSign)
parser := new(dcparser.Parser)
parser.DCDB = db
parser.GoroutineName = "test"
parser.TxSlice = transactionArray
parser.BlockData = &utils.BlockData{BlockId: blockId, Time: time, UserId: userId}
parser.TxHash = []byte("111111111111111")
parser.Variables, _ = parser.DCDB.GetAllVariables()
err0 := utils.CallMethod(parser, txType+"Init")
if i, ok := err0.(error); ok {
fmt.Println(err0.(error), i)
return err0.(error)
}
err0 = utils.CallMethod(parser, txType+"Front")
if i, ok := err0.(error); ok {
fmt.Println(err0.(error), i)
return err0.(error)
}
err0 = utils.CallMethod(parser, txType+"RollbackFront")
if i, ok := err0.(error); ok {
fmt.Println(err0.(error), i)
return err0.(error)
}
return nil
}