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

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

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

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

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

35 1
Data OntTxBuilder::build(const Ontology::Proto::SigningInput &input) {
36 1
    auto method = std::string(input.method().begin(), input.method().end());
37 1
    if (method == "transfer") {
38 1
        return OntTxBuilder::transfer(input);
39 1
    } else if (method == "balanceOf") {
40 1
        return OntTxBuilder::balanceOf(input);
41 1
    } else if (method == "decimals") {
42 1
        return OntTxBuilder::decimals(input);
43
    }
44 0
    return Data();
45
}

Read our documentation on viewing source code .

Loading