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 "Bitcoin/TransactionBuilder.h"
9
#include "Bitcoin/TransactionSigner.h"
10
#include "Hash.h"
11
#include "Data.h"
12
#include "HexCoding.h"
13
#include "Transaction.h"
14

15
using namespace TW;
16
using namespace TW::Groestlcoin;
17

18
using TransactionBuilder = Bitcoin::TransactionBuilder;
19

20 1
TransactionPlan Signer::plan(const SigningInput& input) noexcept {
21 1
    auto signer = Bitcoin::TransactionSigner<Transaction, TransactionBuilder>(std::move(input));
22 1
    return signer.plan.proto();
23
}
24

25 1
SigningOutput Signer::sign(const SigningInput& input) noexcept {
26 1
    SigningOutput output;
27 1
    auto signer = Bitcoin::TransactionSigner<Transaction, TransactionBuilder>(std::move(input));
28 1
    auto result = signer.sign();
29 1
    if (!result) {
30 0
        output.set_error(result.error());
31 0
        return output;
32
    }
33 1
    const auto& tx = result.payload();
34 1
    *output.mutable_transaction() = tx.proto();
35

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

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

Read our documentation on viewing source code .

Loading