-
Notifications
You must be signed in to change notification settings - Fork 2
/
atx.go
53 lines (47 loc) · 2.14 KB
/
atx.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
package model
import (
"context"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/explorer-backend/utils"
)
type Activation struct {
Id string `json:"id" bson:"id"` //nolint will fix it later.
SmesherId string `json:"smesher" bson:"smesher"` //nolint will fix it later // id of smesher who created the ATX
Coinbase string `json:"coinbase" bson:"coinbase"` // coinbase account id
PrevAtx string `json:"prevAtx" bson:"prevAtx"` // previous ATX pointed to
NumUnits uint32 `json:"numunits" bson:"numunits"` // number of PoST data commitment units
CommitmentSize uint64 `json:"commitmentSize" bson:"commitmentSize"`
PublishEpoch uint32 `json:"publishEpoch" bson:"publishEpoch"`
TargetEpoch uint32 `json:"targetEpoch" bson:"targetEpoch"`
TickCount uint64 `json:"tickCount" bson:"tickCount"`
Weight uint64 `json:"weight" bson:"weight"`
EffectiveNumUnits uint32 `json:"effectiveNumUnits" bson:"effectiveNumUnits"`
Received int64 `json:"received" bson:"received"`
}
type ActivationService interface {
GetActivations(ctx context.Context, page, perPage int64) (atxs []*Activation, total int64, err error)
GetActivation(ctx context.Context, activationID string) (*Activation, error)
}
func NewActivation(atx *types.VerifiedActivationTx) *Activation {
return &Activation{
Id: utils.BytesToHex(atx.ID().Bytes()),
PublishEpoch: atx.PublishEpoch.Uint32(),
TargetEpoch: atx.PublishEpoch.Uint32() + 1,
SmesherId: utils.BytesToHex(atx.SmesherID.Bytes()),
Coinbase: atx.Coinbase.String(),
PrevAtx: utils.BytesToHex(atx.PrevATXID.Bytes()),
NumUnits: atx.NumUnits,
TickCount: atx.TickCount(),
Weight: atx.GetWeight(),
EffectiveNumUnits: atx.EffectiveNumUnits(),
Received: atx.Received().UnixNano(),
}
}
func (atx *Activation) GetSmesher(unitSize uint64) *Smesher {
return &Smesher{
Id: atx.SmesherId,
Coinbase: atx.Coinbase,
Timestamp: uint64(atx.Received),
CommitmentSize: uint64(atx.NumUnits) * unitSize,
}
}