-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprocess.go
39 lines (35 loc) · 895 Bytes
/
process.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
package atto
import (
"encoding/json"
"fmt"
)
type process struct {
Action string `json:"action"`
JsonBlock string `json:"json_block"`
SubType string `json:"subtype"`
Block Block `json:"block"`
}
type processResponse struct {
Error string `json:"error"`
}
func doProcessRPC(process process, node string) error {
var requestBody, responseBytes []byte
requestBody, err := json.Marshal(process)
if err != nil {
return err
}
responseBytes, err = doRPC(string(requestBody), node)
if err != nil {
return err
}
var processResponse processResponse
if err = json.Unmarshal(responseBytes, &processResponse); err != nil {
return err
}
// Need to check processResponse.Error because of
// https://github.com/nanocurrency/nano-node/issues/1782.
if processResponse.Error != "" {
err = fmt.Errorf("could not publish block: %s", processResponse.Error)
}
return err
}