-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauditor.go
75 lines (63 loc) · 2.19 KB
/
auditor.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
package audit
import (
"context"
"github.com/0x19/solc-switch"
"github.com/unpackdev/solgo"
)
// Auditor represents a structure that manages the auditing process
// of smart contracts using the Slither tool.
type Auditor struct {
ctx context.Context // Context for the auditor operations.
config *Config // Configuration for the Slither tool.
sources *solgo.Sources // Sources of the smart contracts to be audited.
compiler *solc.Solc // Instance of the solc compiler.
slither *Slither // Instance of the Slither tool.
}
// NewAuditor initializes a new Auditor instance with the provided context,
// configuration, and sources. It ensures that the Slither tool is properly
// initialized and that the sources are prepared for analysis.
func NewAuditor(ctx context.Context, compiler *solc.Solc, config *Config, sources *solgo.Sources) (*Auditor, error) {
slither, err := NewSlither(ctx, compiler, config)
if err != nil {
return nil, err
}
// Ensure that the sources are prepared for future consumption.
if !sources.ArePrepared() {
if err := sources.Prepare(); err != nil {
return nil, err
}
}
return &Auditor{
ctx: ctx,
config: config,
sources: sources,
slither: slither,
compiler: compiler,
}, nil
}
// IsReady checks if the Auditor is ready to perform an analysis.
// It ensures that the Slither tool is installed and that the sources are prepared.
func (a *Auditor) IsReady() bool {
return a.slither.IsInstalled() && a.sources.ArePrepared()
}
// GetConfig returns the configuration used by the Auditor.
func (a *Auditor) GetConfig() *Config {
return a.config
}
// GetSources returns the smart contract sources managed by the Auditor.
func (a *Auditor) GetSources() *solgo.Sources {
return a.sources
}
// GetSlither returns the instance of the Slither tool used by the Auditor.
func (a *Auditor) GetSlither() *Slither {
return a.slither
}
// Analyze performs an analysis of the smart contracts using the Slither tool.
// It returns the analysis response or an error if the analysis fails.
func (a *Auditor) Analyze() (*Report, error) {
response, _, err := a.slither.Analyze(a.sources)
if err != nil {
return nil, err
}
return response, nil
}