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 "OngTxBuilder.h"
8

9
using namespace TW;
10
using namespace TW::Ontology;
11

12 1
Data OngTxBuilder::decimals(const Ontology::Proto::SigningInput &input) {
13 1
    auto transaction = Ong().decimals(input.nonce());
14 1
    auto encoded = transaction.serialize();
15 1
    return encoded;
16
}
17

18 1
Data OngTxBuilder::balanceOf(const Ontology::Proto::SigningInput &input) {
19 1
    auto queryAddress = Address(input.query_address());
20 1
    auto transaction = Ong().balanceOf(queryAddress, input.nonce());
21 1
    auto encoded = transaction.serialize();
22 1
    return encoded;
23
}
24

25 1
Data OngTxBuilder::transfer(const Ontology::Proto::SigningInput &input) {
26 1
    auto payer = Signer(PrivateKey(input.payer_private_key()));
27 1
    auto owner = Signer(PrivateKey(input.owner_private_key()));
28 1
    auto toAddress = Address(input.to_address());
29 1
    auto transaction = Ong().transfer(owner, toAddress, input.amount(), payer, input.gas_price(),
30 1
                                      input.gas_limit(), input.nonce());
31 1
    auto encoded = transaction.serialize();
32 1
    return encoded;
33
}
34

35 1
Data OngTxBuilder::withdraw(const Ontology::Proto::SigningInput &input) {
36 1
    auto payer = Signer(PrivateKey(input.payer_private_key()));
37 1
    auto owner = Signer(PrivateKey(input.owner_private_key()));
38 1
    auto toAddress = Address(input.to_address());
39 1
    auto transaction = Ong().withdraw(owner, toAddress, input.amount(), payer, input.gas_price(),
40 1
                                      input.gas_limit(), input.nonce());
41 1
    auto encoded = transaction.serialize();
42 1
    return encoded;
43
}
44

45 1
Data OngTxBuilder::build(const Ontology::Proto::SigningInput &input) {
46 1
    auto method = std::string(input.method().begin(), input.method().end());
47 1
    if (method == "transfer") {
48 1
        return OngTxBuilder::transfer(input);
49 1
    } else if (method == "balanceOf") {
50 1
        return OngTxBuilder::balanceOf(input);
51 1
    } else if (method == "decimals") {
52 1
        return OngTxBuilder::decimals(input);
53 1
    } else if (method == "withdraw") {
54 1
        return OngTxBuilder::withdraw(input);
55
    }
56 0
    return Data();
57
}

Read our documentation on viewing source code .

Loading