forked from blocto/solana-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.go
55 lines (47 loc) · 1.38 KB
/
state.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
package sysprog
import (
"encoding/binary"
"fmt"
"github.com/doesnotcommit/solana-go-sdk/common"
)
const FeeCalculatorSize = 8
type FeeCalculator struct {
LamportsPerSignature uint64
}
func FeeCalculatorDeserialize(data []byte) (FeeCalculator, error) {
if len(data) < FeeCalculatorSize {
return FeeCalculator{}, fmt.Errorf("fee calculator data size is not enough")
}
lamportsPerSignature := binary.LittleEndian.Uint64(data[:8])
return FeeCalculator{
LamportsPerSignature: lamportsPerSignature,
}, nil
}
const NonceAccountSize = 80
type NonceAccount struct {
Version uint32
State uint32
AuthorizedPubkey common.PublicKey
Nonce common.PublicKey
FeeCalculator FeeCalculator
}
func NonceAccountDeserialize(data []byte) (NonceAccount, error) {
if len(data) < NonceAccountSize {
return NonceAccount{}, fmt.Errorf("nonce account data size is not enough")
}
version := binary.LittleEndian.Uint32(data[:4])
state := binary.LittleEndian.Uint32(data[4:8])
authorizedPubkey := common.PublicKeyFromBytes(data[8:40])
nonce := common.PublicKeyFromBytes(data[40:72])
feeCalculator, err := FeeCalculatorDeserialize(data[72:])
if err != nil {
return NonceAccount{}, err
}
return NonceAccount{
Version: version,
State: state,
AuthorizedPubkey: authorizedPubkey,
Nonce: nonce,
FeeCalculator: feeCalculator,
}, nil
}