Anoncoin  0.9.4
P2P Digital Currency
auxpow.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
4 #ifndef ANONCOIN_AUXPOW_H
5 #define ANONCOIN_AUXPOW_H
6 
7 #include "main.h"
8 
9 class CAuxPow : public CMerkleTx
10 {
11 public:
12  CAuxPow(const CTransaction& txIn) : CMerkleTx(txIn)
13  {
14  }
15 
17  {
18  }
19 
20  // Merkle branch with root vchAux
21  // root must be present inside the coinbase
22  std::vector<uint256> vChainMerkleBranch;
23  // Index of chain in chains merkle tree
26 
28  (
29  nSerSize += SerReadWrite(s, *(CMerkleTx*)this, nType, nVersion, ser_action);
30  nVersion = this->nVersion;
31  READWRITE(vChainMerkleBranch);
32  READWRITE(nChainIndex);
33 
34  // Always serialize the saved parent block as header so that the size of CAuxPow
35  // is consistent.
36  nSerSize += SerReadWrite(s, parentBlock, nType | SER_BLOCKHEADERONLY, nVersion, ser_action);
37  )
38 
39  bool Check(uint256 hashAuxBlock, int nChainID);
40 
42  {
43  return parentBlock.GetHash();
44  }
45 };
46 
47 template <typename Stream>
48 int ReadWriteAuxPow(Stream& s, const boost::shared_ptr<CAuxPow>& auxpow, int nType, int nVersion, CSerActionGetSerializeSize ser_action)
49 {
50  if (nVersion & BLOCK_VERSION_AUXPOW)
51  {
52  return ::GetSerializeSize(*auxpow, nType, nVersion);
53  }
54  return 0;
55 }
56 
57 template <typename Stream>
58 int ReadWriteAuxPow(Stream& s, const boost::shared_ptr<CAuxPow>& auxpow, int nType, int nVersion, CSerActionSerialize ser_action)
59 {
60  if (nVersion & BLOCK_VERSION_AUXPOW)
61  {
62  return SerReadWrite(s, *auxpow, nType, nVersion, ser_action);
63  }
64  return 0;
65 }
66 
67 template <typename Stream>
68 int ReadWriteAuxPow(Stream& s, boost::shared_ptr<CAuxPow>& auxpow, int nType, int nVersion, CSerActionUnserialize ser_action)
69 {
70  if (nVersion & BLOCK_VERSION_AUXPOW)
71  {
72  auxpow.reset(new CAuxPow());
73  return SerReadWrite(s, *auxpow, nType, nVersion, ser_action);
74  }
75  else
76  {
77  auxpow.reset();
78  return 0;
79  }
80 }
81 
82 extern void RemoveMergedMiningHeader(std::vector<unsigned char>& vchAux);
83 extern CScript MakeCoinbaseWithAux(unsigned int nBits, unsigned int nExtraNonce, std::vector<unsigned char>& vchAux);
84 #endif
std::vector< uint256 > vChainMerkleBranch
Definition: auxpow.h:22
int nVersion
Definition: core.h:185
unsigned int SerReadWrite(Stream &s, const T &obj, int nType, int nVersion, CSerActionGetSerializeSize ser_action)
Definition: serialize.h:806
#define READWRITE(obj)
Definition: serialize.h:101
Definition: core.h:394
int nChainIndex
Definition: auxpow.h:24
CAuxPow(const CTransaction &txIn)
Definition: auxpow.h:12
int nChainID
Definition: auxpow.h:39
uint256 GetParentBlockHash()
Definition: auxpow.h:41
unsigned int GetSerializeSize(char a, int, int=0)
Definition: serialize.h:114
CBlock parentBlock
Definition: auxpow.h:25
int ReadWriteAuxPow(Stream &s, const boost::shared_ptr< CAuxPow > &auxpow, int nType, int nVersion, CSerActionGetSerializeSize ser_action)
Definition: auxpow.h:48
void RemoveMergedMiningHeader(std::vector< unsigned char > &vchAux)
Definition: auxpow.cpp:14
CAuxPow()
Definition: auxpow.h:16
256-bit unsigned integer
Definition: uint256.h:532
CScript MakeCoinbaseWithAux(unsigned int nBits, unsigned int nExtraNonce, std::vector< unsigned char > &vchAux)
Definition: auxpow.cpp:105
uint256 GetHash() const
Definition: core.cpp:216
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:413
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: core.h:179
IMPLEMENT_SERIALIZE(nSerSize+=SerReadWrite(s,*(CMerkleTx *) this, nType, nVersion, ser_action);nVersion=this->nVersion;READWRITE(vChainMerkleBranch);READWRITE(nChainIndex);nSerSize+=SerReadWrite(s, parentBlock, nType|SER_BLOCKHEADERONLY, nVersion, ser_action);) bool Check(uint256 hashAuxBlock
Definition: auxpow.h:9
A transaction with a merkle branch linking it to the block chain.
Definition: main.h:436