annotate src/protocol.h @ 3644:e62eeca19443 draft

Add CTxUndo: transaction undo information The CTxUndo class encapsulates data necessary to undo the effects of a transaction on the txout set, namely the previous outputs consumed by it (script + amount), and potentially transaction meta-data when it is spent entirely.
author Pieter Wuille <pieter.wuille@gmail.com>
date Mon, 18 Jun 2012 16:55:29 +0200
parents 50bee06c56c1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
876
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
1818
20667468f95b Update all copyrights to 2012
Gavin Andresen <gavinandresen@gmail.com>
parents: 1762
diff changeset
2 // Copyright (c) 2009-2012 The Bitcoin developers
876
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
3 // Distributed under the MIT/X11 software license, see the accompanying
2607
98dbb2aa4f5a Update License in File Headers
Fordy <fanquake@gmail.com>
parents: 2276
diff changeset
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
876
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
5
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
6 #ifndef __cplusplus
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
7 # error This header can only be compiled as C++.
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
8 #endif
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
9
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
10 #ifndef __INCLUDED_PROTOCOL_H__
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
11 #define __INCLUDED_PROTOCOL_H__
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
12
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
13 #include "serialize.h"
1731
4a2d4c136998 Network stack refactor
Pieter Wuille <pieter.wuille@gmail.com>
parents: 1616
diff changeset
14 #include "netbase.h"
876
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
15 #include <string>
878
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
16 #include "uint256.h"
876
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
17
877
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
18 extern bool fTestNet;
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
19 static inline unsigned short GetDefaultPort(const bool testnet = fTestNet)
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
20 {
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
21 return testnet ? 18333 : 8333;
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
22 }
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
23
876
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
24
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
25 extern unsigned char pchMessageStart[4];
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
26
2096
ee92c87e9cb6 Begin doxygen-compatible comments
Pieter Wuille <pieter.wuille@gmail.com>
parents: 1911
diff changeset
27 /** Message header.
ee92c87e9cb6 Begin doxygen-compatible comments
Pieter Wuille <pieter.wuille@gmail.com>
parents: 1911
diff changeset
28 * (4) message start.
ee92c87e9cb6 Begin doxygen-compatible comments
Pieter Wuille <pieter.wuille@gmail.com>
parents: 1911
diff changeset
29 * (12) command.
ee92c87e9cb6 Begin doxygen-compatible comments
Pieter Wuille <pieter.wuille@gmail.com>
parents: 1911
diff changeset
30 * (4) size.
ee92c87e9cb6 Begin doxygen-compatible comments
Pieter Wuille <pieter.wuille@gmail.com>
parents: 1911
diff changeset
31 * (4) checksum.
ee92c87e9cb6 Begin doxygen-compatible comments
Pieter Wuille <pieter.wuille@gmail.com>
parents: 1911
diff changeset
32 */
876
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
33 class CMessageHeader
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
34 {
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
35 public:
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
36 CMessageHeader();
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
37 CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
38
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
39 std::string GetCommand() const;
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
40 bool IsValid() const;
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
41
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
42 IMPLEMENT_SERIALIZE
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
43 (
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
44 READWRITE(FLATDATA(pchMessageStart));
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
45 READWRITE(FLATDATA(pchCommand));
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
46 READWRITE(nMessageSize);
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
47 READWRITE(nChecksum);
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
48 )
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
49
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
50 // TODO: make private (improves encapsulation)
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
51 public:
3147
50bee06c56c1 Fix remaining warnings.
Matt Corallo <matt@bluematt.me>
parents: 2607
diff changeset
52 enum {
50bee06c56c1 Fix remaining warnings.
Matt Corallo <matt@bluematt.me>
parents: 2607
diff changeset
53 MESSAGE_START_SIZE=sizeof(::pchMessageStart),
50bee06c56c1 Fix remaining warnings.
Matt Corallo <matt@bluematt.me>
parents: 2607
diff changeset
54 COMMAND_SIZE=12,
50bee06c56c1 Fix remaining warnings.
Matt Corallo <matt@bluematt.me>
parents: 2607
diff changeset
55 MESSAGE_SIZE_SIZE=sizeof(int),
50bee06c56c1 Fix remaining warnings.
Matt Corallo <matt@bluematt.me>
parents: 2607
diff changeset
56 CHECKSUM_SIZE=sizeof(int),
50bee06c56c1 Fix remaining warnings.
Matt Corallo <matt@bluematt.me>
parents: 2607
diff changeset
57
50bee06c56c1 Fix remaining warnings.
Matt Corallo <matt@bluematt.me>
parents: 2607
diff changeset
58 MESSAGE_SIZE_OFFSET=MESSAGE_START_SIZE+COMMAND_SIZE,
50bee06c56c1 Fix remaining warnings.
Matt Corallo <matt@bluematt.me>
parents: 2607
diff changeset
59 CHECKSUM_OFFSET=MESSAGE_SIZE_OFFSET+MESSAGE_SIZE_SIZE
50bee06c56c1 Fix remaining warnings.
Matt Corallo <matt@bluematt.me>
parents: 2607
diff changeset
60 };
50bee06c56c1 Fix remaining warnings.
Matt Corallo <matt@bluematt.me>
parents: 2607
diff changeset
61 char pchMessageStart[MESSAGE_START_SIZE];
876
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
62 char pchCommand[COMMAND_SIZE];
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
63 unsigned int nMessageSize;
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
64 unsigned int nChecksum;
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
65 };
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
66
2096
ee92c87e9cb6 Begin doxygen-compatible comments
Pieter Wuille <pieter.wuille@gmail.com>
parents: 1911
diff changeset
67 /** nServices flags */
877
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
68 enum
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
69 {
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
70 NODE_NETWORK = (1 << 0),
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
71 };
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
72
2096
ee92c87e9cb6 Begin doxygen-compatible comments
Pieter Wuille <pieter.wuille@gmail.com>
parents: 1911
diff changeset
73 /** A CService with information about it as peer */
1731
4a2d4c136998 Network stack refactor
Pieter Wuille <pieter.wuille@gmail.com>
parents: 1616
diff changeset
74 class CAddress : public CService
877
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
75 {
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
76 public:
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
77 CAddress();
1762
3ae3a30451cb Fix handling of default ports
Pieter Wuille <sipa@ulyssis.org>
parents: 1731
diff changeset
78 explicit CAddress(CService ipIn, uint64 nServicesIn=NODE_NETWORK);
877
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
79
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
80 void Init();
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
81
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
82 IMPLEMENT_SERIALIZE
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
83 (
1731
4a2d4c136998 Network stack refactor
Pieter Wuille <pieter.wuille@gmail.com>
parents: 1616
diff changeset
84 CAddress* pthis = const_cast<CAddress*>(this);
4a2d4c136998 Network stack refactor
Pieter Wuille <pieter.wuille@gmail.com>
parents: 1616
diff changeset
85 CService* pip = (CService*)pthis;
877
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
86 if (fRead)
1731
4a2d4c136998 Network stack refactor
Pieter Wuille <pieter.wuille@gmail.com>
parents: 1616
diff changeset
87 pthis->Init();
877
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
88 if (nType & SER_DISK)
2223
91b5242159c1 Replace several network protocol version numbers with named constants
Jeff Garzik <jeff@garzik.org>
parents: 2096
diff changeset
89 READWRITE(nVersion);
91b5242159c1 Replace several network protocol version numbers with named constants
Jeff Garzik <jeff@garzik.org>
parents: 2096
diff changeset
90 if ((nType & SER_DISK) ||
91b5242159c1 Replace several network protocol version numbers with named constants
Jeff Garzik <jeff@garzik.org>
parents: 2096
diff changeset
91 (nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH)))
91b5242159c1 Replace several network protocol version numbers with named constants
Jeff Garzik <jeff@garzik.org>
parents: 2096
diff changeset
92 READWRITE(nTime);
877
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
93 READWRITE(nServices);
1731
4a2d4c136998 Network stack refactor
Pieter Wuille <pieter.wuille@gmail.com>
parents: 1616
diff changeset
94 READWRITE(*pip);
877
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
95 )
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
96
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
97 void print() const;
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
98
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
99 // TODO: make private (improves encapsulation)
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
100 public:
1616
997b708d15b8 Revert "Use standard C99 (and Qt) types for 64-bit integers"
Wladimir J. van der Laan <laanwj@gmail.com>
parents: 1615
diff changeset
101 uint64 nServices;
877
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
102
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
103 // disk and network only
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
104 unsigned int nTime;
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
105
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
106 // memory only
1911
a9190d020909 CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents: 1895
diff changeset
107 int64 nLastTry;
877
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
108 };
aef18cc34b65 Move CAddress to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 876
diff changeset
109
2096
ee92c87e9cb6 Begin doxygen-compatible comments
Pieter Wuille <pieter.wuille@gmail.com>
parents: 1911
diff changeset
110 /** inv message data */
878
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
111 class CInv
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
112 {
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
113 public:
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
114 CInv();
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
115 CInv(int typeIn, const uint256& hashIn);
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
116 CInv(const std::string& strType, const uint256& hashIn);
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
117
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
118 IMPLEMENT_SERIALIZE
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
119 (
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
120 READWRITE(type);
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
121 READWRITE(hash);
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
122 )
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
123
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
124 friend bool operator<(const CInv& a, const CInv& b);
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
125
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
126 bool IsKnownType() const;
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
127 const char* GetCommand() const;
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
128 std::string ToString() const;
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
129 void print() const;
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
130
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
131 // TODO: make private (improves encapsulation)
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
132 public:
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
133 int type;
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
134 uint256 hash;
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
135 };
c0f3d2bb26d9 Move CInv to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents: 877
diff changeset
136
876
b5abe85df1e7 Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff changeset
137 #endif // __INCLUDED_PROTOCOL_H__