/
restore_access_request.go
79 lines (70 loc) · 2.56 KB
/
restore_access_request.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
// Copyright 2016 The go-daylight Authors
// This file is part of the go-daylight library.
//
// The go-daylight library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-daylight library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-daylight library. If not, see <http://www.gnu.org/licenses/>.
package parser
import (
"fmt"
"github.com/EGaaS/go-egaas-mvp/packages/utils"
)
// RestoreAccessRequestInit initializes RestoreAccessRequest transaction
func (p *Parser) RestoreAccessRequestInit() error {
fields := []map[string]string{{"sign": "bytes"}}
err := p.GetTxMaps(fields)
if err != nil {
return p.ErrInfo(err)
}
return nil
}
// RestoreAccessRequestFront checks conditions of RestoreAccessRequest transaction
func (p *Parser) RestoreAccessRequestFront() error {
err := p.generalCheck(`system_restore_access_request`)
if err != nil {
return p.ErrInfo(err)
}
data, err := p.OneRow("SELECT * FROM system_restore_access WHERE state_id = ?", p.TxStateID).Int64()
if err != nil {
return p.ErrInfo(err)
}
if len(data) == 0 {
return p.ErrInfo("!system_restore_access")
}
if data["active"] == 0 {
return p.ErrInfo("active=0")
}
forSign := fmt.Sprintf("%s,%s,%d,%d", p.TxMap["type"], p.TxMap["time"], p.TxCitizenID, p.TxStateID)
CheckSignResult, err := utils.CheckSign(p.PublicKeys, forSign, p.TxMap["sign"], false)
if err != nil {
return p.ErrInfo(err)
}
if !CheckSignResult {
return p.ErrInfo("incorrect sign")
}
if err = p.AccessRights(`restore_access_condition`, false); err != nil {
return p.ErrInfo(err)
}
return nil
}
// RestoreAccessRequest proceeds RestoreAccessRequest transaction
func (p *Parser) RestoreAccessRequest() error {
_, err := p.selectiveLoggingAndUpd([]string{"time", "close", "citizen_id"}, []interface{}{p.BlockData.Time, "0", p.TxCitizenID}, "system_restore_access", []string{"state_id"}, []string{utils.UInt32ToStr(p.TxStateID)}, true)
if err != nil {
return p.ErrInfo(err)
}
return nil
}
// RestoreAccessRequestRollback rollbacks RestoreAccessRequest transaction
func (p *Parser) RestoreAccessRequestRollback() error {
return p.autoRollback()
}