/
prepared_block_for_proposing.go
45 lines (36 loc) · 1.23 KB
/
prepared_block_for_proposing.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
// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only
package telemetry
import (
"encoding/json"
"time"
"github.com/ChainSafe/gossamer/lib/common"
)
type preparedBlockForProposingTM PreparedBlockForProposing
var _ json.Marshaler = (*PreparedBlockForProposing)(nil)
// PreparedBlockForProposing holds a 'prepared_block_for_proposing' telemetry
// message, which is supposed to be sent when a new block is built.
type PreparedBlockForProposing struct {
Hash common.Hash `json:"hash"`
// Height of the chain, Block.Header.Number
Number string `json:"number"`
}
// NewPreparedBlockForProposing gets a new PreparedBlockForProposingTM struct.
func NewPreparedBlockForProposing(hash common.Hash, number string) *PreparedBlockForProposing {
return &PreparedBlockForProposing{
Hash: hash,
Number: number,
}
}
func (pb PreparedBlockForProposing) MarshalJSON() ([]byte, error) {
telemetryData := struct {
preparedBlockForProposingTM
MessageType string `json:"msg"`
Timestamp time.Time `json:"ts"`
}{
Timestamp: time.Now(),
MessageType: preparedBlockForProposingMsg,
preparedBlockForProposingTM: preparedBlockForProposingTM(pb),
}
return json.Marshal(telemetryData)
}