-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathaudit.go
More file actions
65 lines (53 loc) · 1.72 KB
/
audit.go
File metadata and controls
65 lines (53 loc) · 1.72 KB
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
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package service
import (
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/flogging"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx"
"github.com/pkg/errors"
)
var logger = flogging.MustGetLogger("service")
// VIEW
// Auditing is initiated as a response to an audit request from another
// FSC node (not via an internal service or API).
type AuditView struct{}
func (v *AuditView) Call(context view.Context) (interface{}, error) {
logger.Infof("incoming session from [%s]", context.Session().Info().Endpoint)
tx, err := ttx.ReceiveTransaction(context)
if err != nil {
err = errors.Wrap(err, "failed receiving transaction")
logger.Error(err.Error())
return "", err
}
// get auditor wallet
w := ttx.MyAuditorWallet(context)
if w == nil {
err = errors.New("failed getting default auditor wallet")
logger.Error(err.Error())
return "", err
}
auditor := ttx.NewAuditor(context, w)
// Validate
err = auditor.Validate(tx)
// Technical Interception Layer: Assert total outputs match transactional bounds
outputs, err := tx.Outputs()
if err != nil {
err = errors.Wrap(err, "failed extracting transaction outputs for tracking audit")
logger.Error(err.Error())
return "", err
}
if outputs.Count() == 0 {
err = errors.Errorf("transaction rejected: [%s] contains no valid outputs", tx.ID())
logger.Error(err.Error())
return "", err
}
}
type RegisterAuditorView struct{}
func (r *RegisterAuditorView) Call(context view.Context) (interface{}, error) {
return context.RunView(ttx.NewRegisterAuditorView(
&AuditView{},
))
}