本文整理汇总了Golang中github.com/c-darwin/dcoin-go/packages/dcparser.Parser.GoroutineName方法的典型用法代码示例。如果您正苦于以下问题:Golang Parser.GoroutineName方法的具体用法?Golang Parser.GoroutineName怎么用?Golang Parser.GoroutineName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/c-darwin/dcoin-go/packages/dcparser.Parser
的用法示例。
在下文中一共展示了Parser.GoroutineName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: QueueParserBlocks
func QueueParserBlocks(chBreaker chan bool, chAnswer chan string) {
defer func() {
if r := recover(); r != nil {
log.Error("daemon Recovered", r)
panic(r)
}
}()
const GoroutineName = "QueueParserBlocks"
d := new(daemon)
d.DCDB = DbConnect(chBreaker, chAnswer, GoroutineName)
if d.DCDB == nil {
return
}
d.goRoutineName = GoroutineName
d.chAnswer = chAnswer
d.chBreaker = chBreaker
if utils.Mobile() {
d.sleepTime = 1800
} else {
d.sleepTime = 10
}
if !d.CheckInstall(chBreaker, chAnswer, GoroutineName) {
return
}
d.DCDB = DbConnect(chBreaker, chAnswer, GoroutineName)
if d.DCDB == nil {
return
}
BEGIN:
for {
log.Info(GoroutineName)
MonitorDaemonCh <- []string{GoroutineName, utils.Int64ToStr(utils.Time())}
// проверим, не нужно ли нам выйти из цикла
if CheckDaemonsRestart(chBreaker, chAnswer, GoroutineName) {
break BEGIN
}
err, restart := d.dbLock()
if restart {
break BEGIN
}
if err != nil {
if d.dPrintSleep(err, d.sleepTime) {
break BEGIN
}
continue BEGIN
}
prevBlockData, err := d.OneRow("SELECT * FROM info_block").String()
if err != nil {
if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) {
break BEGIN
}
continue BEGIN
}
newBlockData, err := d.OneRow("SELECT * FROM queue_blocks").String()
if err != nil {
if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) {
break BEGIN
}
continue BEGIN
}
if len(newBlockData) == 0 {
if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) {
break BEGIN
}
continue BEGIN
}
newBlockData["head_hash_hex"] = string(utils.BinToHex(newBlockData["head_hash"]))
prevBlockData["head_hash_hex"] = string(utils.BinToHex(prevBlockData["head_hash"]))
newBlockData["hash_hex"] = string(utils.BinToHex(newBlockData["hash"]))
prevBlockData["hash_hex"] = string(utils.BinToHex(prevBlockData["hash"]))
variables, err := d.GetAllVariables()
if err != nil {
if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) {
break BEGIN
}
continue BEGIN
}
/*
* Базовая проверка
*/
// проверим, укладывается ли блок в лимит rollback_blocks_1
if utils.StrToInt64(newBlockData["block_id"]) > utils.StrToInt64(prevBlockData["block_id"])+variables.Int64["rollback_blocks_1"] {
d.DeleteQueueBlock(newBlockData["head_hash_hex"], newBlockData["hash_hex"])
if d.unlockPrintSleep(utils.ErrInfo("rollback_blocks_1"), 1) {
break BEGIN
}
continue BEGIN
}
// проверим не старый ли блок в очереди
if utils.StrToInt64(newBlockData["block_id"]) < utils.StrToInt64(prevBlockData["block_id"]) {
d.DeleteQueueBlock(newBlockData["head_hash_hex"], newBlockData["hash_hex"])
//.........这里部分代码省略.........
示例2: BlocksCollection
func BlocksCollection(chBreaker chan bool, chAnswer chan string) {
defer func() {
if r := recover(); r != nil {
log.Error("daemon Recovered", r)
panic(r)
}
}()
const GoroutineName = "BlocksCollection"
d := new(daemon)
d.DCDB = DbConnect(chBreaker, chAnswer, GoroutineName)
if d.DCDB == nil {
return
}
d.goRoutineName = GoroutineName
d.chAnswer = chAnswer
d.chBreaker = chBreaker
if utils.Mobile() {
d.sleepTime = 300
} else {
d.sleepTime = 60
}
if !d.CheckInstall(chBreaker, chAnswer, GoroutineName) {
return
}
d.DCDB = DbConnect(chBreaker, chAnswer, GoroutineName)
if d.DCDB == nil {
return
}
//var cur bool
BEGIN:
for {
log.Info(GoroutineName)
MonitorDaemonCh <- []string{GoroutineName, utils.Int64ToStr(utils.Time())}
// проверим, не нужно ли нам выйти из цикла
if CheckDaemonsRestart(chBreaker, chAnswer, GoroutineName) {
break BEGIN
}
log.Debug("0")
config, err := d.GetNodeConfig()
if err != nil {
if d.dPrintSleep(err, d.sleepTime) {
break BEGIN
}
continue BEGIN
}
log.Debug("1")
err, restart := d.dbLock()
if restart {
log.Debug("restart true")
break BEGIN
}
if err != nil {
log.Debug("restart err %v", err)
if d.dPrintSleep(err, d.sleepTime) {
break BEGIN
}
continue BEGIN
}
log.Debug("2")
// если это первый запуск во время инсталяции
currentBlockId, err := d.GetBlockId()
if err != nil {
if d.unlockPrintSleep(err, d.sleepTime) {
break BEGIN
}
continue BEGIN
}
log.Info("config", config)
log.Info("currentBlockId", currentBlockId)
// на время тестов
/*if !cur {
currentBlockId = 0
cur = true
}*/
parser := new(dcparser.Parser)
parser.DCDB = d.DCDB
parser.GoroutineName = GoroutineName
if currentBlockId == 0 || *utils.StartBlockId > 0 {
/*
IsNotExistBlockChain := false
if _, err := os.Stat(*utils.Dir+"/public/blockchain"); os.IsNotExist(err) {
IsNotExistBlockChain = true
}*/
if config["first_load_blockchain"] == "file" /* && IsNotExistBlockChain*/ {
log.Info("first_load_blockchain=file")
nodeConfig, err := d.GetNodeConfig()
blockchain_url := nodeConfig["first_load_blockchain_url"]
if len(blockchain_url) == 0 {
blockchain_url = consts.BLOCKCHAIN_URL
}
log.Debug("blockchain_url: %s", blockchain_url)
// возможно сервер отдаст блокчейн не с первой попытки
var blockchainSize int64
//.........这里部分代码省略.........
示例3: 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
}