forked from aergoio/aergo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpc.go
68 lines (53 loc) · 1.46 KB
/
rpc.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
/*
* @file
* @copyright defined in aergo/LICENSE.txt
*/
package types
import (
"errors"
"math/big"
"strconv"
)
var RPCErrInvalidArgument = errors.New("invalid argument")
var RPCErrInternalError = errors.New("internal error")
func AddCategory(confs map[string]*ConfigItem, category string) *ConfigItem {
cat := &ConfigItem{Props: make(map[string]string)}
confs[category] = cat
return cat
}
func (ci *ConfigItem) AddInt(key string, value int) *ConfigItem {
ci.Add(key, strconv.Itoa(value))
return ci
}
func (ci *ConfigItem) AddBool(key string, value bool) *ConfigItem {
ci.Add(key, strconv.FormatBool(value))
return ci
}
func (ci *ConfigItem) AddFloat(key string, value float64) *ConfigItem {
ci.Add(key, strconv.FormatFloat(value, 'g', -1, 64))
return ci
}
func (ci *ConfigItem) Add(key, value string) *ConfigItem {
ci.Props[key] = value
return ci
}
// Add adds amount to s.Amount.
func (s *Staking) Add(amount *big.Int) {
s.Amount = new(big.Int).Add(s.GetAmountBigInt(), amount).Bytes()
}
// Sub substracts amount from s.Amount and returns the actual adjustment.
func (s *Staking) Sub(amount *big.Int) *big.Int {
var (
staked = s.GetAmountBigInt()
actualAdjustment = amount
)
// Cannot be a negative value.
if staked.Cmp(amount) < 0 {
actualAdjustment = staked
}
s.Amount = new(big.Int).Sub(s.GetAmountBigInt(), actualAdjustment).Bytes()
return actualAdjustment
}
func (s *Staking) SetWhen(blockNo BlockNo) {
s.When = uint64(blockNo)
}