This repository has been archived by the owner on Aug 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generating.go
65 lines (54 loc) · 1.8 KB
/
generating.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
package syscoinrpc
import "encoding/json"
// GeneratingClient wraps all `generating` related functions.
type GeneratingClient struct {
c *Client // The binded client, must not be nil.
}
func (gc *GeneratingClient) do(method string, params ...interface{}) (json.RawMessage, error) {
return gc.c.do(method, params...)
}
// Generate mines instantly (before RPC call returns) a specified
// number of blocks to a wallet address in the node.
//
// Returns the hashes of the generated blocks.
//
// nBlocks : The number of blocks to generate.
// maxTries : The number of iterations to try (default = 0 -> 1000000 iterations).
func (gc *GeneratingClient) Generate(nBlocks uint64, maxTries uint64) ([]string, error) {
if maxTries == 0 {
maxTries = 1000000
}
response, err := gc.do("generate", nBlocks, maxTries)
if err != nil {
return nil, err
}
var hashes []string
err = json.Unmarshal(response, &hashes)
if err != nil {
return nil, err
}
return hashes, nil
}
// GenerateToAddress mines instantly (before RPC call returns) a specified
// number of blocks to a the specified wallet address.
//
// Returns the hashes of the generated blocks.
//
// nBlocks : The number of blocks to generate.
// address : The address to send the newly generated Syscoin to.
// maxTries : The number of iterations to try (default = 0 -> 1000000 iterations).
func (gc *GeneratingClient) GenerateToAddress(nBlocks uint64, address string, maxTries uint64) ([]string, error) {
if maxTries == 0 {
maxTries = 1000000
}
response, err := gc.do("generatetoaddress", nBlocks, address, maxTries)
if err != nil {
return nil, err
}
var hashes []string
err = json.Unmarshal(response, &hashes)
if err != nil {
return nil, err
}
return hashes, nil
}