-
Notifications
You must be signed in to change notification settings - Fork 0
/
proto.go
53 lines (45 loc) · 1.14 KB
/
proto.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
package proto
import (
"errors"
"os"
"path/filepath"
"github.com/airbloc/solgen/deployment"
)
type option map[string]string
type Options map[string]option
type binder struct {
deployments deployment.Deployments
typeOptions Options
contracts []contract
}
func (bind *binder) parseContracts(deployments deployment.Deployments) {
for name, deployment := range deployments {
contract := &contract{typeOptions: bind.typeOptions, contractName: name}
contract.parseContract(deployment.ABI)
bind.contracts = append(bind.contracts, *contract)
}
}
func GenerateBind(path string, deployments deployment.Deployments, typeOptions Options) error {
stat, err := os.Stat(path)
if os.IsNotExist(err) {
if err = os.MkdirAll(path, os.ModePerm); err != nil {
return err
}
} else {
if !stat.IsDir() {
return errors.New("is not directory")
}
}
bind := &binder{
deployments: deployments,
typeOptions: typeOptions,
}
bind.parseContracts(deployments)
for _, contract := range bind.contracts {
file := filepath.Join(path, contract.PackageName+".proto")
if err := RenderFile(file, contract); err != nil {
return err
}
}
return nil
}