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 "Signer.h"
8
#include "Hash.h"
9
#include "HexCoding.h"
10
#include "Transaction.h"
11
#include "TransactionBuilder.h"
12
#include "TransactionSigner.h"
13

14
using namespace TW;
15
using namespace TW::Bitcoin;
16

17 1
Proto::TransactionPlan Signer::plan(const Proto::SigningInput& input) noexcept {
18 1
    auto signer = TransactionSigner<Transaction, TransactionBuilder>(std::move(input));
19 1
    return signer.plan.proto();
20
}
21

22 1
Proto::SigningOutput Signer::sign(const Proto::SigningInput &input) noexcept {
23 1
    Proto::SigningOutput output;
24 1
    auto signer = TransactionSigner<Transaction, TransactionBuilder>(std::move(input));
25 1
    auto result = signer.sign();
26 1
    if (!result) {
27 0
        output.set_error(result.error());
28 0
        return output;
29
    }
30

31 1
    const auto& tx = result.payload();
32 1
    *output.mutable_transaction() = tx.proto();
33

34 1
    Data encoded;
35 1
    signer.encodeTx(tx, encoded);
36 1
    output.set_encoded(encoded.data(), encoded.size());
37

38 1
    Data txHashData = encoded;
39 1
    if (tx.hasWitness()) {
40 0
        txHashData.clear();
41 0
        tx.encode(txHashData, Transaction::SegwitFormatMode::NonSegwit);
42
    }
43 1
    auto txHash = Hash::sha256d(txHashData.data(), txHashData.size());
44 1
    std::reverse(txHash.begin(), txHash.end());
45 1
    output.set_transaction_id(hex(txHash));
46 1
    return output;
47
}

Read our documentation on viewing source code .

Loading