libbtc
bitcoinclibrary
tx.h
Go to the documentation of this file.
1 /*
2 
3  The MIT License (MIT)
4 
5  Copyright (c) 2015 Jonas Schnelli
6 
7  Permission is hereby granted, free of charge, to any person obtaining
8  a copy of this software and associated documentation files (the "Software"),
9  to deal in the Software without restriction, including without limitation
10  the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  and/or sell copies of the Software, and to permit persons to whom the
12  Software is furnished to do so, subject to the following conditions:
13 
14  The above copyright notice and this permission notice shall be included
15  in all copies or substantial portions of the Software.
16 
17  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
21  OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23  OTHER DEALINGS IN THE SOFTWARE.
24 
25 */
26 
27 
28 #ifndef __LIBBTC_TX_H__
29 #define __LIBBTC_TX_H__
30 
31 #include "btc.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #include <stdint.h>
38 #include <stddef.h>
39 #include <stdint.h>
40 
41 #include "chain.h"
42 #include "cstr.h"
43 #include "hash.h"
44 #include "script.h"
45 #include "vector.h"
46 
47 
48 typedef struct btc_script_
49 {
50  int* data;
51  size_t limit; // Total size of the vector
52  size_t current; //Number of vectors in it at present
53 } btc_script;
54 
55 typedef struct btc_tx_outpoint_
56 {
58  uint32_t n;
60 
61 typedef struct btc_tx_in_
62 {
65  uint32_t sequence;
66 } btc_tx_in;
67 
68 typedef struct btc_tx_out_
69 {
70  int64_t value;
72 } btc_tx_out;
73 
74 typedef struct btc_tx_
75 {
76  uint32_t version;
79  uint32_t locktime;
80 } btc_tx;
81 
82 
86 LIBBTC_API void btc_tx_in_copy(btc_tx_in* dest, const btc_tx_in* src);
87 
91 LIBBTC_API void btc_tx_out_copy(btc_tx_out* dest, const btc_tx_out* src);
92 
95 LIBBTC_API void btc_tx_free(btc_tx* tx);
96 LIBBTC_API void btc_tx_copy(btc_tx* dest, const btc_tx* src);
97 
99 LIBBTC_API int btc_tx_deserialize(const unsigned char* tx_serialized, size_t inlen, btc_tx* tx);
100 
102 LIBBTC_API void btc_tx_serialize(cstring* s, const btc_tx* tx);
103 
104 LIBBTC_API void btc_tx_hash(const btc_tx* tx, uint8_t *hashout);
105 
106 LIBBTC_API btc_bool btc_tx_sighash(const btc_tx* tx_to, const cstring* fromPubKey, unsigned int in_num, int hashtype, uint8_t* hash);
107 
108 LIBBTC_API btc_bool btc_tx_add_address_out(btc_tx* tx, const btc_chain* chain, int64_t amount, const char *address);
109 LIBBTC_API btc_bool btc_tx_add_p2sh_hash160_out(btc_tx* tx, int64_t amount, uint8_t *hash160);
110 LIBBTC_API btc_bool btc_tx_add_p2pkh_hash160_out(btc_tx* tx, int64_t amount, uint8_t *hash160);
111 LIBBTC_API btc_bool btc_tx_add_p2pkh_out(btc_tx* tx, int64_t amount, const btc_pubkey *pubkey);
112 #ifdef __cplusplus
113 }
114 #endif
115 
116 #endif //__LIBBTC_TX_H__
uint8_t btc_bool
Definition: btc.h:34
Definition: tx.h:68
size_t current
Definition: tx.h:52
Definition: vector.h:39
size_t limit
Definition: tx.h:51
Definition: tx.h:48
#define LIBBTC_API
Definition: btc.h:59
int * data
Definition: tx.h:50
LIBBTC_API void btc_tx_in_free(btc_tx_in *tx_in)
Definition: tx.c:39
uint32_t sequence
Definition: tx.h:65
LIBBTC_API void btc_tx_out_free(btc_tx_out *tx_out)
Definition: tx.c:77
LIBBTC_API void btc_tx_serialize(cstring *s, const btc_tx *tx)
serialize a lbc bitcoin data structure into a p2p serialized buffer
Definition: tx.c:210
LIBBTC_API int btc_tx_deserialize(const unsigned char *tx_serialized, size_t inlen, btc_tx *tx)
deserialize/parse a p2p serialized bitcoin transaction
Definition: tx.c:157
LIBBTC_API btc_bool btc_tx_add_p2pkh_out(btc_tx *tx, int64_t amount, const btc_pubkey *pubkey)
Definition: tx.c:475
LIBBTC_API btc_bool btc_tx_add_p2sh_hash160_out(btc_tx *tx, int64_t amount, uint8_t *hash160)
Definition: tx.c:461
Definition: tx.h:61
LIBBTC_API btc_bool btc_tx_sighash(const btc_tx *tx_to, const cstring *fromPubKey, unsigned int in_num, int hashtype, uint8_t *hash)
Definition: tx.c:330
btc_tx_outpoint prevout
Definition: tx.h:63
struct btc_tx_in_ btc_tx_in
LIBBTC_API btc_bool btc_tx_add_address_out(btc_tx *tx, const btc_chain *chain, int64_t amount, const char *address)
Definition: tx.c:426
cstring * script_sig
Definition: tx.h:64
LIBBTC_API btc_bool btc_tx_add_p2pkh_hash160_out(btc_tx *tx, int64_t amount, uint8_t *hash160)
Definition: tx.c:447
LIBBTC_API btc_tx_in * btc_tx_in_new()
create a new tx input
Definition: tx.c:67
LIBBTC_API void btc_tx_copy(btc_tx *dest, const btc_tx *src)
Definition: tx.c:283
struct btc_tx_outpoint_ btc_tx_outpoint
uint32_t locktime
Definition: tx.h:79
uint32_t n
Definition: tx.h:58
cstring * script_pubkey
Definition: tx.h:71
struct btc_script_ btc_script
struct btc_tx_ btc_tx
vector * vin
Definition: tx.h:77
LIBBTC_API btc_tx * btc_tx_new()
create a new tx input
Definition: tx.c:124
uint256 hash
Definition: tx.h:57
LIBBTC_API void btc_tx_out_copy(btc_tx_out *dest, const btc_tx_out *src)
Definition: tx.c:268
uint32_t version
Definition: tx.h:76
LIBBTC_API void btc_tx_in_copy(btc_tx_in *dest, const btc_tx_in *src)
Definition: tx.c:252
int64_t value
Definition: tx.h:70
LIBBTC_API void btc_tx_hash(const btc_tx *tx, uint8_t *hashout)
Definition: tx.c:240
struct btc_tx_out_ btc_tx_out
Definition: tx.h:74
Definition: cstr.h:41
LIBBTC_API btc_tx_out * btc_tx_out_new()
create a new tx output
Definition: tx.c:103
LIBBTC_API void btc_tx_free(btc_tx *tx)
Definition: tx.c:112
uint8_t uint256[32]
Definition: hash.h:44
vector * vout
Definition: tx.h:78