/
info.go
125 lines (112 loc) · 3.36 KB
/
info.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package proto
import (
"github.com/wavesplatform/gowaves/pkg/crypto"
"github.com/wavesplatform/gowaves/pkg/grpc/generated/waves"
g "github.com/wavesplatform/gowaves/pkg/grpc/generated/waves/node/grpc"
"github.com/wavesplatform/gowaves/pkg/util/common"
)
type BlockInfo struct {
Version BlockVersion
Timestamp uint64
Height uint64
BaseTarget uint64
Generator WavesAddress
GeneratorPublicKey crypto.PublicKey
GenerationSignature B58Bytes
VRF B58Bytes
Rewards Rewards
}
func NewBlockInfo(version BlockVersion, timestamp, height, baseTarget uint64,
generatorAddress WavesAddress, generatorPK crypto.PublicKey,
generationSignature, vrf []byte, rewards Rewards) *BlockInfo {
return &BlockInfo{
Version: version,
Timestamp: timestamp,
Height: height,
BaseTarget: baseTarget,
Generator: generatorAddress,
GeneratorPublicKey: generatorPK,
GenerationSignature: generationSignature,
VRF: vrf,
Rewards: rewards,
}
}
func BlockInfoFromHeader(header *BlockHeader, generator WavesAddress, height uint64, vrf []byte, rewards Rewards) (*BlockInfo, error) {
return &BlockInfo{
Version: header.Version,
Timestamp: header.Timestamp,
Height: height,
BaseTarget: header.BaseTarget,
GenerationSignature: header.GenSignature,
Generator: generator,
GeneratorPublicKey: header.GeneratorPublicKey,
VRF: vrf,
Rewards: rewards.Sorted(),
}, nil
}
func (bi *BlockInfo) CopyVRF() []byte {
if bi.Version >= ProtobufBlockVersion {
return common.Dup(bi.VRF)
}
return nil
}
func (bi *BlockInfo) CopyGenerationSignature() []byte {
return common.Dup(bi.GenerationSignature)
}
func (bi *BlockInfo) CopyGeneratorPublicKey() []byte {
return common.Dup(bi.GeneratorPublicKey.Bytes())
}
func (bi *BlockInfo) IsEmptyGenerator() bool {
return bi.GeneratorPublicKey == crypto.PublicKey{}
}
type FullAssetInfo struct {
AssetInfo
Name string
Description string
ScriptInfo ScriptInfo
SponsorshipCost uint64
IssueTransaction Transaction
SponsorBalance uint64
}
func (i *FullAssetInfo) ToProtobuf(scheme Scheme) (*g.AssetInfoResponse, error) {
res := i.AssetInfo.ToProtobuf()
res.Name = i.Name
res.Description = i.Description
res.Script = i.ScriptInfo.ToProtobuf()
res.Sponsorship = int64(i.SponsorshipCost)
// Issue transaction is optional here
var protoTransaction *waves.SignedTransaction
if i.IssueTransaction != nil {
var err error
protoTransaction, err = i.IssueTransaction.ToProtobufSigned(scheme)
if err != nil {
return nil, err
}
}
res.IssueTransaction = protoTransaction
res.SponsorBalance = int64(i.SponsorBalance)
return res, nil
}
type AssetInfo struct {
ID crypto.Digest
Quantity uint64
Decimals byte
Issuer WavesAddress
IssuerPublicKey crypto.PublicKey
Reissuable bool
Scripted bool
Sponsored bool
IssueHeight Height
}
func (ai *AssetInfo) ToProtobuf() *g.AssetInfoResponse {
return &g.AssetInfoResponse{
Issuer: ai.IssuerPublicKey.Bytes(),
Decimals: int32(ai.Decimals),
Reissuable: ai.Reissuable,
TotalVolume: int64(ai.Quantity),
}
}
type EnrichedFullAssetInfo struct {
FullAssetInfo
SequenceInBlock uint32
}