if (!BN_div(&dv, &rem, &bn, &bn58, pctx))
throw bignum_error("EncodeBase58 : BN_div failed");
bn = dv;
- unsigned int c = rem.getulong();
+ unsigned int c = rem.getuint32();
str += pszBase58[c];
}
return false;
break;
}
- bnChar.setulong(p1 - pszBase58);
+ bnChar.setuint32(p1 - pszBase58);
if (!BN_mul(&bn, &bn, &bn58, pctx))
throw bignum_error("DecodeBase58 : BN_mul failed");
bn += bnChar;
BN_clear_free(this);
}
- //CBigNum(char n) is not portable. Use 'signed char' or 'unsigned char'.
- CBigNum(signed char n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
- CBigNum(short n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
- CBigNum(int n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
- CBigNum(long n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
- CBigNum(unsigned char n) { BN_init(this); setulong(n); }
- CBigNum(unsigned short n) { BN_init(this); setulong(n); }
- CBigNum(unsigned int n) { BN_init(this); setulong(n); }
- CBigNum(unsigned long n) { BN_init(this); setulong(n); }
- explicit CBigNum(uint256 n) { BN_init(this); setuint256(n); }
+ CBigNum(int8_t n) { BN_init(this); if (n >= 0) setuint32(n); else setint64(n); }
+ CBigNum(int16_t n) { BN_init(this); if (n >= 0) setuint32(n); else setint64(n); }
+ CBigNum(int32_t n) { BN_init(this); if (n >= 0) setuint32(n); else setint64(n); }
+ CBigNum(int64_t n) { BN_init(this); if (n >= 0) setuint64(n); else setint64(n); }
+
+ CBigNum(uint8_t n) { BN_init(this); setuint32(n); }
+ CBigNum(uint16_t n) { BN_init(this); setuint32(n); }
+ CBigNum(uint32_t n) { BN_init(this); setuint32(n); }
+ CBigNum(uint64_t n) { BN_init(this); setuint64(n); }
+ explicit CBigNum(uint256 n) { BN_init(this); setuint256(n); }
explicit CBigNum(const std::vector<unsigned char>& vch)
{
BN_init(this);
}
- void setulong(unsigned long n)
+ void setuint32(uint32_t n)
{
if (!BN_set_word(this, n))
- throw bignum_error("CBigNum conversion from unsigned long : BN_set_word failed");
- }
-
- unsigned long getulong() const
- {
- return BN_get_word(this);
+ throw bignum_error("CBigNum conversion from uint32_t : BN_set_word failed");
}
- unsigned int getuint() const
+ uint32_t getuint32() const
{
return BN_get_word(this);
}
- int getint() const
+ int32_t getint32() const
{
- unsigned long n = BN_get_word(this);
+ uint64_t n = BN_get_word(this);
if (!BN_is_negative(this))
- return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : n);
+ return (n > (uint64_t)std::numeric_limits<int32_t>::max() ? std::numeric_limits<int32_t>::max() : n);
else
- return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::min() : -(int)n);
+ return (n > (uint64_t)std::numeric_limits<int32_t>::max() ? std::numeric_limits<int32_t>::min() : -(int32_t)n);
}
void setint64(int64_t sn)
}
*p++ = c;
}
- unsigned int nSize = p - (pch + 4);
+ uint32_t nSize = p - (pch + 4);
pch[0] = (nSize >> 24) & 0xff;
pch[1] = (nSize >> 16) & 0xff;
pch[2] = (nSize >> 8) & 0xff;
}
*p++ = c;
}
- unsigned int nSize = p - (pch + 4);
+ uint32_t nSize = p - (pch + 4);
pch[0] = (nSize >> 24) & 0xff;
pch[1] = (nSize >> 16) & 0xff;
pch[2] = (nSize >> 8) & 0xff;
}
*p++ = c;
}
- unsigned int nSize = p - (pch + 4);
+ uint32_t nSize = p - (pch + 4);
pch[0] = (nSize >> 24) & 0xff;
pch[1] = (nSize >> 16) & 0xff;
pch[2] = (nSize >> 8) & 0xff;
}
*p++ = c;
}
- unsigned int nSize = p - (pch + 4);
+ uint32_t nSize = p - (pch + 4);
pch[0] = (nSize >> 24) & 0xff;
pch[1] = (nSize >> 16) & 0xff;
pch[2] = (nSize >> 8) & 0xff;
void setvch(const std::vector<unsigned char>& vch)
{
std::vector<unsigned char> vch2(vch.size() + 4);
- unsigned int nSize = vch.size();
+ uint32_t nSize = vch.size();
// BIGNUM's byte stream format expects 4 bytes of
// big endian size data info at the front
vch2[0] = (nSize >> 24) & 0xff;
return vch;
}
- CBigNum& SetCompact(unsigned int nCompact)
+ CBigNum& SetCompact(uint32_t nCompact)
{
- unsigned int nSize = nCompact >> 24;
+ uint32_t nSize = nCompact >> 24;
std::vector<unsigned char> vch(4 + nSize);
vch[3] = nSize;
if (nSize >= 1) vch[4] = (nCompact >> 16) & 0xff;
return *this;
}
- unsigned int GetCompact() const
+ uint32_t GetCompact() const
{
- unsigned int nSize = BN_bn2mpi(this, NULL);
+ uint32_t nSize = BN_bn2mpi(this, NULL);
std::vector<unsigned char> vch(nSize);
nSize -= 4;
BN_bn2mpi(this, &vch[0]);
- unsigned int nCompact = nSize << 24;
+ uint32_t nCompact = nSize << 24;
if (nSize >= 1) nCompact |= (vch[4] << 16);
if (nSize >= 2) nCompact |= (vch[5] << 8);
if (nSize >= 3) nCompact |= (vch[6] << 0);
if (!BN_div(&dv, &rem, &bn, &bnBase, pctx))
throw bignum_error("CBigNum::ToString() : BN_div failed");
bn = dv;
- unsigned int c = rem.getulong();
+ unsigned int c = rem.getuint32();
str += "0123456789abcdef"[c];
}
if (BN_is_negative(this))
// quantities so as to generate blocks faster, degrading the system back into
// a proof-of-work situation.
//
-bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned int nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, unsigned int nTimeTx, uint256& hashProofOfStake, uint256& targetProofOfStake, bool fPrintProofOfStake)
+bool CheckStakeKernelHash(uint32_t nBits, const CBlock& blockFrom, uint32_t nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, uint32_t nTimeTx, uint256& hashProofOfStake, uint256& targetProofOfStake, bool fPrintProofOfStake)
{
if (nTimeTx < txPrev.nTime) // Transaction timestamp violation
return error("CheckStakeKernelHash() : nTime violation");
- unsigned int nTimeBlockFrom = blockFrom.GetBlockTime();
+ uint32_t nTimeBlockFrom = blockFrom.GetBlockTime();
if (nTimeBlockFrom + nStakeMinAge > nTimeTx) // Min age requirement
return error("CheckStakeKernelHash() : min age violation");
}
// Scan given coins set for kernel solution
-bool ScanForStakeKernelHash(MetaMap &mapMeta, KernelSearchSettings &settings, CoinsSet::value_type &kernelcoin, unsigned int &nTimeTx, unsigned int &nBlockTime, uint64_t &nKernelsTried, uint64_t &nCoinDaysTried)
+bool ScanForStakeKernelHash(MetaMap &mapMeta, KernelSearchSettings &settings, CoinsSet::value_type &kernelcoin, uint32_t &nTimeTx, uint32_t &nBlockTime, uint64_t &nKernelsTried, uint64_t &nCoinDaysTried)
{
uint256 hashProofOfStake = 0;
continue;
// Transaction offset inside block
- unsigned int nTxOffset = txindex.pos.nTxPos - txindex.pos.nBlockPos;
+ uint32_t nTxOffset = txindex.pos.nTxPos - txindex.pos.nBlockPos;
// Current timestamp scanning interval
unsigned int nCurrentSearchInterval = min((int64_t)settings.nSearchInterval, (int64_t)nMaxStakeSearchInterval);
}
// Get stake modifier checksum
-unsigned int GetStakeModifierChecksum(const CBlockIndex* pindex)
+uint32_t GetStakeModifierChecksum(const CBlockIndex* pindex)
{
assert (pindex->pprev || pindex->GetBlockHash() == (!fTestNet ? hashGenesisBlock : hashGenesisBlockTestNet));
// Hash previous checksum with flags, hashProofOfStake and nStakeModifier
}
// Check stake modifier hard checkpoints
-bool CheckStakeModifierCheckpoints(int nHeight, unsigned int nStakeModifierChecksum)
+bool CheckStakeModifierCheckpoints(int nHeight, uint32_t nStakeModifierChecksum)
{
MapModifierCheckpoints& checkpoints = (fTestNet ? mapStakeModifierCheckpointsTestNet : mapStakeModifierCheckpoints);
// Check whether stake kernel meets hash target
// Sets hashProofOfStake on success return
-bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned int nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, unsigned int nTimeTx, uint256& hashProofOfStake, uint256& targetProofOfStake, bool fPrintProofOfStake=false);
+bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, uint32_t nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, uint32_t nTimeTx, uint256& hashProofOfStake, uint256& targetProofOfStake, bool fPrintProofOfStake=false);
// Coins scanning options
typedef struct KernelSearchSettings {
- unsigned int nBits; // Packed difficulty
- unsigned int nTime; // Basic time
- unsigned int nOffset; // Offset inside CoinsSet (isn't used yet)
- unsigned int nLimit; // Coins to scan (isn't used yet)
- unsigned int nSearchInterval; // Number of seconds allowed to go into the past
+ uint32_t nBits; // Packed difficulty
+ uint32_t nTime; // Basic time
+ uint32_t nOffset; // Offset inside CoinsSet (isn't used yet)
+ uint32_t nLimit; // Coins to scan (isn't used yet)
+ uint32_t nSearchInterval; // Number of seconds allowed to go into the past
} KernelSearchSettings;
typedef std::set<std::pair<const CWalletTx*,unsigned int> > CoinsSet;
typedef std::map<std::pair<uint256, unsigned int>, std::pair<std::pair<CTxIndex, std::pair<const CWalletTx*,unsigned int> >, std::pair<CBlock, uint64_t> > > MetaMap;
// Scan given coins set for kernel solution
-bool ScanForStakeKernelHash(MetaMap &mapMeta, KernelSearchSettings &settings, CoinsSet::value_type &kernelcoin, unsigned int &nTimeTx, unsigned int &nBlockTime, uint64_t &nKernelsTried, uint64_t &nCoinDaysTried);
+bool ScanForStakeKernelHash(MetaMap &mapMeta, KernelSearchSettings &settings, CoinsSet::value_type &kernelcoin, uint32_t &nTimeTx, uint32_t &nBlockTime, uint64_t &nKernelsTried, uint64_t &nCoinDaysTried);
// Check kernel hash target and coinstake signature
// Sets hashProofOfStake on success return
bool CheckProofOfStake(const CTransaction& tx, unsigned int nBits, uint256& hashProofOfStake, uint256& targetProofOfStake);
// Get stake modifier checksum
-unsigned int GetStakeModifierChecksum(const CBlockIndex* pindex);
+uint32_t GetStakeModifierChecksum(const CBlockIndex* pindex);
// Check stake modifier hard checkpoints
-bool CheckStakeModifierCheckpoints(int nHeight, unsigned int nStakeModifierChecksum);
+bool CheckStakeModifierCheckpoints(int nHeight, uint32_t nStakeModifierChecksum);
// Get time weight using supplied timestamps
int64_t GetWeight(int64_t nIntervalBeginning, int64_t nIntervalEnd);
class CDiskTxPos
{
public:
- unsigned int nFile;
- unsigned int nBlockPos;
- unsigned int nTxPos;
+ uint32_t nFile;
+ uint32_t nBlockPos;
+ uint32_t nTxPos;
CDiskTxPos()
{
{
public:
CTransaction* ptx;
- unsigned int n;
+ uint32_t n;
CInPoint() { SetNull(); }
CInPoint(CTransaction* ptxIn, unsigned int nIn) { ptx = ptxIn; n = nIn; }
{
public:
uint256 hash;
- unsigned int n;
+ uint32_t n;
COutPoint() { SetNull(); }
COutPoint(uint256 hashIn, unsigned int nIn) { hash = hashIn; n = nIn; }
public:
COutPoint prevout;
CScript scriptSig;
- unsigned int nSequence;
+ uint32_t nSequence;
CTxIn()
{
public:
static const int CURRENT_VERSION=1;
int nVersion;
- unsigned int nTime;
+ uint32_t nTime;
std::vector<CTxIn> vin;
std::vector<CTxOut> vout;
- unsigned int nLockTime;
+ uint32_t nLockTime;
// Denial-of-service detection:
mutable int nDoS;
public:
uint256 hashBlock;
std::vector<uint256> vMerkleBranch;
- int nIndex;
+ int32_t nIndex;
// memory only
mutable bool fMerkleVerified;
public:
// header
static const int CURRENT_VERSION=6;
- int nVersion;
+ int32_t nVersion;
uint256 hashPrevBlock;
uint256 hashMerkleRoot;
- unsigned int nTime;
- unsigned int nBits;
- unsigned int nNonce;
+ uint32_t nTime;
+ uint32_t nBits;
+ uint32_t nNonce;
// network and disk
std::vector<CTransaction> vtx;
const uint256* phashBlock;
CBlockIndex* pprev;
CBlockIndex* pnext;
- unsigned int nFile;
- unsigned int nBlockPos;
+ uint32_t nFile;
+ uint32_t nBlockPos;
uint256 nChainTrust; // ppcoin: trust score of block chain
- int nHeight;
+ int32_t nHeight;
int64_t nMint;
int64_t nMoneySupply;
- unsigned int nFlags; // ppcoin: block index flags
+ uint32_t nFlags; // ppcoin: block index flags
enum
{
BLOCK_PROOF_OF_STAKE = (1 << 0), // is proof-of-stake block
};
uint64_t nStakeModifier; // hash modifier for proof-of-stake
- unsigned int nStakeModifierChecksum; // checksum of index; in-memeory only
+ uint32_t nStakeModifierChecksum; // checksum of index; in-memeory only
// proof-of-stake specific fields
COutPoint prevoutStake;
- unsigned int nStakeTime;
+ uint32_t nStakeTime;
uint256 hashProofOfStake;
// block header
- int nVersion;
- uint256 hashMerkleRoot;
- unsigned int nTime;
- unsigned int nBits;
- unsigned int nNonce;
+ int32_t nVersion;
+ uint256 hashMerkleRoot;
+ uint32_t nTime;
+ uint32_t nBits;
+ uint32_t nNonce;
CBlockIndex()
{
-unsigned int pnSeed[] =
+uint32_t pnSeed[] =
{
0x5360a653, 0x6c47bb25, 0x52568c5f, 0xc6f5c851, 0x6f17f3a2, 0x1d52a9d5, 0x2c1544c1, 0xb8748368,
0x055d6ac1, 0x2490bb25, 0x614488d5, 0xa463f8a2, 0xc54c1256, 0xf72d9252, 0x548432c6, 0xade08368,
int64_t nLastRecv;
int64_t nTimeConnected;
std::string addrName;
- int nVersion;
+ int32_t nVersion;
std::string strSubVer;
bool fInbound;
int64_t nReleaseTime;
- int nStartingHeight;
- int nMisbehavior;
+ int32_t nStartingHeight;
+ int32_t nMisbehavior;
uint64_t nSendBytes;
uint64_t nRecvBytes;
bool fSyncNode;
int64_t nLastRecv;
int64_t nLastSendEmpty;
int64_t nTimeConnected;
- int nHeaderStart;
- unsigned int nMessageStart;
+ int32_t nHeaderStart;
+ uint32_t nMessageStart;
CAddress addr;
std::string addrName;
CService addrLocal;
- int nVersion;
+ int32_t nVersion;
std::string strSubVer;
bool fOneShot;
bool fClient;
uint256 hashContinue;
CBlockIndex* pindexLastGetBlocksBegin;
uint256 hashLastGetBlocksEnd;
- int nStartingHeight;
+ int32_t nStartingHeight;
bool fStartSync;
// flood relay
return;
// Set the size
- unsigned int nSize = vSend.size() - nMessageStart;
+ uint32_t nSize = vSend.size() - nMessageStart;
memcpy((char*)&vSend[nHeaderStart] + CMessageHeader::MESSAGE_SIZE_OFFSET, &nSize, sizeof(nSize));
// Set the checksum
uint256 hash = Hash(vSend.begin() + nMessageStart, vSend.end());
- unsigned int nChecksum = 0;
+ uint32_t nChecksum = 0;
memcpy(&nChecksum, &hash, sizeof(nChecksum));
assert(nMessageStart - nHeaderStart >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum));
memcpy((char*)&vSend[nHeaderStart] + CMessageHeader::CHECKSUM_OFFSET, &nChecksum, sizeof(nChecksum));
CTxIn MultisigInputEntry::getInput()
{
- int nOutput = ui->transactionOutput->currentIndex();
+ unsigned int nOutput = ui->transactionOutput->currentIndex();
CTxIn input(COutPoint(txHash, nOutput));
return input;
int64_t MultisigInputEntry::getAmount()
{
int64_t amount = 0;
- int nOutput = ui->transactionOutput->currentIndex();
+ unsigned int nOutput = ui->transactionOutput->currentIndex();
CTransaction tx;
uint256 blockHash = 0;
uint256 blockHash = 0;
if(!GetTransaction(txHash, tx, blockHash))
return;
- for(int i = 0; i < tx.vout.size(); i++)
+ for(unsigned int i = 0; i < tx.vout.size(); i++)
{
QString idStr;
idStr.setNum(i);
// (xn ... x2 x1 x0 n - ... x2 x1 x0 xn)
if (stack.size() < 2)
return false;
- int n = CastToBigNum(stacktop(-1)).getint();
+ int n = CastToBigNum(stacktop(-1)).getint32();
popstack(stack);
if (n < 0 || n >= (int)stack.size())
return false;
if ((int)stack.size() < i)
return false;
- int nKeysCount = CastToBigNum(stacktop(-i)).getint();
+ int nKeysCount = CastToBigNum(stacktop(-i)).getint32();
if (nKeysCount < 0 || nKeysCount > 20)
return false;
nOpCount += nKeysCount;
if ((int)stack.size() < i)
return false;
- int nSigsCount = CastToBigNum(stacktop(-i)).getint();
+ int nSigsCount = CastToBigNum(stacktop(-i)).getint32();
if (nSigsCount < 0 || nSigsCount > nKeysCount)
return false;
int isig = ++i;
inline std::string ValueString(const std::vector<unsigned char>& vch)
{
if (vch.size() <= 4)
- return strprintf("%d", CBigNum(vch).getint());
+ return strprintf("%d", CBigNum(vch).getint32());
else
return HexStr(vch);
}
return ret;
}
+ explicit CScript(int8_t b) { operator<<(b); }
+ explicit CScript(int16_t b) { operator<<(b); }
+ explicit CScript(int32_t b) { operator<<(b); }
+ explicit CScript(int64_t b) { operator<<(b); }
- //explicit CScript(char b) is not portable. Use 'signed char' or 'unsigned char'.
- explicit CScript(signed char b) { operator<<(b); }
- explicit CScript(short b) { operator<<(b); }
- explicit CScript(int b) { operator<<(b); }
- explicit CScript(long b) { operator<<(b); }
- explicit CScript(unsigned char b) { operator<<(b); }
- explicit CScript(unsigned int b) { operator<<(b); }
- explicit CScript(unsigned short b) { operator<<(b); }
- explicit CScript(unsigned long b) { operator<<(b); }
+ explicit CScript(uint8_t b) { operator<<(b); }
+ explicit CScript(uint16_t b) { operator<<(b); }
+ explicit CScript(uint32_t b) { operator<<(b); }
+ explicit CScript(uint64_t b) { operator<<(b); }
explicit CScript(opcodetype b) { operator<<(b); }
explicit CScript(const uint256& b) { operator<<(b); }
explicit CScript(const std::vector<unsigned char>& b) { operator<<(b); }
- //CScript& operator<<(char b) is not portable. Use 'signed char' or 'unsigned char'.
- CScript& operator<<(signed char b) { return push_int64(b); }
- CScript& operator<<(short b) { return push_int64(b); }
- CScript& operator<<(int b) { return push_int64(b); }
- CScript& operator<<(long b) { return push_int64(b); }
- CScript& operator<<(unsigned char b) { return push_uint64(b); }
- CScript& operator<<(unsigned int b) { return push_uint64(b); }
- CScript& operator<<(unsigned short b) { return push_uint64(b); }
- CScript& operator<<(unsigned long b) { return push_uint64(b); }
+ CScript& operator<<(int8_t b) { return push_int64(b); }
+ CScript& operator<<(int16_t b) { return push_int64(b); }
+ CScript& operator<<(int32_t b) { return push_int64(b); }
+ CScript& operator<<(int64_t b) { return push_int64(b); }
+
+ CScript& operator<<(uint8_t b) { return push_uint64(b); }
+ CScript& operator<<(uint16_t b) { return push_uint64(b); }
+ CScript& operator<<(uint32_t b) { return push_uint64(b); }
+ CScript& operator<<(uint64_t b) { return push_uint64(b); }
CScript& operator<<(opcodetype opcode)
{
return *this;
}
- CScript& operator<<(const std::vector<unsigned char>& b)
+ CScript& operator<<(const std::vector<uint8_t>& b)
{
if (b.size() < OP_PUSHDATA1)
{
- insert(end(), (unsigned char)b.size());
+ insert(end(), (uint8_t)b.size());
}
else if (b.size() <= 0xff)
{
insert(end(), OP_PUSHDATA1);
- insert(end(), (unsigned char)b.size());
+ insert(end(), (uint8_t)b.size());
}
else if (b.size() <= 0xffff)
{
insert(end(), OP_PUSHDATA2);
- unsigned short nSize = b.size();
+ uint16_t nSize = b.size();
insert(end(), (unsigned char*)&nSize, (unsigned char*)&nSize + sizeof(nSize));
}
else
{
insert(end(), OP_PUSHDATA4);
- unsigned int nSize = b.size();
+ uint32_t nSize = b.size();
insert(end(), (unsigned char*)&nSize, (unsigned char*)&nSize + sizeof(nSize));
}
insert(end(), b.begin(), b.end());