/
doc_manifest.go
61 lines (53 loc) · 1.32 KB
/
doc_manifest.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
package digest
import (
"time"
mongodbstorage "github.com/ProtoconNet/mitum-currency/v3/digest/mongodb"
bsonenc "github.com/ProtoconNet/mitum-currency/v3/digest/util/bson"
"github.com/ProtoconNet/mitum2/base"
"github.com/ProtoconNet/mitum2/util/encoder"
)
type ManifestDoc struct {
mongodbstorage.BaseDoc
va base.Manifest
operations []base.Operation
height base.Height
confirmedAt time.Time
proposer base.Address
round base.Round
}
func NewManifestDoc(
manifest base.Manifest,
enc encoder.Encoder,
height base.Height,
operations []base.Operation,
confirmedAt time.Time,
proposer base.Address,
round base.Round,
) (ManifestDoc, error) {
b, err := mongodbstorage.NewBaseDoc(nil, manifest, enc)
if err != nil {
return ManifestDoc{}, err
}
return ManifestDoc{
BaseDoc: b,
va: manifest,
operations: operations,
height: height,
confirmedAt: confirmedAt,
proposer: proposer,
round: round,
}, nil
}
func (doc ManifestDoc) MarshalBSON() ([]byte, error) {
m, err := doc.BaseDoc.M()
if err != nil {
return nil, err
}
m["block"] = doc.va.Hash()
m["operations"] = len(doc.operations)
m["height"] = doc.height
m["confirmed_at"] = doc.confirmedAt.String()
m["proposer"] = doc.proposer.String()
m["round"] = doc.round.Uint64()
return bsonenc.Marshal(m)
}