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