1
|
|
// Copyright © 2017-2020 Trust Wallet.
|
2
|
|
//
|
3
|
|
// This file is part of Trust. The full Trust copyright notice, including
|
4
|
|
// terms governing use, modification, and redistribution, is contained in the
|
5
|
|
// file LICENSE at the root of the source code distribution tree.
|
6
|
|
|
7
|
|
#include "Ong.h"
|
8
|
|
#include "Data.h"
|
9
|
|
#include "ParamsBuilder.h"
|
10
|
|
|
11
|
|
#include <list>
|
12
|
|
|
13
|
|
using namespace TW;
|
14
|
|
using namespace TW::Ontology;
|
15
|
|
|
16
|
1
|
Transaction Ong::decimals(uint32_t nonce) {
|
17
|
1
|
auto builder = ParamsBuilder();
|
18
|
|
auto invokeCode =
|
19
|
1
|
ParamsBuilder::buildNativeInvokeCode(contractAddress(), version, "decimals", Data());
|
20
|
1
|
auto tx =
|
21
|
1
|
Transaction(version, txType, nonce, (uint64_t)0, (uint64_t)0, (std::string) "", invokeCode);
|
22
|
1
|
return tx;
|
23
|
|
}
|
24
|
|
|
25
|
1
|
Transaction Ong::balanceOf(const Address &address, uint32_t nonce) {
|
26
|
1
|
auto builder = ParamsBuilder();
|
27
|
|
auto invokeCode =
|
28
|
1
|
ParamsBuilder::buildNativeInvokeCode(contractAddress(), version, "balanceOf", address.data);
|
29
|
1
|
auto tx =
|
30
|
1
|
Transaction(version, txType, nonce, (uint64_t)0, (uint64_t)0, (std::string) "", invokeCode);
|
31
|
1
|
return tx;
|
32
|
|
}
|
33
|
|
|
34
|
1
|
Transaction Ong::transfer(const Signer &from, const Address &to, uint64_t amount,
|
35
|
|
const Signer &payer, uint64_t gasPrice, uint64_t gasLimit,
|
36
|
|
uint32_t nonce) {
|
37
|
1
|
std::list<boost::any> transferParam{from.getAddress().data, to.data, amount};
|
38
|
1
|
std::vector<boost::any> args{transferParam};
|
39
|
|
auto invokeCode =
|
40
|
1
|
ParamsBuilder::buildNativeInvokeCode(contractAddress(), 0x00, "transfer", args);
|
41
|
1
|
auto tx = Transaction(version, txType, nonce, gasPrice, gasLimit, payer.getAddress().string(),
|
42
|
1
|
invokeCode);
|
43
|
1
|
from.sign(tx);
|
44
|
1
|
payer.addSign(tx);
|
45
|
1
|
return tx;
|
46
|
|
}
|
47
|
|
|
48
|
1
|
Transaction Ong::withdraw(const Signer &claimer, const Address &receiver, uint64_t amount,
|
49
|
|
const Signer &payer, uint64_t gasPrice, uint64_t gasLimit,
|
50
|
|
uint32_t nonce) {
|
51
|
1
|
auto ontContract = Address("AFmseVrdL9f9oyCzZefL9tG6UbvhUMqNMV");
|
52
|
1
|
std::list<boost::any> args{claimer.getAddress().data, ontContract.data, receiver.data, amount};
|
53
|
|
auto invokeCode =
|
54
|
1
|
ParamsBuilder::buildNativeInvokeCode(contractAddress(), 0x00, "transferFrom", args);
|
55
|
1
|
auto tx = Transaction(version, txType, nonce, gasPrice, gasLimit, payer.getAddress().string(),
|
56
|
1
|
invokeCode);
|
57
|
1
|
claimer.sign(tx);
|
58
|
1
|
payer.addSign(tx);
|
59
|
1
|
return tx;
|
60
|
|
}
|