-
Notifications
You must be signed in to change notification settings - Fork 671
/
payload.go
48 lines (41 loc) · 1.01 KB
/
payload.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
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package tx
import "github.com/ava-labs/avalanchego/ids"
type Payload struct {
// Sender + Nonce provides replay protection
Sender ids.ShortID `serialize:"true" json:"sender"`
Nonce uint64 `serialize:"true" json:"nonce"`
IsReturn bool `serialize:"true" json:"isReturn"`
Amount uint64 `serialize:"true" json:"amount"`
To ids.ShortID `serialize:"true" json:"to"`
bytes []byte
}
func (p *Payload) Bytes() []byte {
return p.bytes
}
func NewPayload(
sender ids.ShortID,
nonce uint64,
isReturn bool,
amount uint64,
to ids.ShortID,
) (*Payload, error) {
p := &Payload{
Sender: sender,
Nonce: nonce,
IsReturn: isReturn,
Amount: amount,
To: to,
}
bytes, err := Codec.Marshal(Version, p)
p.bytes = bytes
return p, err
}
func ParsePayload(bytes []byte) (*Payload, error) {
p := &Payload{
bytes: bytes,
}
_, err := Codec.Unmarshal(bytes, p)
return p, err
}