-
Notifications
You must be signed in to change notification settings - Fork 95
/
address_anchor.gen.go
106 lines (81 loc) · 2.69 KB
/
address_anchor.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 (
// AnchorAddressBytesLength is the length of an AnchorAddress.
AnchorAddressBytesLength = blake2b.Size256
// AnchorAddressSerializedBytesSize is the size of a serialized AnchorAddress with its type denoting byte.
AnchorAddressSerializedBytesSize = serializer.SmallTypeDenotationByteSize + AnchorAddressBytesLength
)
// AnchorAddress defines an AnchorAddress.
// An AnchorAddress is the Blake2b-256 hash of the OutputID which created it.
type AnchorAddress [AnchorAddressBytesLength]byte
func (addr *AnchorAddress) Clone() Address {
cpy := &AnchorAddress{}
copy(cpy[:], addr[:])
return cpy
}
func (addr *AnchorAddress) StorageScore(_ *StorageScoreStructure, _ StorageScoreFunc) StorageScore {
return 0
}
func (addr *AnchorAddress) ID() []byte {
return lo.PanicOnErr(CommonSerixAPI().Encode(context.TODO(), addr))
}
func (addr *AnchorAddress) Key() string {
return string(addr.ID())
}
func (addr *AnchorAddress) ChainID() ChainID {
return AnchorID(*addr)
}
func (addr *AnchorAddress) AnchorID() AnchorID {
return AnchorID(*addr)
}
func (addr *AnchorAddress) Equal(other Address) bool {
otherAddr, is := other.(*AnchorAddress)
if !is {
return false
}
return *addr == *otherAddr
}
func (addr *AnchorAddress) Type() AddressType {
return AddressAnchor
}
func (addr *AnchorAddress) Bech32(hrp NetworkPrefix) string {
return bech32StringBytes(hrp, addr.ID())
}
func (addr *AnchorAddress) String() string {
return hexutil.EncodeHex(addr.ID())
}
func (addr *AnchorAddress) Size() int {
return AnchorAddressSerializedBytesSize
}
// AnchorAddressFromOutputID returns the AnchorAddress computed from a given OutputID.
func AnchorAddressFromOutputID(outputID OutputID) *AnchorAddress {
address := blake2b.Sum256(outputID[:])
return (*AnchorAddress)(&address)
}
// AnchorAddressFromReader parses the AnchorAddress from the given reader.
func AnchorAddressFromReader(reader io.Reader) (*AnchorAddress, error) {
addrBytes, err := stream.ReadBytes(reader, AnchorAddressSerializedBytesSize)
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.(*AnchorAddress)
if !ok {
return nil, ierrors.Errorf("invalid address type: %T", addr)
}
return address, nil
}