/
state.go
67 lines (57 loc) · 1.36 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
56
57
58
59
60
61
62
63
64
65
66
67
package tokenmeta
import (
"fmt"
"strings"
"github.com/near/borsh-go"
"github.com/portto/solana-go-sdk/common"
)
const EDITION_MARKER_BIT_SIZE uint64 = 248
type Key borsh.Enum
const (
KeyUninitialized Key = iota
KeyEditionV1
KeyMasterEditionV1
KeyReservationListV1
KeyMetadataV1
KeyReservationListV2
KeyMasterEditionV2
KeyEditionMarker
)
type Creator struct {
Address common.PublicKey
Verified bool
Share uint8
}
type Data struct {
Name string
Symbol string
Uri string
SellerFeeBasisPoints uint16
Creators *[]Creator
}
type Metadata struct {
Key Key
UpdateAuthority common.PublicKey
Mint common.PublicKey
Data Data
PrimarySaleHappened bool
IsMutable bool
EditionNonce *uint8
}
func MetadataDeserialize(data []byte) (Metadata, error) {
var metadata Metadata
err := borsh.Deserialize(&metadata, data)
if err != nil {
return Metadata{}, fmt.Errorf("failed to deserialize data, err: %v", err)
}
// trim null byte
metadata.Data.Name = strings.TrimRight(metadata.Data.Name, "\x00")
metadata.Data.Symbol = strings.TrimRight(metadata.Data.Symbol, "\x00")
metadata.Data.Uri = strings.TrimRight(metadata.Data.Uri, "\x00")
return metadata, nil
}
type MasterEditionV2 struct {
Key Key
Supply uint64
MaxSupply *uint64
}