-
Notifications
You must be signed in to change notification settings - Fork 95
/
address_implicit_account_creation.gen.go
104 lines (80 loc) · 3.39 KB
/
address_implicit_account_creation.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
package iotago
// Code generated by go generate; DO NOT EDIT. Check gen/ directory instead.
import (
"context"
"crypto/ed25519"
"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 (
// ImplicitAccountCreationAddressBytesLength is the length of an ImplicitAccountCreationAddress.
ImplicitAccountCreationAddressBytesLength = blake2b.Size256
// ImplicitAccountCreationAddressSerializedBytesSize is the size of a serialized ImplicitAccountCreationAddress with its type denoting byte.
ImplicitAccountCreationAddressSerializedBytesSize = serializer.SmallTypeDenotationByteSize + ImplicitAccountCreationAddressBytesLength
)
// ImplicitAccountCreationAddress defines an ImplicitAccountCreationAddress.
// An ImplicitAccountCreationAddress is an address that is used to create implicit accounts by sending basic outputs to it.
type ImplicitAccountCreationAddress [ImplicitAccountCreationAddressBytesLength]byte
func (addr *ImplicitAccountCreationAddress) Clone() Address {
cpy := &ImplicitAccountCreationAddress{}
copy(cpy[:], addr[:])
return cpy
}
func (addr *ImplicitAccountCreationAddress) ID() []byte {
return lo.PanicOnErr(CommonSerixAPI().Encode(context.TODO(), addr))
}
func (addr *ImplicitAccountCreationAddress) Key() string {
return string(addr.ID())
}
func (addr *ImplicitAccountCreationAddress) Unlock(msg []byte, sig Signature) error {
edSig, isEdSig := sig.(*Ed25519Signature)
if !isEdSig {
return ierrors.Wrapf(ErrSignatureAndAddrIncompatible, "can not unlock ImplicitAccountCreationAddress with signature of type %s", sig.Type())
}
return edSig.Valid(msg, (*Ed25519Address)(addr))
}
func (addr *ImplicitAccountCreationAddress) Equal(other Address) bool {
otherAddr, is := other.(*ImplicitAccountCreationAddress)
if !is {
return false
}
return *addr == *otherAddr
}
func (addr *ImplicitAccountCreationAddress) Type() AddressType {
return AddressImplicitAccountCreation
}
func (addr *ImplicitAccountCreationAddress) Bech32(hrp NetworkPrefix) string {
return bech32StringBytes(hrp, addr.ID())
}
func (addr *ImplicitAccountCreationAddress) String() string {
return hexutil.EncodeHex(addr.ID())
}
func (addr *ImplicitAccountCreationAddress) Size() int {
return ImplicitAccountCreationAddressSerializedBytesSize
}
// ImplicitAccountCreationAddressFromPubKey returns the address belonging to the given Ed25519 public key.
func ImplicitAccountCreationAddressFromPubKey(pubKey ed25519.PublicKey) *ImplicitAccountCreationAddress {
address := blake2b.Sum256(pubKey[:])
return (*ImplicitAccountCreationAddress)(&address)
}
// ImplicitAccountCreationAddressFromReader parses the ImplicitAccountCreationAddress from the given reader.
func ImplicitAccountCreationAddressFromReader(reader io.Reader) (*ImplicitAccountCreationAddress, error) {
addrBytes, err := stream.ReadBytes(reader, ImplicitAccountCreationAddressSerializedBytesSize)
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.(*ImplicitAccountCreationAddress)
if !ok {
return nil, ierrors.Errorf("invalid address type: %T", addr)
}
return address, nil
}