-
Notifications
You must be signed in to change notification settings - Fork 1
/
exec_local.go
101 lines (86 loc) · 3.41 KB
/
exec_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// 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/common/db/table"
//"github.com/assetcloud/chain/common"
"github.com/assetcloud/chain/types"
pty "github.com/assetcloud/plugin/plugin/dapp/issuance/types"
)
func (c *Issuance) execLocal(tx *types.Transaction, receipt *types.ReceiptData) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
var IDtable, recordTable *table.Table
cfg := c.GetAPI().GetConfig()
if cfg.IsDappFork(c.GetHeight(), pty.IssuanceX, pty.ForkIssuanceTableUpdate) {
recordTable = pty.NewRecordTable(c.GetLocalDB())
IDtable = pty.NewIssuanceTable(c.GetLocalDB())
}
for _, item := range receipt.Logs {
if item.Ty >= pty.TyLogIssuanceCreate && item.Ty <= pty.TyLogIssuanceClose {
var issuanceLog pty.ReceiptIssuance
err := types.Decode(item.Log, &issuanceLog)
if err != nil {
return nil, err
}
if item.Ty == pty.TyLogIssuanceCreate || item.Ty == pty.TyLogIssuanceClose {
if !cfg.IsDappFork(c.GetHeight(), pty.IssuanceX, pty.ForkIssuanceTableUpdate) {
IDtable = pty.NewIssuanceTable(c.GetLocalDB())
}
err = IDtable.Replace(&pty.ReceiptIssuanceID{IssuanceId: issuanceLog.IssuanceId, Status: issuanceLog.Status})
if err != nil {
return nil, err
}
} else {
if !cfg.IsDappFork(c.GetHeight(), pty.IssuanceX, pty.ForkIssuanceTableUpdate) {
recordTable = pty.NewRecordTable(c.GetLocalDB())
}
err = recordTable.Replace(&pty.ReceiptIssuance{IssuanceId: issuanceLog.IssuanceId, Status: issuanceLog.Status,
DebtId: issuanceLog.DebtId, AccountAddr: issuanceLog.AccountAddr})
if err != nil {
return nil, err
}
}
}
}
if IDtable != nil {
kvs, err := IDtable.Save()
if err != nil {
return nil, err
}
set.KV = append(set.KV, kvs...)
}
if recordTable != nil {
kvs, err := recordTable.Save()
if err != nil {
return nil, err
}
set.KV = append(set.KV, kvs...)
}
set.KV = c.AddRollbackKV(tx, []byte(pty.IssuanceX), set.KV)
return set, nil
}
// ExecLocal_Create Action
func (c *Issuance) ExecLocal_Create(payload *pty.IssuanceCreate, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return c.execLocal(tx, receiptData)
}
// ExecLocal_Debt Action
func (c *Issuance) ExecLocal_Debt(payload *pty.IssuanceDebt, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return c.execLocal(tx, receiptData)
}
// ExecLocal_Repay Action
func (c *Issuance) ExecLocal_Repay(payload *pty.IssuanceRepay, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return c.execLocal(tx, receiptData)
}
// ExecLocal_Feed Action
func (c *Issuance) ExecLocal_Feed(payload *pty.IssuanceFeed, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return c.execLocal(tx, receiptData)
}
// ExecLocal_Close Action
func (c *Issuance) ExecLocal_Close(payload *pty.IssuanceClose, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return c.execLocal(tx, receiptData)
}
// ExecLocal_Manage Action
func (c *Issuance) ExecLocal_Manage(payload *pty.IssuanceManage, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return c.execLocal(tx, receiptData)
}