-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathaddress_special.go
More file actions
89 lines (72 loc) · 2.4 KB
/
address_special.go
File metadata and controls
89 lines (72 loc) · 2.4 KB
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
package address
import "golang.org/x/crypto/sha3"
const (
// ZeroAddress is the IoTeX address whose hash160 is all zero
ZeroAddress = "io1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqd39ym7"
// StakingBucketPoolAddr is the staking bucket pool address
StakingBucketPoolAddr = "io000000000000000000000000stakingprotocol"
// RewardingPoolAddr is the rewarding pool address
RewardingPoolAddr = "io0000000000000000000000rewardingprotocol"
// StakingProtocolAddr is the staking protocol address
StakingProtocolAddr = "io1qnpz47hx5q6r3w876axtrn6yz95d70cjl35r53"
// RewardingProtocol is the rewarding protocol address
RewardingProtocol = "io154mvzs09vkgn0hw6gg3ayzw5w39jzp47f8py9v"
// PollProtocol is the poll protocol address
PollProtocol = "io1ze4hg0pvrftuj0pw90p7z6wj3wae7mdrwws6d5"
// RollDPoSProtocol is the Roll-DPoS protocol address
RollDPoSProtocol = "io1qsfhpcq2wywds8dpjx8suj2ytx4d4egwxzqsg3"
)
// 20-byte protocol address hash
var (
StakingProtocolAddrHash = hash160b([]byte("staking"))
RewardingProtocolAddrHash = hash160b([]byte("rewarding"))
PollProtocolAddrHash = hash160b([]byte("poll"))
RollDPoSProtocolAddrHash = hash160b([]byte("rolldpos"))
)
// hash160b returns 160-bit (20-byte) hash of input
func hash160b(input []byte) Hash160 {
// use keccak algorithm
hasher := sha3.NewLegacyKeccak256()
hasher.Write(input)
var hash Hash160
copy(hash[:], hasher.Sum(nil)[12:])
return hash
}
// bytesToHash160 copies the byte slice into hash
func bytesToHash160(b []byte) Hash160 {
var h Hash160
if len(b) > 20 {
b = b[len(b)-20:]
}
copy(h[20-len(b):], b)
return h
}
// AddrV1Special is address that consists of special text
// it is NOT a valid bech32 encoding of the 20-bytes hash
type AddrV1Special struct {
addr string
}
func newAddrV1Special(s string) *AddrV1Special {
return &AddrV1Special{
addr: s,
}
}
// IsAddrV1Special returns true for special address
func IsAddrV1Special(s string) bool {
switch s {
case RewardingPoolAddr, StakingBucketPoolAddr:
return true
default:
return false
}
}
// String returns the special-text address
func (addr *AddrV1Special) String() string { return addr.addr }
// Bytes panics since it is NOT a valid bech32 encoding
func (addr *AddrV1Special) Bytes() []byte {
panic("Bytes() does not apply for special address")
}
// Hex panics since it is NOT a valid bech32 encoding
func (addr *AddrV1Special) Hex() string {
panic("Hex() does not apply for special address")
}