libbtc
bitcoinclibrary
script.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 #ifndef __LIBBTC_SCRIPT_H__
28 #define __LIBBTC_SCRIPT_H__
29 
30 #include "btc.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include "cstr.h"
37 #include "ecc_key.h"
38 #include "vector.h"
39 
41 enum {
46 };
47 
49 enum opcodetype {
50  // push value
51  OP_0 = 0x00,
53  OP_PUSHDATA1 = 0x4c,
54  OP_PUSHDATA2 = 0x4d,
55  OP_PUSHDATA4 = 0x4e,
56  OP_1NEGATE = 0x4f,
57  OP_RESERVED = 0x50,
58  OP_1 = 0x51,
60  OP_2 = 0x52,
61  OP_3 = 0x53,
62  OP_4 = 0x54,
63  OP_5 = 0x55,
64  OP_6 = 0x56,
65  OP_7 = 0x57,
66  OP_8 = 0x58,
67  OP_9 = 0x59,
68  OP_10 = 0x5a,
69  OP_11 = 0x5b,
70  OP_12 = 0x5c,
71  OP_13 = 0x5d,
72  OP_14 = 0x5e,
73  OP_15 = 0x5f,
74  OP_16 = 0x60,
75 
76  // control
77  OP_NOP = 0x61,
78  OP_VER = 0x62,
79  OP_IF = 0x63,
80  OP_NOTIF = 0x64,
81  OP_VERIF = 0x65,
82  OP_VERNOTIF = 0x66,
83  OP_ELSE = 0x67,
84  OP_ENDIF = 0x68,
85  OP_VERIFY = 0x69,
86  OP_RETURN = 0x6a,
87 
88  // stack ops
89  OP_TOALTSTACK = 0x6b,
91  OP_2DROP = 0x6d,
92  OP_2DUP = 0x6e,
93  OP_3DUP = 0x6f,
94  OP_2OVER = 0x70,
95  OP_2ROT = 0x71,
96  OP_2SWAP = 0x72,
97  OP_IFDUP = 0x73,
98  OP_DEPTH = 0x74,
99  OP_DROP = 0x75,
100  OP_DUP = 0x76,
101  OP_NIP = 0x77,
102  OP_OVER = 0x78,
103  OP_PICK = 0x79,
104  OP_ROLL = 0x7a,
105  OP_ROT = 0x7b,
106  OP_SWAP = 0x7c,
107  OP_TUCK = 0x7d,
108 
109  // splice ops
110  OP_CAT = 0x7e,
111  OP_SUBSTR = 0x7f,
112  OP_LEFT = 0x80,
113  OP_RIGHT = 0x81,
114  OP_SIZE = 0x82,
115 
116  // bit logic
117  OP_INVERT = 0x83,
118  OP_AND = 0x84,
119  OP_OR = 0x85,
120  OP_XOR = 0x86,
121  OP_EQUAL = 0x87,
123  OP_RESERVED1 = 0x89,
124  OP_RESERVED2 = 0x8a,
125 
126  // numeric
127  OP_1ADD = 0x8b,
128  OP_1SUB = 0x8c,
129  OP_2MUL = 0x8d,
130  OP_2DIV = 0x8e,
131  OP_NEGATE = 0x8f,
132  OP_ABS = 0x90,
133  OP_NOT = 0x91,
134  OP_0NOTEQUAL = 0x92,
135 
136  OP_ADD = 0x93,
137  OP_SUB = 0x94,
138  OP_MUL = 0x95,
139  OP_DIV = 0x96,
140  OP_MOD = 0x97,
141  OP_LSHIFT = 0x98,
142  OP_RSHIFT = 0x99,
143 
144  OP_BOOLAND = 0x9a,
145  OP_BOOLOR = 0x9b,
146  OP_NUMEQUAL = 0x9c,
149  OP_LESSTHAN = 0x9f,
153  OP_MIN = 0xa3,
154  OP_MAX = 0xa4,
155 
156  OP_WITHIN = 0xa5,
157 
158  // crypto
159  OP_RIPEMD160 = 0xa6,
160  OP_SHA1 = 0xa7,
161  OP_SHA256 = 0xa8,
162  OP_HASH160 = 0xa9,
163  OP_HASH256 = 0xaa,
165  OP_CHECKSIG = 0xac,
169 
170  // expansion
171  OP_NOP1 = 0xb0,
172  OP_NOP2 = 0xb1,
174  OP_NOP3 = 0xb2,
175  OP_NOP4 = 0xb3,
176  OP_NOP5 = 0xb4,
177  OP_NOP6 = 0xb5,
178  OP_NOP7 = 0xb6,
179  OP_NOP8 = 0xb7,
180  OP_NOP9 = 0xb8,
181  OP_NOP10 = 0xb9,
182 
183 
184  // template matching params
186  OP_PUBKEYS = 0xfb,
188  OP_PUBKEY = 0xfe,
189 
191 };
192 
195  // 'standard' transaction types:
200 };
201 
202 typedef struct btc_script_op_
203 {
204  enum opcodetype op; /* opcode found */
205  unsigned char* data; /* associated data, if any */
206  size_t datalen;
207 } btc_script_op;
208 
209 //copy a script without the codeseperator ops
211 
214 void btc_script_op_free_cb(void* data);
215 btc_bool btc_script_get_ops(const cstring* script_in, vector* ops_out);
216 
218 
219 LIBBTC_API btc_bool btc_script_build_multisig(cstring* script_in, unsigned int required_signatures, vector *pubkeys_chars);
220 LIBBTC_API btc_bool btc_script_build_p2pkh(cstring* script, const uint8_t *hash160);
221 LIBBTC_API btc_bool btc_script_build_p2sh(cstring* script_in, const uint8_t *hash160);
222 #ifdef __cplusplus
223 }
224 #endif
225 
226 #endif // __LIBBTC_SCRIPT_H__
Definition: script.h:133
Definition: script.h:62
Definition: script.h:118
uint8_t btc_bool
Definition: btc.h:34
LIBBTC_API btc_bool btc_script_build_p2sh(cstring *script_in, const uint8_t *hash160)
Definition: script.c:338
Definition: vector.h:39
#define LIBBTC_API
Definition: btc.h:59
Definition: script.h:101
Definition: script.h:154
Definition: script.h:93
Definition: script.h:79
Definition: script.h:72
Definition: script.h:68
Definition: script.h:95
Definition: script.h:132
Definition: script.h:60
Definition: script.h:139
Definition: script.h:66
btc_bool btc_script_copy_without_op_codeseperator(const cstring *scriptin, cstring *scriptout)
Definition: script.c:36
Definition: script.h:61
size_t datalen
Definition: script.h:206
LIBBTC_API void btc_script_op_free(btc_script_op *script_op)
Definition: script.c:90
Definition: script.h:153
Definition: script.h:74
Definition: script.h:70
Definition: script.h:119
btc_bool btc_script_get_ops(const cstring *script_in, vector *ops_out)
Definition: script.c:108
struct btc_script_op_ btc_script_op
LIBBTC_API btc_bool btc_script_build_p2pkh(cstring *script, const uint8_t *hash160)
Definition: script.c:323
Definition: script.h:63
Definition: script.h:140
enum btc_tx_out_type btc_script_classify(vector *ops)
Definition: script.c:243
opcodetype
Definition: script.h:49
LIBBTC_API btc_script_op * btc_script_op_new()
Definition: script.c:81
void btc_script_op_free_cb(void *data)
Definition: script.c:100
Definition: script.h:110
Definition: script.h:65
btc_tx_out_type
Definition: script.h:193
Definition: script.h:58
Definition: script.h:77
Definition: script.h:137
Definition: script.h:105
Definition: script.h:138
Definition: script.h:83
Definition: script.h:67
Definition: script.h:99
Definition: script.h:92
Definition: script.h:64
LIBBTC_API btc_bool btc_script_build_multisig(cstring *script_in, unsigned int required_signatures, vector *pubkeys_chars)
Definition: script.c:298
Definition: script.h:71
enum opcodetype op
Definition: script.h:204
Definition: script.h:120
Definition: script.h:69
Definition: script.h:78
Definition: cstr.h:41
Definition: script.h:59
Definition: script.h:51
unsigned char * data
Definition: script.h:205
Definition: script.h:136
Definition: script.h:73
Definition: script.h:100