cbitcoin
 All Data Structures Files Functions Variables Typedefs
src/CBConstants.h
00001 //
00002 //  CBConstants.h
00003 //  cbitcoin
00004 //
00005 //  Created by Matthew Mitchell on 28/04/2012.
00006 //  Copyright (c) 2012 Matthew Mitchell
00007 //  
00008 //  This file is part of cbitcoin.
00009 //
00010 //  cbitcoin is free software: you can redistribute it and/or modify
00011 //  it under the terms of the GNU General Public License as published by
00012 //  the Free Software Foundation, either version 3 of the License, or
00013 //  (at your option) any later version.
00014 //  
00015 //  cbitcoin is distributed in the hope that it will be useful,
00016 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 //  GNU General Public License for more details.
00019 //  
00020 //  You should have received a copy of the GNU General Public License
00021 //  along with cbitcoin.  If not, see <http://www.gnu.org/licenses/>.
00022 
00023 #ifndef CBCONSTANTSH
00024 #define CBCONSTANTSH
00025 
00026 //  Macros
00027 
00028 #define CB_MESSAGE_MAX_SIZE 0x02000000 // 32 MB
00029 #define CB_BLOCK_ALLOWED_TIME_DRIFT 7200 // 2 Hours from network time
00030 #define CB_NETWORK_TIME_ALLOWED_TIME_DRIFT 4200 // 70 minutes from system time
00031 #define CB_MIN_PROTO_VERSION 209
00032 #define CB_ADDR_TIME_VERSION 31402 // Version where times are included in addr messages.
00033 #define CB_PONG_VERSION 60000 // Version where pings are responded with pongs.
00034 #define CB_LIBRARY_VERSION 2 // Goes up in increments
00035 #define CB_LIBRARY_VERSION_STRING "1.0 alpha-2" // Features.Non-features pre-alpha/alpha/beta
00036 #define CB_USER_AGENT_SEGMENT "/cbitcoin:1.0(alpha-2)/"
00037 #define CB_PRODUCTION_NETWORK_BYTE 0 // The normal network for trading
00038 #define CB_TEST_NETWORK_BYTE 111 // The network for testing
00039 #define CB_PRODUCTION_NETWORK_BYTES 0xD9B4BEF9 // The normal network for trading
00040 #define CB_TEST_NETWORK_BYTES 0xDAB5BFFA // The network for testing
00041 #define CB_TRANSACTION_INPUT_FINAL 0xFFFFFFFF // Transaction input is final
00042 #define CB_TRANSACTION_INPUT_OUT_POINTER_MESSAGE_LENGTH 36
00043 #define CB_BLOCK_MAX_SIZE 1000000 // ~0.95 MB Not including header.
00044 #define CB_TRANSACTION_MAX_SIZE CB_BLOCK_MAX_SIZE - 81 // Minus the header
00045 #define CB_VERSION_MAX_SIZE 492 // Includes 400 characters for the user-agent and the 9 byte var int.
00046 #define CB_ADDRESS_BROADCAST_MAX_SIZE 1000
00047 #define CB_INVENTORY_BROADCAST_MAX_SIZE 50000
00048 #define CB_GET_DATA_MAX_SIZE 50000
00049 #define CB_GET_BLOCKS_MAX_SIZE 16045
00050 #define CB_GET_HEADERS_MAX_SIZE 64045
00051 #define CB_BLOCK_HEADERS_MAX_SIZE 178009
00052 #define CB_ALERT_MAX_SIZE 2100 // Max size for payload is 2000. Extra 100 for signature though the signature will likely be less.
00053 #define CB_OUTPUT_VALUE_MINUS_ONE 0xFFFFFFFFFFFFFFFF // In twos complement it represents -1. Bitcoin uses twos compliment.
00054 #define CB_ONE_BITCOIN 100000000 // Each bitcoin has 100 million satoshis (individual units).
00055 #define CB_MAX_MONEY 21000000 * CB_ONE_BITCOIN // 21 million Bitcoins. 
00056 #define CB_SOCKET_CONNECTION_CLOSE -1
00057 #define CB_SOCKET_FAILURE -2
00058 #define CB_SEND_QUEUE_MAX_SIZE 10 // Sent no more than 10 messages at once to a peer.
00059 #define CB_BUCKET_NUM 255 // Maximum number of buckets
00060 #define CB_NODE_MAX_ADDRESSES_24_HOURS 100 // Maximum number of addresses accepted by a peer in 24 hours
00061 #define CB_24_HOURS 86400
00062 #define NOT ! // Better readability than !
00063 #define CB_MAX_RESPONSES_EXPECTED 3 // A pong, an inventory broadcast and an address broadcast.
00064 #define CB_TARGET_INTERVAL 1209600 // Two week interval
00065 #define CB_MAX_TARGET 0x1D00FFFF
00066 #define CB_LOCKTIME_THRESHOLD 500000000 // Below this value it is a blok number, else it is a time.
00067 #define CB_COINBASE_MATURITY 100 // Number of confirming blocks before a block reward can be spent.
00068 
00069 //  Enums
00070 
00071 typedef enum{
00072         CB_ERROR_MESSAGE_CHECKSUM_BAD_SIZE,
00073         CB_ERROR_MESSAGE_NO_SERIALISATION_IMPLEMENTATION,
00074         CB_ERROR_MESSAGE_NO_DESERIALISATION_IMPLEMENTATION,
00075         CB_ERROR_MESSAGE_DESERIALISATION_BAD_BYTES,
00076         CB_ERROR_MESSAGE_DESERIALISATION_NULL_BYTES,
00077         CB_ERROR_MESSAGE_SERIALISATION_BAD_BYTES,
00078         CB_ERROR_MESSAGE_SERIALISATION_NULL_BYTES,
00079         CB_ERROR_MESSAGE_SERIALISATION_BAD_DATA,
00080         CB_ERROR_SHA_256_HASH_BAD_BYTE_ARRAY_LENGTH,
00081         CB_ERROR_BASE58_DECODE_CHECK_TOO_SHORT,
00082         CB_ERROR_BASE58_DECODE_CHECK_INVALID,
00083         CB_ERROR_TRANSACTION_FEW_INPUTS,
00084         CB_ERROR_TRANSACTION_FEW_OUTPUTS,
00085         CB_ERROR_NETWORK_COMMUNICATOR_LOOP_FAIL,
00086         CB_ERROR_NETWORK_COMMUNICATOR_LOOP_CREATE_FAIL,
00087         CB_ERROR_NETWORK_COMMUNICATOR_CONNECT_FAILURE,
00088         CB_ERROR_OUT_OF_MEMORY,
00089         CB_ERROR_INIT_FAIL,
00090 }CBError;
00091 
00092 /*
00093  @brief The return values for CBScriptExecute. @see CBScript.h
00094  */
00095 typedef enum{
00096         CB_SCRIPT_VALID, 
00097         CB_SCRIPT_INVALID, 
00098         CB_SCRIPT_ERR 
00099 } CBScriptExecuteReturn;
00100 
00101 /*
00102  @brief The return values for CBTransactionGetInputHashForSignature. @see CBTransaction.h
00103  */
00104 typedef enum{
00105         CB_TX_HASH_OK, 
00106         CB_TX_HASH_BAD, 
00107         CB_TX_HASH_ERR 
00108 } CBGetHashReturn;
00109 
00110 typedef enum{
00111         CB_SOCKET_OK,
00112         CB_SOCKET_NO_SUPPORT,
00113         CB_SOCKET_BAD
00114 } CBSocketReturn;
00115 
00116 typedef enum{
00117         CB_CONNECT_OK,
00118         CB_CONNECT_NO_SUPPORT,
00119         CB_CONNECT_BAD,
00120         CB_CONNECT_FAIL
00121 } CBConnectReturn;
00122 
00123 typedef enum{
00124         CB_IP_INVALID = 0,
00125         CB_IP_IPv4 = 1,
00126         CB_IP_IPv6 = 2,
00127         CB_IP_LOCAL = 4,
00128         CB_IP_TOR = 8,
00129         CB_IP_I2P = 16,
00130         CB_IP_SITT = 32,
00131         CB_IP_RFC6052 = 64,
00132         CB_IP_6TO4 = 128,
00133         CB_IP_TEREDO = 256,
00134         CB_IP_HENET = 512
00135 } CBIPType;
00136 
00137 typedef enum{
00138         CB_TIMEOUT_CONNECT,
00139         CB_TIMEOUT_RESPONSE,
00140         CB_TIMEOUT_NO_DATA,
00141         CB_TIMEOUT_SEND,
00142         CB_TIMEOUT_RECEIVE
00143 } CBTimeOutType;
00144 
00145 /*
00146  @brief Used for CBNetworkCommunicator objects. These flags alter the behaviour of a CBNetworkCommunicator.
00147  */
00148 typedef enum{
00149         CB_NETWORK_COMMUNICATOR_AUTO_HANDSHAKE = 1, 
00150         CB_NETWORK_COMMUNICATOR_AUTO_DISCOVERY = 2, 
00151         CB_NETWORK_COMMUNICATOR_AUTO_PING = 4, 
00152 }CBNetworkCommunicatorFlags;
00153 
00154 /*
00155  @brief The action for a CBNetworkCommunicator to complete after the onMessageReceived handler returns.
00156  */
00157 typedef enum{
00158         CB_MESSAGE_ACTION_CONTINUE, 
00159         CB_MESSAGE_ACTION_DISCONNECT, 
00160         CB_MESSAGE_ACTION_STOP, 
00161         CB_MESSAGE_ACTION_RETURN 
00162 }CBOnMessageReceivedAction;
00163 
00164 /*
00165  @brief The type of a CBMessage.
00166  */
00167 typedef enum{
00168         CB_MESSAGE_TYPE_VERSION = 1, 
00169         CB_MESSAGE_TYPE_VERACK = 2, 
00170         CB_MESSAGE_TYPE_ADDR = 4, 
00171         CB_MESSAGE_TYPE_INV = 8, 
00172         CB_MESSAGE_TYPE_GETDATA = 16, 
00173         CB_MESSAGE_TYPE_GETBLOCKS = 32, 
00174         CB_MESSAGE_TYPE_GETHEADERS = 64, 
00175         CB_MESSAGE_TYPE_TX = 128, 
00176         CB_MESSAGE_TYPE_BLOCK = 256, 
00177         CB_MESSAGE_TYPE_HEADERS = 512, 
00178         CB_MESSAGE_TYPE_GETADDR = 1024, 
00179         CB_MESSAGE_TYPE_PING = 2048, 
00180         CB_MESSAGE_TYPE_PONG = 4096, 
00181         CB_MESSAGE_TYPE_ALERT = 8192, 
00182         CB_MESSAGE_TYPE_ALT = 16384, 
00183         CB_MESSAGE_TYPE_ADDRMAN = 32768, 
00184         CB_MESSAGE_TYPE_CHAINDESC = 65536, 
00185 }CBMessageType;
00186 
00187 typedef enum{
00188         CB_SERVICE_FULL_BLOCKS = 1, 
00189 }CBVersionServices;
00190 
00191 typedef enum{
00192         CB_INVENTORY_ITEM_ERROR = 0,
00193         CB_INVENTORY_ITEM_TRANSACTION = 1,
00194         CB_INVENTORY_ITEM_BLOCK = 2,
00195 }CBInventoryItemType;
00196 
00197 typedef enum{
00198         CB_SCRIPT_OP_0 = 0x00,
00199     CB_SCRIPT_OP_FALSE = CB_SCRIPT_OP_0,
00200     CB_SCRIPT_OP_PUSHDATA1 = 0x4c,
00201     CB_SCRIPT_OP_PUSHDATA2 = 0x4d,
00202     CB_SCRIPT_OP_PUSHDATA4 = 0x4e,
00203     CB_SCRIPT_OP_1NEGATE = 0x4f,
00204     CB_SCRIPT_OP_RESERVED = 0x50,
00205     CB_SCRIPT_OP_1 = 0x51,
00206     CB_SCRIPT_OP_TRUE = CB_SCRIPT_OP_1,
00207     CB_SCRIPT_OP_2 = 0x52,
00208     CB_SCRIPT_OP_3 = 0x53,
00209     CB_SCRIPT_OP_4 = 0x54,
00210     CB_SCRIPT_OP_5 = 0x55,
00211     CB_SCRIPT_OP_6 = 0x56,
00212     CB_SCRIPT_OP_7 = 0x57,
00213     CB_SCRIPT_OP_8 = 0x58,
00214     CB_SCRIPT_OP_9 = 0x59,
00215     CB_SCRIPT_OP_10 = 0x5a,
00216     CB_SCRIPT_OP_11 = 0x5b,
00217     CB_SCRIPT_OP_12 = 0x5c,
00218     CB_SCRIPT_OP_13 = 0x5d,
00219     CB_SCRIPT_OP_14 = 0x5e,
00220     CB_SCRIPT_OP_15 = 0x5f,
00221     CB_SCRIPT_OP_16 = 0x60,
00222     CB_SCRIPT_OP_NOP = 0x61,
00223     CB_SCRIPT_OP_VER = 0x62,
00224     CB_SCRIPT_OP_IF = 0x63,
00225     CB_SCRIPT_OP_NOTIF = 0x64,
00226     CB_SCRIPT_OP_VERIF = 0x65,
00227     CB_SCRIPT_OP_VERNOTIF = 0x66,
00228     CB_SCRIPT_OP_ELSE = 0x67,
00229     CB_SCRIPT_OP_ENDIF = 0x68,
00230     CB_SCRIPT_OP_VERIFY = 0x69,
00231     CB_SCRIPT_OP_RETURN = 0x6a,
00232     CB_SCRIPT_OP_TOALTSTACK = 0x6b,
00233     CB_SCRIPT_OP_FROMALTSTACK = 0x6c,
00234     CB_SCRIPT_OP_2DROP = 0x6d,
00235     CB_SCRIPT_OP_2DUP = 0x6e,
00236     CB_SCRIPT_OP_3DUP = 0x6f,
00237     CB_SCRIPT_OP_2OVER = 0x70,
00238     CB_SCRIPT_OP_2ROT = 0x71,
00239     CB_SCRIPT_OP_2SWAP = 0x72,
00240     CB_SCRIPT_OP_IFDUP = 0x73,
00241     CB_SCRIPT_OP_DEPTH = 0x74,
00242     CB_SCRIPT_OP_DROP = 0x75,
00243     CB_SCRIPT_OP_DUP = 0x76,
00244     CB_SCRIPT_OP_NIP = 0x77,
00245     CB_SCRIPT_OP_OVER = 0x78,
00246     CB_SCRIPT_OP_PICK = 0x79,
00247     CB_SCRIPT_OP_ROLL = 0x7a,
00248     CB_SCRIPT_OP_ROT = 0x7b,
00249     CB_SCRIPT_OP_SWAP = 0x7c,
00250     CB_SCRIPT_OP_TUCK = 0x7d,
00251     CB_SCRIPT_OP_CAT = 0x7e, // Disabled
00252     CB_SCRIPT_OP_SUBSTR = 0x7f, // Disabled
00253     CB_SCRIPT_OP_LEFT = 0x80, // Disabled
00254     CB_SCRIPT_OP_RIGHT = 0x81, // Disabled
00255     CB_SCRIPT_OP_SIZE = 0x82,
00256     CB_SCRIPT_OP_INVERT = 0x83, // Disabled
00257     CB_SCRIPT_OP_AND = 0x84, // Disabled
00258     CB_SCRIPT_OP_OR = 0x85, // Disabled
00259     CB_SCRIPT_OP_XOR = 0x86, // Disabled
00260     CB_SCRIPT_OP_EQUAL = 0x87,
00261     CB_SCRIPT_OP_EQUALVERIFY = 0x88,
00262     CB_SCRIPT_OP_RESERVED1 = 0x89,
00263     CB_SCRIPT_OP_RESERVED2 = 0x8a,
00264     CB_SCRIPT_OP_1ADD = 0x8b,
00265     CB_SCRIPT_OP_1SUB = 0x8c,
00266     CB_SCRIPT_OP_2MUL = 0x8d, // Disabled
00267     CB_SCRIPT_OP_2DIV = 0x8e, // Disabled
00268     CB_SCRIPT_OP_NEGATE = 0x8f,
00269     CB_SCRIPT_OP_ABS = 0x90,
00270     CB_SCRIPT_OP_NOT = 0x91,
00271     CB_SCRIPT_OP_0NOTEQUAL = 0x92,
00272     CB_SCRIPT_OP_ADD = 0x93,
00273     CB_SCRIPT_OP_SUB = 0x94,
00274     CB_SCRIPT_OP_MUL = 0x95, // Disabled
00275     CB_SCRIPT_OP_DIV = 0x96, // Disabled
00276     CB_SCRIPT_OP_MOD = 0x97, // Disabled
00277     CB_SCRIPT_OP_LSHIFT = 0x98, // Disabled
00278     CB_SCRIPT_OP_RSHIFT = 0x99, // Disabled
00279     CB_SCRIPT_OP_BOOLAND = 0x9a,
00280     CB_SCRIPT_OP_BOOLOR = 0x9b,
00281     CB_SCRIPT_OP_NUMEQUAL = 0x9c,
00282     CB_SCRIPT_OP_NUMEQUALVERIFY = 0x9d,
00283     CB_SCRIPT_OP_NUMNOTEQUAL = 0x9e,
00284     CB_SCRIPT_OP_LESSTHAN = 0x9f,
00285     CB_SCRIPT_OP_GREATERTHAN = 0xa0,
00286     CB_SCRIPT_OP_LESSTHANOREQUAL = 0xa1,
00287     CB_SCRIPT_OP_GREATERTHANOREQUAL = 0xa2,
00288     CB_SCRIPT_OP_MIN = 0xa3,
00289     CB_SCRIPT_OP_MAX = 0xa4,
00290     CB_SCRIPT_OP_WITHIN = 0xa5,
00291     CB_SCRIPT_OP_RIPEMD160 = 0xa6,
00292     CB_SCRIPT_OP_SHA1 = 0xa7,
00293     CB_SCRIPT_OP_SHA256 = 0xa8,
00294     CB_SCRIPT_OP_HASH160 = 0xa9,
00295     CB_SCRIPT_OP_HASH256 = 0xaa,
00296     CB_SCRIPT_OP_CODESEPARATOR = 0xab,
00297     CB_SCRIPT_OP_CHECKSIG = 0xac,
00298     CB_SCRIPT_OP_CHECKSIGVERIFY = 0xad,
00299     CB_SCRIPT_OP_CHECKMULTISIG = 0xae,
00300     CB_SCRIPT_OP_CHECKMULTISIGVERIFY = 0xaf,
00301     CB_SCRIPT_OP_NOP1 = 0xb0,
00302     CB_SCRIPT_OP_NOP2 = 0xb1,
00303     CB_SCRIPT_OP_NOP3 = 0xb2,
00304     CB_SCRIPT_OP_NOP4 = 0xb3,
00305     CB_SCRIPT_OP_NOP5 = 0xb4,
00306     CB_SCRIPT_OP_NOP6 = 0xb5,
00307     CB_SCRIPT_OP_NOP7 = 0xb6,
00308     CB_SCRIPT_OP_NOP8 = 0xb7,
00309     CB_SCRIPT_OP_NOP9 = 0xb8,
00310     CB_SCRIPT_OP_NOP10 = 0xb9,
00311     CB_SCRIPT_OP_SMALLINTEGER = 0xfa,
00312     CB_SCRIPT_OP_PUBKEYS = 0xfb,
00313     CB_SCRIPT_OP_PUBKEYHASH = 0xfd,
00314     CB_SCRIPT_OP_PUBKEY = 0xfe,
00315     CB_SCRIPT_OP_INVALIDOPCODE = 0xff,
00316 }CBScriptOp;
00317 
00318 typedef enum{
00319         CB_SIGHASH_ALL = 0x00000001,
00320         CB_SIGHASH_NONE = 0x00000002,
00321         CB_SIGHASH_SINGLE = 0x00000003,
00322         CB_SIGHASH_ANYONECANPAY = 0x00000080,
00323 }CBSignType;
00324 
00325 typedef enum{
00326         CB_COMPARE_MORE_THAN = 1,
00327         CB_COMPARE_EQUAL = 0,
00328         CB_COMPARE_LESS_THAN = -1,
00329 }CBCompare;
00330 
00331 #endif