-
Notifications
You must be signed in to change notification settings - Fork 210
/
transaction_header.go
48 lines (40 loc) · 1.32 KB
/
transaction_header.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
package types
import "github.com/spacemeshos/go-spacemesh/log"
//go:generate scalegen
// TxHeader is a transaction header, with some of the fields defined directly in the tx
// and the rest is computed by the template based on immutable state and method arguments.
type TxHeader struct {
Principal Address
TemplateAddress Address
Method uint8
Nonce Nonce
LayerLimits LayerLimits
MaxGas uint64
GasPrice uint64
MaxSpend uint64
}
// Fee is a MaxGas multiplied by a GasPrice.
func (h *TxHeader) Fee() uint64 {
return h.MaxGas * h.GasPrice
}
// Spending is Fee() + MaxSpend.
func (h *TxHeader) Spending() uint64 {
return h.Fee() + h.MaxSpend
}
// MarshalLogObject implements encoding for the tx header.
func (h *TxHeader) MarshalLogObject(encoder log.ObjectEncoder) error {
encoder.AddString("principal", h.Principal.String())
encoder.AddUint64("nonce_counter", h.Nonce)
encoder.AddUint32("layer_min", h.LayerLimits.Min)
encoder.AddUint32("layer_max", h.LayerLimits.Max)
encoder.AddUint64("max_gas", h.MaxGas)
encoder.AddUint64("gas_price", h.GasPrice)
encoder.AddUint64("max_spend", h.MaxSpend)
return nil
}
// LayerLimits if defined restricts in what layers transaction may be applied.
type LayerLimits struct {
Min, Max uint32
}
// Nonce alias to uint64.
type Nonce = uint64