-
Notifications
You must be signed in to change notification settings - Fork 151
/
marshalutils_helper.go
67 lines (55 loc) · 1.5 KB
/
marshalutils_helper.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 utxo
import (
"github.com/iotaledger/hive.go/marshalutil"
"github.com/iotaledger/hive.go/serializer"
"github.com/iotaledger/hornet/pkg/model/hornet"
iotago "github.com/iotaledger/iota.go/v2"
)
func ParseOutputID(ms *marshalutil.MarshalUtil) (*iotago.UTXOInputID, error) {
bytes, err := ms.ReadBytes(OutputIDLength)
if err != nil {
return nil, err
}
o := &iotago.UTXOInputID{}
copy(o[:], bytes)
return o, nil
}
func parseTransactionID(ms *marshalutil.MarshalUtil) (*iotago.TransactionID, error) {
bytes, err := ms.ReadBytes(iotago.TransactionIDLength)
if err != nil {
return nil, err
}
t := &iotago.TransactionID{}
copy(t[:], bytes)
return t, nil
}
func ParseMessageID(ms *marshalutil.MarshalUtil) (hornet.MessageID, error) {
bytes, err := ms.ReadBytes(iotago.MessageIDLength)
if err != nil {
return nil, err
}
return hornet.MessageIDFromSlice(bytes), nil
}
func parseAddress(ms *marshalutil.MarshalUtil) (iotago.Address, error) {
addrType, err := ms.ReadByte()
if err != nil {
return nil, err
}
// Move the cursor back
ms.ReadSeek(-1)
addr, err := iotago.AddressSelector(uint32(addrType))
if err != nil {
return nil, err
}
address := addr.(iotago.Address)
pre := ms.ReadOffset()
readBytes, err := address.Deserialize(ms.ReadRemainingBytes(), serializer.DeSeriModePerformValidation)
if err != nil {
return nil, err
}
post := ms.ReadOffset()
bytesReadTooFar := post - pre - readBytes
// Move the cursor back some bytes
ms.ReadSeek(-bytesReadTooFar)
return address, err
}