Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sdk-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
sdk-api
Commits
4773d4b8
Commit
4773d4b8
authored
Jul 22, 2024
by
贾浩@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update log
parent
a8871496
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
53 deletions
+53
-53
executer.go
executor/executer.go
+53
-53
No files found.
executor/executer.go
View file @
4773d4b8
...
...
@@ -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
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment