-
Notifications
You must be signed in to change notification settings - Fork 1
/
exec_del_local.go
66 lines (55 loc) · 2.06 KB
/
exec_del_local.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright Fuzamei Corp. 2018 All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
package executor
import (
"github.com/assetcloud/chain/types"
oty "github.com/assetcloud/plugin/plugin/dapp/oracle/types"
)
func (o *oracle) execDelLocal(receipt *types.ReceiptData) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
table := oty.NewTable(o.GetLocalDB())
for _, item := range receipt.Logs {
var oraclelog oty.ReceiptOracle
err := types.Decode(item.Log, &oraclelog)
if err != nil {
return nil, err
}
//回滚时如果状态为EventPublished则删除记录,否则回滚至上一状态
if oraclelog.Status == oty.EventPublished {
err = table.Del([]byte(oraclelog.EventID))
if err != nil {
return nil, err
}
} else {
oraclelog.Status = oraclelog.PreStatus
err = table.Replace(&oraclelog)
if err != nil {
return nil, err
}
}
kvs, err := table.Save()
if err != nil {
return nil, err
}
set.KV = append(set.KV, kvs...)
}
return set, nil
}
func (o *oracle) ExecDelLocal_EventPublish(payload *oty.EventPublish, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return o.execDelLocal(receiptData)
}
func (o *oracle) ExecDelLocal_EventAbort(payload *oty.EventAbort, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return o.execDelLocal(receiptData)
}
func (o *oracle) ExecDelLocal_ResultPrePublish(payload *oty.ResultPrePublish, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return o.execDelLocal(receiptData)
}
func (o *oracle) ExecDelLocal_ResultAbort(payload *oty.ResultAbort, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return o.execDelLocal(receiptData)
}
func (o *oracle) ExecDelLocal_ResultPublish(payload *oty.ResultPublish, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return o.execDelLocal(receiptData)
}