-
Notifications
You must be signed in to change notification settings - Fork 0
/
solc.go
75 lines (63 loc) · 1.83 KB
/
solc.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 solc
import (
"context"
"fmt"
"net/http"
"runtime"
"time"
)
// Solc represents the main structure for interacting with the Solidity compiler.
// It holds the configuration, context, and other necessary components to perform operations like compilation.
type Solc struct {
ctx context.Context
config *Config
client *http.Client
gOOSFunc func() string
localReleases []Version
lastSync time.Time
}
// New initializes and returns a new instance of the Solc structure.
func New(ctx context.Context, config *Config) (*Solc, error) {
if config == nil {
return nil, fmt.Errorf("config needs to be provided")
}
if err := config.Validate(); err != nil {
return nil, err
}
return &Solc{
ctx: ctx,
config: config,
gOOSFunc: func() string { return runtime.GOOS },
client: &http.Client{
Timeout: config.GetHttpClientTimeout(),
},
}, nil
}
// GetContext retrieves the context associated with the Solc instance.
func (s *Solc) GetContext() context.Context {
return s.ctx
}
// LastSyncTime retrieves the last time the Solc instance was synced.
func (s *Solc) LastSyncTime() time.Time {
return s.lastSync
}
// GetConfig retrieves the configuration associated with the Solc instance.
func (s *Solc) GetConfig() *Config {
return s.config
}
// GetHTTPClient retrieves the HTTP client associated with the Solc instance.
func (s *Solc) GetHTTPClient() *http.Client {
return s.client
}
// Compile compiles the provided Solidity source code using the specified compiler configuration.
func (s *Solc) Compile(ctx context.Context, source string, config *CompilerConfig) (*CompilerResults, error) {
compiler, err := NewCompiler(ctx, s, config, source)
if err != nil {
return nil, err
}
compilerResults, err := compiler.Compile()
if err != nil {
return nil, err
}
return compilerResults, nil
}