File tree Expand file tree Collapse file tree 3 files changed +41
-4
lines changed Expand file tree Collapse file tree 3 files changed +41
-4
lines changed Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
var (
4
- // The node needs to support the work_generate action . See
4
+ // The node that is used to interact with the nano network . See
5
5
// e.g. https://publicnodes.somenano.com to find public nodes
6
6
// or set up your own node.
7
7
node = "https://node.somenano.com/proxy"
10
10
// opening an accout, but can be changed afterwards. See e.g.
11
11
// https://nanolooker.com/representatives to find representatives.
12
12
defaultRepresentative = "nano_1jtx5p8141zjtukz4msp1x93st7nh475f74odj8673qqm96xczmtcnanos1o"
13
+
14
+ // workSource specifies where the work for block submission shall
15
+ // come from. These options are available:
16
+ // - workSourceLocal: The work is generated on the CPU of the
17
+ // current computer.
18
+ // - workSourceNode: The work is fetched from the node using the
19
+ // work_generate action. Make sure that your node supports it.
20
+ // - workSourceLocalFallback: It is attempted to fetch the work
21
+ // from the node, but if this fails, it will be generated on
22
+ // the CPU of the current computer.
23
+ workSource = workSourceLocalFallback
13
24
)
Original file line number Diff line number Diff line change @@ -50,6 +50,14 @@ Environment:
50
50
Authentication.
51
51
`
52
52
53
+ type workSourceType int
54
+
55
+ const (
56
+ workSourceLocal workSourceType = iota
57
+ workSourceNode
58
+ workSourceLocalFallback
59
+ )
60
+
53
61
var accountIndexFlag uint
54
62
var yFlag bool
55
63
@@ -191,7 +199,7 @@ func printBalance() error {
191
199
if err = block .Sign (privateKey ); err != nil {
192
200
return err
193
201
}
194
- if err = block . FetchWork ( node ); err != nil {
202
+ if err = fillWork ( & block , node ); err != nil {
195
203
return err
196
204
}
197
205
if err = block .Submit (node ); err != nil {
@@ -255,7 +263,7 @@ func changeRepresentative() error {
255
263
if err = block .Sign (privateKey ); err != nil {
256
264
return err
257
265
}
258
- if err = block . FetchWork ( node ); err != nil {
266
+ if err = fillWork ( & block , node ); err != nil {
259
267
return err
260
268
}
261
269
if err = block .Submit (node ); err != nil {
@@ -296,7 +304,7 @@ func sendFunds() error {
296
304
if err = block .Sign (privateKey ); err != nil {
297
305
return err
298
306
}
299
- if err = block . FetchWork ( node ); err != nil {
307
+ if err = fillWork ( & block , node ); err != nil {
300
308
return err
301
309
}
302
310
if err = block .Submit (node ); err != nil {
Original file line number Diff line number Diff line change 7
7
"os"
8
8
"runtime"
9
9
"strings"
10
+
11
+ "github.com/codesoap/atto"
10
12
)
11
13
12
14
// getSeed returns the first line of the standard input.
@@ -61,3 +63,19 @@ func letUserVerifySend(amount, recipient string) (err error) {
61
63
}
62
64
return
63
65
}
66
+
67
+ func fillWork (block * atto.Block , node string ) error {
68
+ switch workSource {
69
+ case workSourceLocal :
70
+ return block .GenerateWork ()
71
+ case workSourceNode :
72
+ return block .FetchWork (node )
73
+ case workSourceLocalFallback :
74
+ if err := block .FetchWork (node ); err != nil {
75
+ fmt .Fprintf (os .Stderr , "Could not fetch work from node (error: %v); generating it on CPU... " , err )
76
+ return block .GenerateWork ()
77
+ }
78
+ return nil
79
+ }
80
+ return fmt .Errorf ("unknown work source" )
81
+ }
You can’t perform that action at this time.
0 commit comments