-
Notifications
You must be signed in to change notification settings - Fork 3
/
miner.go
111 lines (97 loc) · 3.36 KB
/
miner.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
package qlcchain
import (
"math/big"
"github.com/qlcchain/qlc-go-sdk/pkg/types"
)
type MinerApi struct {
client *QLCClient
}
type RewardParam struct {
Coinbase types.Address `json:"coinbase"`
Beneficial types.Address `json:"beneficial"`
StartHeight uint64 `json:"startHeight"`
EndHeight uint64 `json:"endHeight"`
RewardBlocks uint64 `json:"rewardBlocks"`
RewardAmount *big.Int `json:"rewardAmount"`
}
type MinerAvailRewardInfo struct {
LastEndHeight uint64 `json:"lastEndHeight"`
LatestBlockHeight uint64 `json:"latestBlockHeight"`
NodeRewardHeight uint64 `json:"nodeRewardHeight"`
AvailStartHeight uint64 `json:"availStartHeight"`
AvailEndHeight uint64 `json:"availEndHeight"`
AvailRewardBlocks uint64 `json:"availRewardBlocks"`
AvailRewardAmount types.Balance `json:"availRewardAmount"`
NeedCallReward bool `json:"needCallReward"`
}
type MinerHistoryRewardInfo struct {
LastEndHeight uint64 `json:"lastEndHeight"`
RewardBlocks uint64 `json:"rewardBlocks"`
RewardAmount types.Balance `json:"rewardAmount"`
LastRewardTime int64 `json:"lastRewardTime"`
}
// NewMinerAPI creates miner module for client
func NewMinerAPI(c *QLCClient) *MinerApi {
return &MinerApi{client: c}
}
// MinerAvailRewardInfo returns miner available reward info
func (m *MinerApi) GetAvailRewardInfo(coinbase types.Address) (*MinerAvailRewardInfo, error) {
var rspData MinerAvailRewardInfo
err := m.client.getClient().Call(&rspData, "miner_getAvailRewardInfo", coinbase)
if err != nil {
return nil, err
}
return &rspData, nil
}
// GetRewardSendBlock returns miner contract send block
func (m *MinerApi) GetRewardSendBlock(param *RewardParam) (*types.StateBlock, error) {
var rspData types.StateBlock
err := m.client.getClient().Call(&rspData, "miner_getRewardSendBlock", param)
if err != nil {
return nil, err
}
return &rspData, nil
}
// GetRewardSendBlock returns miner contract reward block
func (m *MinerApi) GetRewardRecvBlock(input *types.StateBlock) (*types.StateBlock, error) {
var rspData types.StateBlock
err := m.client.getClient().Call(&rspData, "miner_getRewardRecvBlock", input)
if err != nil {
return nil, err
}
return &rspData, nil
}
// GetRewardRecvBlockBySendHash returns miner contract reward block
func (m *MinerApi) GetRewardRecvBlockBySendHash(sendHash types.Hash) (*types.StateBlock, error) {
var rspData types.StateBlock
err := m.client.getClient().Call(&rspData, "miner_getRewardRecvBlockBySendHash", sendHash)
if err != nil {
return nil, err
}
return &rspData, nil
}
// GetRewardHistory returns miner history reward info
func (m *MinerApi) GetRewardHistory(coinbase types.Address) (*MinerHistoryRewardInfo, error) {
var rspData MinerHistoryRewardInfo
err := m.client.getClient().Call(&rspData, "miner_getRewardHistory", coinbase)
if err != nil {
return nil, err
}
return &rspData, nil
}
func (m *MinerApi) GetRewardData(param *RewardParam) ([]byte, error) {
var rspData []byte
err := m.client.getClient().Call(&rspData, "miner_getRewardData", param)
if err != nil {
return nil, err
}
return rspData, nil
}
func (m *MinerApi) UnpackRewardData(data []byte) (*RewardParam, error) {
var rspData RewardParam
err := m.client.getClient().Call(&rspData, "miner_unpackRewardData", data)
if err != nil {
return nil, err
}
return &rspData, nil
}