-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34b38bb
commit 28d6e90
Showing
23 changed files
with
1,985 additions
and
1,413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright (c) 2009-2010 Satoshi Nakamoto | ||
// Copyright (c) 2009-2013 The Bitcoin developers | ||
// Distributed under the MIT/X11 software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include "core.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
// Copyright (c) 2009-2010 Satoshi Nakamoto | ||
// Copyright (c) 2009-2013 The Bitcoin developers | ||
// Distributed under the MIT/X11 software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
#ifndef BITCOIN_CORE_H | ||
#define BITCOIN_CORE_H | ||
|
||
#include "uint256.h" | ||
#include "serialize.h" | ||
#include "util.h" | ||
#include "script.h" | ||
|
||
#include <stdio.h> | ||
|
||
class CScript; | ||
class CTransaction; | ||
|
||
/** An outpoint - a combination of a transaction hash and an index n into its vout */ | ||
class COutPoint | ||
{ | ||
public: | ||
uint256 hash; | ||
unsigned int n; | ||
|
||
COutPoint() { SetNull(); } | ||
COutPoint(uint256 hashIn, unsigned int nIn) { hash = hashIn; n = nIn; } | ||
IMPLEMENT_SERIALIZE( READWRITE(FLATDATA(*this)); ) | ||
void SetNull() { hash = 0; n = (unsigned int) -1; } | ||
bool IsNull() const { return (hash == 0 && n == (unsigned int) -1); } | ||
|
||
friend bool operator<(const COutPoint& a, const COutPoint& b) | ||
{ | ||
return (a.hash < b.hash || (a.hash == b.hash && a.n < b.n)); | ||
} | ||
|
||
friend bool operator==(const COutPoint& a, const COutPoint& b) | ||
{ | ||
return (a.hash == b.hash && a.n == b.n); | ||
} | ||
|
||
friend bool operator!=(const COutPoint& a, const COutPoint& b) | ||
{ | ||
return !(a == b); | ||
} | ||
|
||
std::string ToString() const | ||
{ | ||
return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10).c_str(), n); | ||
} | ||
}; | ||
|
||
/** An inpoint - a combination of a transaction and an index n into its vin */ | ||
class CInPoint | ||
{ | ||
public: | ||
CTransaction* ptx; | ||
unsigned int n; | ||
|
||
CInPoint() { SetNull(); } | ||
CInPoint(CTransaction* ptxIn, unsigned int nIn) { ptx = ptxIn; n = nIn; } | ||
void SetNull() { ptx = NULL; n = (unsigned int) -1; } | ||
bool IsNull() const { return (ptx == NULL && n == (unsigned int) -1); } | ||
}; | ||
|
||
/** An input of a transaction. It contains the location of the previous | ||
* transaction's output that it claims and a signature that matches the | ||
* output's public key. | ||
*/ | ||
class CTxIn | ||
{ | ||
public: | ||
COutPoint prevout; | ||
CScript scriptSig; | ||
CScript prevPubKey; | ||
unsigned int nSequence; | ||
|
||
CTxIn() | ||
{ | ||
nSequence = std::numeric_limits<unsigned int>::max(); | ||
} | ||
|
||
explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=std::numeric_limits<unsigned int>::max()) | ||
{ | ||
prevout = prevoutIn; | ||
scriptSig = scriptSigIn; | ||
nSequence = nSequenceIn; | ||
} | ||
|
||
explicit CTxIn(uint256 hashPrevTx, unsigned int nOut, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=std::numeric_limits<unsigned int>::max()) | ||
{ | ||
prevout = COutPoint(hashPrevTx, nOut); | ||
scriptSig = scriptSigIn; | ||
nSequence = nSequenceIn; | ||
} | ||
|
||
IMPLEMENT_SERIALIZE | ||
( | ||
READWRITE(prevout); | ||
READWRITE(scriptSig); | ||
READWRITE(nSequence); | ||
) | ||
|
||
bool IsFinal() const | ||
{ | ||
return (nSequence == std::numeric_limits<unsigned int>::max()); | ||
} | ||
|
||
friend bool operator==(const CTxIn& a, const CTxIn& b) | ||
{ | ||
return (a.prevout == b.prevout && | ||
a.scriptSig == b.scriptSig && | ||
a.nSequence == b.nSequence); | ||
} | ||
|
||
friend bool operator!=(const CTxIn& a, const CTxIn& b) | ||
{ | ||
return !(a == b); | ||
} | ||
|
||
std::string ToString() const | ||
{ | ||
std::string str; | ||
str += "CTxIn("; | ||
str += prevout.ToString(); | ||
if (prevout.IsNull()) | ||
str += strprintf(", coinbase %s", HexStr(scriptSig).c_str()); | ||
else | ||
str += strprintf(", scriptSig=%s", scriptSig.ToString().substr(0,24).c_str()); | ||
if (nSequence != std::numeric_limits<unsigned int>::max()) | ||
str += strprintf(", nSequence=%u", nSequence); | ||
str += ")"; | ||
return str; | ||
} | ||
}; | ||
|
||
|
||
|
||
|
||
/** An output of a transaction. It contains the public key that the next input | ||
* must be able to sign with to claim it. | ||
*/ | ||
class CTxOut | ||
{ | ||
public: | ||
int64_t nValue; | ||
CScript scriptPubKey; | ||
|
||
CTxOut() | ||
{ | ||
SetNull(); | ||
} | ||
|
||
CTxOut(int64_t nValueIn, CScript scriptPubKeyIn) | ||
{ | ||
nValue = nValueIn; | ||
scriptPubKey = scriptPubKeyIn; | ||
} | ||
|
||
IMPLEMENT_SERIALIZE | ||
( | ||
READWRITE(nValue); | ||
READWRITE(scriptPubKey); | ||
) | ||
|
||
void SetNull() | ||
{ | ||
nValue = -1; | ||
scriptPubKey.clear(); | ||
} | ||
|
||
bool IsNull() const | ||
{ | ||
return (nValue == -1); | ||
} | ||
|
||
void SetEmpty() | ||
{ | ||
nValue = 0; | ||
scriptPubKey.clear(); | ||
} | ||
|
||
bool IsEmpty() const | ||
{ | ||
return (nValue == 0 && scriptPubKey.empty()); | ||
} | ||
|
||
uint256 GetHash() const | ||
{ | ||
return SerializeHash(*this); | ||
} | ||
|
||
friend bool operator==(const CTxOut& a, const CTxOut& b) | ||
{ | ||
return (a.nValue == b.nValue && | ||
a.scriptPubKey == b.scriptPubKey); | ||
} | ||
|
||
friend bool operator!=(const CTxOut& a, const CTxOut& b) | ||
{ | ||
return !(a == b); | ||
} | ||
|
||
std::string ToString() const | ||
{ | ||
if (IsEmpty()) return "CTxOut(empty)"; | ||
return strprintf("CTxOut(nValue=%s, scriptPubKey=%s)", FormatMoney(nValue).c_str(), scriptPubKey.ToString().c_str()); | ||
} | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.