-
Notifications
You must be signed in to change notification settings - Fork 95
/
address_nft.gen.go
106 lines (81 loc) · 2.57 KB
/
address_nft.gen.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package iotago
// Code generated by go generate; DO NOT EDIT. Check gen/ directory instead.
import (
"context"
"io"
"golang.org/x/crypto/blake2b"
"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/lo"
"github.com/iotaledger/hive.go/serializer/v2"
"github.com/iotaledger/hive.go/serializer/v2/stream"
"github.com/iotaledger/iota.go/v4/hexutil"
)
const (
// NFTAddressBytesLength is the length of an NFTAddress.
NFTAddressBytesLength = blake2b.Size256
// NFTAddressSerializedBytesSize is the size of a serialized NFTAddress with its type denoting byte.
NFTAddressSerializedBytesSize = serializer.SmallTypeDenotationByteSize + NFTAddressBytesLength
)
// NFTAddress defines an NFTAddress.
// An NFTAddress is the Blake2b-256 hash of the OutputID which created it.
type NFTAddress [NFTAddressBytesLength]byte
func (addr *NFTAddress) Clone() Address {
cpy := &NFTAddress{}
copy(cpy[:], addr[:])
return cpy
}
func (addr *NFTAddress) StorageScore(_ *StorageScoreStructure, _ StorageScoreFunc) StorageScore {
return 0
}
func (addr *NFTAddress) ID() []byte {
return lo.PanicOnErr(CommonSerixAPI().Encode(context.TODO(), addr))
}
func (addr *NFTAddress) Key() string {
return string(addr.ID())
}
func (addr *NFTAddress) ChainID() ChainID {
return NFTID(*addr)
}
func (addr *NFTAddress) NFTID() NFTID {
return NFTID(*addr)
}
func (addr *NFTAddress) Equal(other Address) bool {
otherAddr, is := other.(*NFTAddress)
if !is {
return false
}
return *addr == *otherAddr
}
func (addr *NFTAddress) Type() AddressType {
return AddressNFT
}
func (addr *NFTAddress) Bech32(hrp NetworkPrefix) string {
return bech32StringBytes(hrp, addr.ID())
}
func (addr *NFTAddress) String() string {
return hexutil.EncodeHex(addr.ID())
}
func (addr *NFTAddress) Size() int {
return NFTAddressSerializedBytesSize
}
// NFTAddressFromOutputID returns the NFTAddress computed from a given OutputID.
func NFTAddressFromOutputID(outputID OutputID) *NFTAddress {
address := blake2b.Sum256(outputID[:])
return (*NFTAddress)(&address)
}
// NFTAddressFromReader parses the NFTAddress from the given reader.
func NFTAddressFromReader(reader io.Reader) (*NFTAddress, error) {
addrBytes, err := stream.ReadBytes(reader, NFTAddressSerializedBytesSize)
if err != nil {
return nil, ierrors.Wrap(err, "unable to read address bytes")
}
addr, _, err := AddressFromBytes(addrBytes)
if err != nil {
return nil, ierrors.Wrap(err, "unable to parse address from bytes")
}
address, ok := addr.(*NFTAddress)
if !ok {
return nil, ierrors.Errorf("invalid address type: %T", addr)
}
return address, nil
}