Skip to content

Commit aa1ae1f

Browse files
authored
Merge pull request #701 from iotexproject/tx-hash
query task, return send router tx
2 parents 86f404f + 4fb66ea commit aa1ae1f

File tree

9 files changed

+131
-72
lines changed

9 files changed

+131
-72
lines changed

cmd/apinode/api/http.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type StateLog struct {
4747
State string `json:"state"`
4848
Time time.Time `json:"time"`
4949
Comment string `json:"comment,omitempty"`
50+
Tx string `json:"transaction_hash,omitempty"`
5051
ProverID string `json:"prover_id,omitempty"`
5152
}
5253

@@ -164,7 +165,7 @@ func (s *httpServer) queryTask(c *gin.Context) {
164165
}
165166
resp.States = append(resp.States, &StateLog{
166167
State: "assigned",
167-
Time: t.CreatedAt,
168+
Time: ta.CreatedAt,
168169
ProverID: "did:io:" + strings.TrimPrefix(ta.Prover.String(), "0x"),
169170
})
170171

@@ -180,8 +181,9 @@ func (s *httpServer) queryTask(c *gin.Context) {
180181
}
181182
resp.States = append(resp.States, &StateLog{
182183
State: "settled",
183-
Time: t.CreatedAt,
184+
Time: ts.CreatedAt,
184185
Comment: "The task has been completed. Please check the generated proof in the corresponding DApp contract.",
186+
Tx: ts.Tx.String(),
185187
})
186188
c.JSON(http.StatusOK, resp)
187189
}

cmd/apinode/persistence/postgres.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type SettledTask struct {
5050
gorm.Model
5151
TaskID common.Hash `gorm:"uniqueIndex:settled_task_uniq,not null"`
5252
ProjectID uint64 `gorm:"uniqueIndex:settled_task_uniq,not null"`
53+
Tx common.Hash `gorm:"not null"`
5354
}
5455

5556
type Persistence struct {
@@ -165,14 +166,15 @@ func (p *Persistence) UpsertAssignedTask(projectID uint64, taskID common.Hash, p
165166
return errors.Wrap(err, "failed to upsert assigned task")
166167
}
167168

168-
func (p *Persistence) UpsertSettledTask(projectID uint64, taskID common.Hash) error {
169+
func (p *Persistence) UpsertSettledTask(projectID uint64, taskID, tx common.Hash) error {
169170
t := SettledTask{
170171
ProjectID: projectID,
171172
TaskID: taskID,
173+
Tx: tx,
172174
}
173175
err := p.db.Clauses(clause.OnConflict{
174176
Columns: []clause.Column{{Name: "task_id"}, {Name: "project_id"}},
175-
DoNothing: true,
177+
DoUpdates: clause.AssignmentColumns([]string{"tx"}),
176178
}).Create(&t).Error
177179
return errors.Wrap(err, "failed to upsert settled task")
178180
}

cmd/prover/db/db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (p *DB) ProcessTask(projectID uint64, taskID common.Hash) error {
136136
return errors.Wrap(err, "failed to update task")
137137
}
138138

139-
func (p *DB) DeleteTask(projectID uint64, taskID common.Hash) error {
139+
func (p *DB) DeleteTask(projectID uint64, taskID, tx common.Hash) error {
140140
err := p.db.Where("task_id = ?", taskID).Where("project_id = ?", projectID).Delete(&task{}).Error
141141
return errors.Wrap(err, "failed to delete task")
142142
}

cmd/prover/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func main() {
7979
log.Fatal(errors.Wrap(err, "failed to connect datasource"))
8080
}
8181

82-
if err := processor.Run(vmHandler.Handle, projectManager.Project, db, datasource.Retrieve, prv, cfg.ChainEndpoint, common.HexToAddress(cfg.RouterContractAddr), common.HexToAddress(cfg.TaskManagerContractAddr)); err != nil {
82+
if err := processor.Run(vmHandler.Handle, projectManager.Project, db, datasource.Retrieve, prv, cfg.ChainEndpoint, common.HexToAddress(cfg.RouterContractAddr)); err != nil {
8383
log.Fatal(errors.Wrap(err, "failed to run task processor"))
8484
}
8585

cmd/sequencer/db/db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (p *DB) AssignTask(projectID uint64, taskID common.Hash, prover common.Addr
154154
return errors.Wrap(err, "failed to assign task")
155155
}
156156

157-
func (p *DB) DeleteTask(projectID uint64, taskID common.Hash) error {
157+
func (p *DB) DeleteTask(projectID uint64, taskID, tx common.Hash) error {
158158
err := p.db.Where("task_id = ?", taskID).Where("project_id = ?", projectID).Delete(&task{}).Error
159159
return errors.Wrap(err, "failed to delete task")
160160
}

monitor/monitor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type (
2929
UpsertNBits func(uint32) error
3030
UpsertBlockHead func(uint64, common.Hash) error
3131
AssignTask func(uint64, common.Hash, common.Address) error
32-
SettleTask func(uint64, common.Hash) error
32+
SettleTask func(uint64, common.Hash, common.Hash) error
3333
UpsertProject func(uint64, string, common.Hash) error
3434
UpsertProver func(uint64, common.Address) error
3535
)
@@ -158,7 +158,7 @@ func (c *contract) processLogs(logs []types.Log) error {
158158
if err != nil {
159159
return errors.Wrap(err, "failed to parse task settled event")
160160
}
161-
if err := c.h.SettleTask(e.ProjectId.Uint64(), e.TaskId); err != nil {
161+
if err := c.h.SettleTask(e.ProjectId.Uint64(), e.TaskId, l.TxHash); err != nil {
162162
return err
163163
}
164164
case projectConfigUpdatedTopic:

smartcontracts/go/router/router.abi

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,44 @@
195195
"internalType": "bytes",
196196
"name": "_data",
197197
"type": "bytes"
198+
},
199+
{
200+
"internalType": "bytes32",
201+
"name": "_taskId",
202+
"type": "bytes32"
198203
}
199204
],
200205
"name": "route",
201206
"outputs": [],
202207
"stateMutability": "nonpayable",
203208
"type": "function"
204209
},
210+
{
211+
"inputs": [
212+
{
213+
"internalType": "address",
214+
"name": "_add",
215+
"type": "address"
216+
}
217+
],
218+
"name": "setTaskManager",
219+
"outputs": [],
220+
"stateMutability": "nonpayable",
221+
"type": "function"
222+
},
223+
{
224+
"inputs": [],
225+
"name": "taskManager",
226+
"outputs": [
227+
{
228+
"internalType": "address",
229+
"name": "",
230+
"type": "address"
231+
}
232+
],
233+
"stateMutability": "view",
234+
"type": "function"
235+
},
205236
{
206237
"inputs": [
207238
{

smartcontracts/go/router/router.go

Lines changed: 65 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)