-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
171 lines (148 loc) · 3.84 KB
/
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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package main
import (
"os"
"strconv"
"path/filepath"
"regexp"
"github.com/badlamb/dexm/blockchain"
"github.com/badlamb/dexm/sync"
"github.com/badlamb/dexm/contracts"
"github.com/badlamb/dexm/wallet"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
"gopkg.in/mgo.v2/bson"
)
func main() {
app := cli.NewApp()
app.Version = "1.0.0 pre-alpha"
app.Commands = []cli.Command{
{
Name: "makewallet",
Usage: "mw [filename]",
Aliases: []string{"genwallet", "mw", "gw"},
Action: func(c *cli.Context) error {
wal := wallet.GenerateWallet()
log.Info("Generated wallet ", wal.GetWallet())
if c.Args().Get(0) == "" {
log.Fatal("Invalid filename")
}
wal.ExportWallet(c.Args().Get(0))
return nil
},
},
{
Name: "startnode",
Usage: "sn",
Aliases: []string{"sn", "rn"},
Action: func(c *cli.Context) error {
//bc := blockchain.NewBlockChain()
//bc.GenerateBalanceDB()
go contracts.StartCDNServer()
protocol.StartSyncServer()
return nil
},
},
{
Name: "maketransaction",
Usage: "mkt [walletPath] [recipient] [amount]",
Aliases: []string{"mkt", "gt"},
Action: func(c *cli.Context) error {
walletPath := c.Args().Get(0)
recipient := c.Args().Get(1)
amount, err := strconv.Atoi(c.Args().Get(2))
if err != nil {
log.Error(err)
return nil
}
senderWallet := wallet.ImportWallet(walletPath)
transaction, err := senderWallet.NewTransaction(recipient, amount, 0)
if err != nil {
log.Error(err)
return nil
}
//the nonce and amount have changed, let's save them
senderWallet.ExportWallet(walletPath)
log.Info("Generated Transaction")
b, _ := bson.Marshal(transaction)
protocol.InitPartialNode()
protocol.BroadcastMessage(1, b)
return nil
},
},
{
Name: "getbalance",
Usage: "gb [wallet]",
Aliases: []string{"gb", "fb"},
Action: func(c *cli.Context) error {
bc := blockchain.OpenBlockchain()
bal, _, _ := bc.GetBalance(c.Args().Get(0))
log.Info("Balance for given wallet is ", bal)
return nil
},
},
{
Name: "fixwallet",
Usage: "fw [walletfile]",
Aliases: []string{"fw"},
Action: func(c *cli.Context) error {
// This updates balance and nonce of a given wallet
walletPath := c.Args().Get(0)
senderWallet := wallet.ImportWallet(walletPath)
bc := blockchain.OpenBlockchain()
bal, nonce, _ := bc.GetBalance(senderWallet.GetWallet())
senderWallet.Balance = bal
senderWallet.Nonce = nonce
senderWallet.ExportWallet(walletPath)
return nil
},
},
{
Name: "makecdn",
Usage: "mc [static folder] [wallet]",
Aliases: []string{"mc"},
Action: func(c *cli.Context) error {
ownerWallet := wallet.ImportWallet(c.Args().Get(1))
files := []string{}
err := filepath.Walk(c.Args().Get(0), func(path string, f os.FileInfo, err error) error {
if !f.IsDir(){
files = append(files, path)
}
return nil
})
if err != nil{
return err
}
cont, err := contracts.CreateCDNContract(files, 1, ownerWallet)
if err != nil{
log.Fatal(err)
}
cont.SelectCDNNodes(ownerWallet)
return nil
},
},
{
Name: "makevanitywallet",
Usage: "mvw [wallet] [regex]",
Aliases: []string{"mvw", "mv"},
Action: func(c *cli.Context) error {
log.Info("Dexm uses Base58 encoding, only chars allowed are 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
regex, err := regexp.Compile(c.Args().Get(1))
if err != nil {
log.Error(err)
return err
}
for {
wal := wallet.GenerateWallet()
wallString := wal.GetWallet()
if regex.MatchString(wallString) {
log.Info("Found wallet: ", wallString)
wal.ExportWallet(c.Args().Get(0))
return nil
}
}
return nil
},
},
}
app.Run(os.Args)
}