2014-04-29 05:26:51 -07:00
|
|
|
/*
|
|
|
|
* This file is part of the TREZOR project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Pavol Rusnak <stick@satoshilabs.com>
|
|
|
|
*
|
|
|
|
* This library is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TRANSACTION_H__
|
|
|
|
#define __TRANSACTION_H__
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "sha2.h"
|
|
|
|
#include "bip32.h"
|
|
|
|
#include "types.pb.h"
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint32_t inputs_len;
|
|
|
|
uint32_t outputs_len;
|
|
|
|
|
|
|
|
uint32_t version;
|
|
|
|
uint32_t lock_time;
|
2016-04-29 13:15:55 -07:00
|
|
|
bool add_hash_type, is_segwit;
|
2014-04-29 05:26:51 -07:00
|
|
|
|
|
|
|
uint32_t have_inputs;
|
|
|
|
uint32_t have_outputs;
|
2016-10-19 00:37:46 -07:00
|
|
|
|
|
|
|
uint32_t extra_data_len;
|
|
|
|
uint32_t extra_data_received;
|
|
|
|
|
2014-04-29 05:26:51 -07:00
|
|
|
uint32_t size;
|
|
|
|
|
|
|
|
SHA256_CTX ctx;
|
|
|
|
} TxStruct;
|
|
|
|
|
2017-05-04 09:54:54 -07:00
|
|
|
bool compute_address(const CoinType *coin, InputScriptType script_type, const HDNode *node, bool has_multisig, const MultisigRedeemScriptType *multisig, char address[MAX_ADDR_SIZE]);
|
2016-10-09 12:38:51 -07:00
|
|
|
uint32_t compile_script_sig(uint32_t address_type, const uint8_t *pubkeyhash, uint8_t *out);
|
2014-12-06 10:12:55 -08:00
|
|
|
uint32_t compile_script_multisig(const MultisigRedeemScriptType *multisig, uint8_t *out);
|
2014-12-10 09:04:51 -08:00
|
|
|
uint32_t compile_script_multisig_hash(const MultisigRedeemScriptType *multisig, uint8_t *hash);
|
2014-12-06 10:12:55 -08:00
|
|
|
uint32_t serialize_script_sig(const uint8_t *signature, uint32_t signature_len, const uint8_t *pubkey, uint32_t pubkey_len, uint8_t *out);
|
|
|
|
uint32_t serialize_script_multisig(const MultisigRedeemScriptType *multisig, uint8_t *out);
|
2014-04-29 05:26:51 -07:00
|
|
|
int compile_output(const CoinType *coin, const HDNode *root, TxOutputType *in, TxOutputBinType *out, bool needs_confirm);
|
2016-04-29 12:17:06 -07:00
|
|
|
|
|
|
|
uint32_t tx_prevout_hash(SHA256_CTX *ctx, const TxInputType *input);
|
2016-04-29 13:15:55 -07:00
|
|
|
uint32_t tx_script_hash(SHA256_CTX *ctx, uint32_t size, const uint8_t *data);
|
2016-04-29 12:17:06 -07:00
|
|
|
uint32_t tx_sequence_hash(SHA256_CTX *ctx, const TxInputType *input);
|
|
|
|
uint32_t tx_output_hash(SHA256_CTX *ctx, const TxOutputBinType *output);
|
2016-04-29 13:15:55 -07:00
|
|
|
uint32_t tx_serialize_script(uint32_t size, const uint8_t *data, uint8_t *out);
|
2016-04-29 12:17:06 -07:00
|
|
|
|
2016-04-30 17:47:15 -07:00
|
|
|
uint32_t tx_serialize_footer(TxStruct *tx, uint8_t *out);
|
2014-12-21 10:39:20 -08:00
|
|
|
uint32_t tx_serialize_input(TxStruct *tx, const TxInputType *input, uint8_t *out);
|
|
|
|
uint32_t tx_serialize_output(TxStruct *tx, const TxOutputBinType *output, uint8_t *out);
|
2014-04-29 05:26:51 -07:00
|
|
|
|
2016-10-19 00:37:46 -07:00
|
|
|
void tx_init(TxStruct *tx, uint32_t inputs_len, uint32_t outputs_len, uint32_t version, uint32_t lock_time, uint32_t extra_data_len, bool add_hash_type);
|
2016-10-21 04:20:57 -07:00
|
|
|
uint32_t tx_serialize_header_hash(TxStruct *tx);
|
2014-12-21 10:39:20 -08:00
|
|
|
uint32_t tx_serialize_input_hash(TxStruct *tx, const TxInputType *input);
|
|
|
|
uint32_t tx_serialize_output_hash(TxStruct *tx, const TxOutputBinType *output);
|
2016-10-19 00:37:46 -07:00
|
|
|
uint32_t tx_serialize_extra_data_hash(TxStruct *tx, const uint8_t *data, uint32_t datalen);
|
2014-04-29 05:26:51 -07:00
|
|
|
void tx_hash_final(TxStruct *t, uint8_t *hash, bool reverse);
|
|
|
|
|
|
|
|
uint32_t transactionEstimateSize(uint32_t inputs, uint32_t outputs);
|
|
|
|
|
|
|
|
uint32_t transactionEstimateSizeKb(uint32_t inputs, uint32_t outputs);
|
|
|
|
|
|
|
|
#endif
|