forked from trustwallet/wallet-core
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAction.cpp
More file actions
65 lines (55 loc) · 1.95 KB
/
Action.cpp
File metadata and controls
65 lines (55 loc) · 1.95 KB
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
// Copyright © 2017-2020 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 "Action.h"
#include "../HexCoding.h"
#include "../Bravo/Serialization.h"
using namespace TW;
using namespace TW::EOS;
using json = nlohmann::json;
void PermissionLevel::serialize(Data& o) const {
actor.serialize(o);
permission.serialize(o);
}
json PermissionLevel::serialize() const noexcept {
json obj;
obj["actor"] = actor.string();
obj["permission"] = permission.string();
return obj;
}
void Action::serialize(Data& o) const {
account.serialize(o);
name.serialize(o);
Bravo::encodeCollection(authorization, o);
Bravo::encodeVarInt64(data.size(), o);
append(o, data);
}
json Action::serialize() const noexcept {
json obj;
obj["account"] = account.string();
obj["name"] = name.string();
obj["authorizations"] = Bravo::encodeCollection(authorization);
obj["data"] = hex(data);
return obj;
}
TransferAction::TransferAction( const std::string& currency,
const std::string& from,
const std::string& to,
const Bravo::Asset& asset,
const std::string& memo) {
account = Name(currency);
name = Name("transfer");
authorization.push_back(PermissionLevel(Name(from), Name("active")));
setData(from, to, asset, memo);
}
void TransferAction::setData(const std::string& from, const std::string& to, const Bravo::Asset& asset, const std::string& memo) {
if (asset.amount <= 0) {
throw std::invalid_argument("Amount in a transfer action must be greater than zero.");
}
Name(from).serialize(data);
Name(to).serialize(data);
asset.serialize(data);
Bravo::encodeString(memo, data);
}