forked from bluesign/cadenceUpgrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (43 loc) · 973 Bytes
/
main.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
package main
import (
"fmt"
"github.com/bluesign/cadenceUpgrader/fixer"
"os"
"path"
"path/filepath"
"strings"
)
func main() {
filter := ""
if len(os.Args) > 1 {
filter = os.Args[1]
}
filepath.Walk("./contracts",
func(spath string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !strings.Contains(spath, filter) {
return nil
}
fmt.Println(spath)
if strings.HasSuffix(spath, ".cdc") {
data_raw, _ := os.ReadFile(spath)
code := string(data_raw)
newPath := strings.Replace(spath, "contracts/", "contractsV1/", 1)
identifier := path.Base(newPath)
if strings.Contains(identifier, "TenantService") {
return nil
}
libPath := fmt.Sprintf("./standardsV1/%s", identifier)
_, err := os.ReadFile(libPath)
if err != nil {
_, err = os.ReadFile(newPath)
if err != nil || filter != "" {
fixer.FixFile(spath, newPath, code)
}
}
}
return nil
})
}