本文整理匯總了Golang中github.com/c-darwin/dcoin-go/packages/dcparser.Parser.TxSlice方法的典型用法代碼示例。如果您正苦於以下問題:Golang Parser.TxSlice方法的具體用法?Golang Parser.TxSlice怎麽用?Golang Parser.TxSlice使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/c-darwin/dcoin-go/packages/dcparser.Parser
的用法示例。
在下文中一共展示了Parser.TxSlice方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
f, err := os.OpenFile("dclog.txt", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0777)
defer f.Close()
log.SetOutput(f)
log.SetFlags(log.LstdFlags | log.Lshortfile)
dir, err := utils.GetCurrentDir()
if err != nil {
log.Fatal(err)
}
config, err := configparser.Read(dir + "/config.ini")
if err != nil {
log.Fatal(err)
}
configIni, err := config.Section("main")
txType := "NewHolidays"
txTime := "1426283713"
blockData := make(map[string]string)
var txSlice []string
// hash
txSlice = append(txSlice, "22cb812e53e22ee539af4a1d39b4596d")
// type
txSlice = append(txSlice, strconv.Itoa(int(TypeInt(txType))))
// time
txSlice = append(txSlice, txTime)
// user_id
txSlice = append(txSlice, strconv.FormatInt(1, 10))
//start
txSlice = append(txSlice, strconv.FormatInt(100000, 10))
//end
txSlice = append(txSlice, strconv.FormatInt(4545, 10))
// sign
txSlice = append(txSlice, "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")
blockData["block_id"] = strconv.FormatInt(185510, 10)
blockData["time"] = txTime
blockData["user_id"] = strconv.FormatInt(1, 10)
//fmt.Println(txSlice)
parser := new(dcparser.Parser)
parser.DCDB = utils.NewDbConnect(configIni)
parser.TxSlice = txSlice
parser.BlockData = blockData
/*for i:=0; i<10000; i++ {
x := func() {
stmt, err := parser.DCDB.Prepare(`INSERT INTO main_lock(lock_time,script_name) VALUES($1,$2)`)
defer stmt.Close()
if err!=nil {
fmt.Println(err)
}
_, err = stmt.Exec(11111, "testblock_generator")
if err!=nil {
fmt.Println(err)
}
}
x()
//stmt, _ := parser.DCDB.Prepare(`INSERT INTO main_lock(lock_time,script_name) VALUES($1,$2)`)
//fmt.Println(err)
//defer stmt.Close()
//_, _ = stmt.Exec(11111, "testblock_generator")
//fmt.Println(err)
//_, _ = parser.DCDB.Query("INSERT INTO main_lock(lock_time,script_name) VALUES($1,$2)", 11111, "testblock_generator")
x2 := func() {
row, err := parser.DCDB.Query("DELETE FROM main_lock WHERE script_name='testblock_generator'")
defer row.Close()
if err!=nil {
fmt.Println(err)
}
}
x2()
//parser.DCDB.DbLock()
//parser.DCDB.DbUnlock()
//fmt.Println(i)
}*/
fmt.Println()
err = dcparser.MakeTest(parser, txType, hashesStart)
if err != nil {
fmt.Println("err", err)
}
//go daemons.Testblock_is_ready()
//parser.Db.HashTableData("holidays", "", "")
//HashTableData(parser.Db.DB,"holidays", "", "")
//hashes, err := parser.Db.AllHashes()
utils.CheckErr(err)
//fmt.Println(hashes)
fmt.Println()
/*
var ptr reflect.Value
var value reflect.Value
//var finalMethod reflect.Value
i := Test{Start: "start"}
//.........這裏部分代碼省略.........
示例2: 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
}
示例3: main
func main() {
f, err := os.OpenFile("dclog.txt", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0777)
defer f.Close()
log.SetOutput(f)
log.SetFlags(log.LstdFlags | log.Lshortfile)
txType := "NewPct"
txTime := "1426283713"
userId := []byte("1")
var txSlice [][]byte
// hash
txSlice = append(txSlice, []byte("22cb812e53e22ee539af4a1d39b4596d"))
// type
txSlice = append(txSlice, utils.Int64ToByte(TypeInt(txType)))
// time
txSlice = append(txSlice, []byte(txTime))
// user_id
txSlice = append(txSlice, userId)
//new_pct
txSlice = append(txSlice, []byte(`{"1":{"miner_pct":"0.0000000044318","user_pct":"0.0000000027036"},"72":{"miner_pct":"0.0000000047610","user_pct":"0.0000000029646"}}`))
// sign
txSlice = append(txSlice, []byte("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"))
blockData := new(utils.BlockData)
blockData.BlockId = 1200
blockData.Time = utils.StrToInt64(txTime)
blockData.UserId = 1
dir, err := utils.GetCurrentDir()
if err != nil {
fmt.Println(err)
}
configIni_, err := config.NewConfig("ini", dir+"/config.ini")
if err != nil {
fmt.Println(err)
}
configIni, err := configIni_.GetSection("default")
db := utils.DbConnect(configIni)
parser := new(dcparser.Parser)
parser.DCDB = db
parser.TxSlice = txSlice
parser.BlockData = blockData
// делаем снимок БД в виде хэшей до начала тестов
hashesStart, err := parser.AllHashes()
err = dcparser.MakeTest(parser, txType, hashesStart)
if err != nil {
fmt.Println(err)
}
//go daemons.Testblock_is_ready()
//parser.Db.HashTableData("holidays", "", "")
//HashTableData(parser.Db.DB,"holidays", "", "")
//hashes, err := parser.Db.AllHashes()
utils.CheckErr(err)
//fmt.Println(hashes)
fmt.Println()
}
示例4: 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
}