/
exec_local.go
executable file
·91 lines (77 loc) · 3.02 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
// 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 (
"fmt"
"github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/cert/authority"
ct "github.com/33cn/plugin/plugin/dapp/cert/types"
)
func calcCertHeightKey(height int64) []byte {
return []byte(fmt.Sprintf("LODB-cert-%d", height))
}
// ExecLocal_New 启用证书交易执行
func (c *Cert) ExecLocal_New(payload *ct.CertNew, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if !authority.IsAuthEnable {
clog.Error("Authority is not available. Please check the authority config or authority initialize error logs.")
return nil, ct.ErrInitializeAuthority
}
var set types.LocalDBSet
historityCertdata := &types.HistoryCertStore{}
authority.Author.HistoryCertCache.CurHeight = c.GetHeight()
authority.Author.HistoryCertCache.ToHistoryCertStore(historityCertdata)
key := calcCertHeightKey(c.GetHeight())
set.KV = append(set.KV, &types.KeyValue{
Key: key,
Value: types.Encode(historityCertdata),
})
// 构造非证书历史数据
noneCertdata := &types.HistoryCertStore{}
noneCertdata.NxtHeight = historityCertdata.CurHeigth
noneCertdata.CurHeigth = 0
set.KV = append(set.KV, &types.KeyValue{
Key: calcCertHeightKey(0),
Value: types.Encode(noneCertdata),
})
return &set, nil
}
// ExecLocal_Update 更新证书交易执行
func (c *Cert) ExecLocal_Update(payload *ct.CertUpdate, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if !authority.IsAuthEnable {
clog.Error("Authority is not available. Please check the authority config or authority initialize error logs.")
return nil, ct.ErrInitializeAuthority
}
var set types.LocalDBSet
// 写入上一纪录的next-height
key := calcCertHeightKey(authority.Author.HistoryCertCache.CurHeight)
historityCertdata := &types.HistoryCertStore{}
authority.Author.HistoryCertCache.NxtHeight = c.GetHeight()
authority.Author.HistoryCertCache.ToHistoryCertStore(historityCertdata)
set.KV = append(set.KV, &types.KeyValue{
Key: key,
Value: types.Encode(historityCertdata),
})
// 证书更新
historityCertdata = &types.HistoryCertStore{}
err := authority.Author.ReloadCertByHeght(c.GetHeight())
if err != nil {
return nil, err
}
authority.Author.HistoryCertCache.ToHistoryCertStore(historityCertdata)
setKey := calcCertHeightKey(c.GetHeight())
set.KV = append(set.KV, &types.KeyValue{
Key: setKey,
Value: types.Encode(historityCertdata),
})
return &set, nil
}
// ExecLocal_Normal 非证书变更交易执行
func (c *Cert) ExecLocal_Normal(payload *ct.CertNormal, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if !authority.IsAuthEnable {
clog.Error("Authority is not available. Please check the authority config or authority initialize error logs.")
return nil, ct.ErrInitializeAuthority
}
var set types.LocalDBSet
return &set, nil
}