forked from trustwallet/wallet-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OptInAssetTransaction.cpp
59 lines (43 loc) · 1.41 KB
/
OptInAssetTransaction.cpp
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
// Copyright © 2017-2023 Trust Wallet.
//
// This file is part of Trust. The full Trust copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.
#include "OptInAssetTransaction.h"
#include "BinaryCoding.h"
namespace TW::Algorand {
Data OptInAssetTransaction::serialize() const {
Data data;
// encode map length
uint8_t size = 9;
if (!note.empty()) {
// note is optional
size += 1;
}
data.push_back(0x80 + size);
// encode fields one by one (sorted by name)
encodeString("arcv", data);
encodeBytes(Data(address.bytes.begin(), address.bytes.end()), data);
encodeString("fee", data);
encodeNumber(fee, data);
encodeString("fv", data);
encodeNumber(firstRound, data);
encodeString("gen", data);
encodeString(genesisId, data);
encodeString("gh", data);
encodeBytes(genesisHash, data);
encodeString("lv", data);
encodeNumber(lastRound, data);
if (!note.empty()) {
encodeString("note", data);
encodeBytes(note, data);
}
encodeString("snd", data);
encodeBytes(Data(address.bytes.begin(), address.bytes.end()), data);
encodeString("type", data);
encodeString(type, data);
encodeString("xaid", data);
encodeNumber(assetId, data);
return data;
}
} // namespace TW::Algorand