Commit 4773d4b8 authored by 贾浩@五瓣科技's avatar 贾浩@五瓣科技

update log

parent a8871496
......@@ -42,6 +42,59 @@ func (e *Executor) Start() {
}
func (e *Executor) ProcessTransaction() {
log.Info("start process transaction")
ticker := time.NewTicker(200 * time.Millisecond)
defer ticker.Stop()
for {
tasks, err := e.d.GetNotExecutedTasks()
if err != nil {
log.WithError(err).Error("get not executed tasks failed")
time.Sleep(time.Millisecond * 500)
continue
}
for _, task := range tasks {
e.Lock()
nonce := e.nonces[common.HexToAddress(e.c.Chain.SenderAddress)]
e.Unlock()
val, _ := new(big.Int).SetString(task.Value, 10)
txHash, sent, err := e.d.BroadcastTx(
common.HexToAddress(task.ToAddress),
nonce,
val,
common.FromHex(task.Calldata),
)
if sent {
e.Lock()
e.nonces[common.HexToAddress(e.c.Chain.SenderAddress)]++
e.Unlock()
}
// 交易成功
if err == nil {
err = e.d.UpdateTaskStatus(task.TaskId, txHash.String(), constant.TransactionPending)
if err != nil {
log.WithFields(log.Fields{"taskId": task.TaskId, "err": err}).Error("update task status failed")
continue
}
log.WithFields(log.Fields{"taskId": task.TaskId, "nonce": nonce, "action": task.Action, "txHash": txHash}).Info("broadcast tx success")
continue
}
// 交易失败
log.WithFields(log.Fields{"taskId": task.TaskId, "err": err}).Error("broadcast tx failed")
err = e.d.UpdateTaskStatus(task.TaskId, "", constant.TransactionBroadcastError)
if err != nil {
log.WithFields(log.Fields{"taskId": task.TaskId, "err": err}).Error("update task status failed")
}
}
<-ticker.C
}
}
func (e *Executor) ProcessReceipt(sync bool) {
// sync:true 启动时运行
log.WithField("sync", sync).Info("start process receipt")
......@@ -95,56 +148,3 @@ func (e *Executor) ProcessReceipt(sync bool) {
<-ticker.C
}
}
func (e *Executor) ProcessTransaction() {
log.Info("start process transaction")
ticker := time.NewTicker(200 * time.Millisecond)
defer ticker.Stop()
for {
tasks, err := e.d.GetNotExecutedTasks()
if err != nil {
log.WithError(err).Error("get not executed tasks failed")
time.Sleep(time.Millisecond * 500)
continue
}
for _, task := range tasks {
e.Lock()
nonce := e.nonces[common.HexToAddress(e.c.Chain.SenderAddress)]
e.Unlock()
val, _ := new(big.Int).SetString(task.Value, 10)
txHash, sent, err := e.d.BroadcastTx(
common.HexToAddress(task.ToAddress),
nonce,
val,
common.FromHex(task.Calldata),
)
if sent {
e.Lock()
e.nonces[common.HexToAddress(e.c.Chain.SenderAddress)]++
e.Unlock()
}
// 交易成功
if err == nil {
err = e.d.UpdateTaskStatus(task.TaskId, txHash.String(), constant.TransactionPending)
if err != nil {
log.WithFields(log.Fields{"taskId": task.TaskId, "err": err}).Error("update task status failed")
continue
}
log.WithFields(log.Fields{"taskId": task.TaskId, "action": task.Action, "txHash": txHash}).Info("broadcast tx success")
continue
}
// 交易失败
log.WithFields(log.Fields{"taskId": task.TaskId, "err": err}).Error("broadcast tx failed")
err = e.d.UpdateTaskStatus(task.TaskId, "", constant.TransactionBroadcastError)
if err != nil {
log.WithFields(log.Fields{"taskId": task.TaskId, "err": err}).Error("update task status failed")
}
}
<-ticker.C
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment