-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
104 lines (91 loc) · 2.46 KB
/
Copy pathmain.go
File metadata and controls
104 lines (91 loc) · 2.46 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/TrueBlocks/trueblocks-chifra/v6/pkg/config"
"github.com/TrueBlocks/trueblocks-chifra/v6/pkg/crud"
"github.com/TrueBlocks/trueblocks-chifra/v6/pkg/file"
"github.com/TrueBlocks/trueblocks-chifra/v6/pkg/logger"
"github.com/TrueBlocks/trueblocks-chifra/v6/pkg/names"
"github.com/TrueBlocks/trueblocks-chifra/v6/pkg/types"
"github.com/TrueBlocks/trueblocks-chifra/v6/pkg/usage"
sdk "github.com/TrueBlocks/trueblocks-sdk/v6"
)
func main() {
app := ParseArgs()
if app.database == names.DatabaseRegular {
if !usage.QueryUser("Are you sure you want to operate against the Regular names database (Y/n)?", "Quitting...") {
os.Exit(0)
}
}
if app.dryrun {
backupAllFiles()
defer restoreAllFiles()
}
switch app.action {
case AutoName:
app.AutoName(os.Args)
return
case Delete:
app.DeleteName(os.Args)
return
case Undelete:
app.UndeleteName(os.Args)
return
case Remove:
app.RemoveName(os.Args)
return
case Clean:
app.CleanNames()
return
case Publish:
app.PublishNames()
return
}
var name types.Name
name.Address, _, _ = getValue(1, "address", "0xf503017d7baf7fbc0fff7492b751025c6a78179b")
_, name.Name, _ = getValue(2, "name", "TrueBlocks 2020 Wallet 0xf503")
_, name.Tags, _ = getValue(3, "tags", defTags)
_, name.Source, _ = getValue(4, "source", defSource)
_, name.Symbol, _ = getValue(5, "symbol", "")
_, _, name.Decimals = getValue(6, "decimals", "")
opts := sdk.NamesOptions{
Regular: app.IsRegular(),
}
cd := crud.CrudFromName(name)
if names, _, err := opts.ModifyName(crud.Update, cd); err != nil {
printHelp(err)
} else {
for _, name := range names {
fmt.Printf("Names: %v\n", name.String())
}
}
}
func getFilenames() []string {
return []string{
filepath.Join(config.MustGetPathToChainConfig("mainnet"), string(names.DatabaseRegular)),
filepath.Join(config.MustGetPathToChainConfig("mainnet"), string(names.DatabaseCustom)),
}
}
func backupAllFiles() {
backupFile := func(fileName string) {
backupName := fileName + ".bak"
_, _ = file.Copy(backupName, fileName)
}
for _, file := range getFilenames() {
logger.Info("Dryrun - backing up file:", file)
backupFile(file)
}
}
func restoreAllFiles() {
restoreFile := func(fileName string) {
backupName := fileName + ".bak"
_, _ = file.Copy(fileName, backupName)
_ = os.Remove(backupName)
}
for _, file := range getFilenames() {
logger.Info("Dryrun - restoring file:", file)
restoreFile(file)
}
}