File tree Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Original file line number Diff line number Diff line change 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 @@ -57,6 +57,14 @@ Environment:
57
57
Authentication.
58
58
`
59
59
60
+ type workSourceType int
61
+
62
+ const (
63
+ workSourceLocal workSourceType = iota
64
+ workSourceNode
65
+ workSourceLocalFallback
66
+ )
67
+
60
68
var accountIndexFlag uint
61
69
var yFlag bool
62
70
@@ -153,7 +161,7 @@ func receive() error {
153
161
if err != nil {
154
162
return err
155
163
}
156
- if err = block . FetchWork ( node ); err != nil {
164
+ if err = fillWork ( & block , node ); err != nil {
157
165
return err
158
166
}
159
167
blockJSON , err := json .Marshal (block )
@@ -186,7 +194,7 @@ func change() error {
186
194
if err != nil {
187
195
return err
188
196
}
189
- if err = block . FetchWork ( node ); err != nil {
197
+ if err = fillWork ( & block , node ); err != nil {
190
198
return err
191
199
}
192
200
blockJSON , err := json .Marshal (block )
@@ -215,7 +223,7 @@ func send() error {
215
223
if err != nil {
216
224
return err
217
225
}
218
- if err = block . FetchWork ( node ); err != nil {
226
+ if err = fillWork ( & block , node ); err != nil {
219
227
return err
220
228
}
221
229
blockJSON , err := json .Marshal (block )
Original file line number Diff line number Diff line change @@ -136,3 +136,19 @@ func letUserVerifyBlock(block atto.Block) (err error) {
136
136
}
137
137
return
138
138
}
139
+
140
+ func fillWork (block * atto.Block , node string ) error {
141
+ switch workSource {
142
+ case workSourceLocal :
143
+ return block .GenerateWork ()
144
+ case workSourceNode :
145
+ return block .FetchWork (node )
146
+ case workSourceLocalFallback :
147
+ if err := block .FetchWork (node ); err != nil {
148
+ fmt .Fprintf (os .Stderr , "Could not fetch work from node (error: %v); generating it on CPU...\n " , err )
149
+ return block .GenerateWork ()
150
+ }
151
+ return nil
152
+ }
153
+ return fmt .Errorf ("unknown work source" )
154
+ }
You can’t perform that action at this time.
0 commit comments