bn = new BigInteger(BitConverter.GetBytes(ulongValue));
}
+ public BigNum(long longValue)
+ {
+ bn = new BigInteger(Math.Sign(longValue), BitConverter.GetBytes(longValue));
+ }
+
public BigNum(uint256 uint256Value)
{
bn = new BigInteger(uint256Value);
return new BigNum(a.bn.Add(bnValueToAdd));
}
+ public static BigNum operator +(BigNum a, long b)
+ {
+ var bnValueToAdd = new BigInteger(BitConverter.GetBytes(b));
+ return new BigNum(a.bn.Add(bnValueToAdd));
+ }
+
public static BigNum operator -(BigNum a, ulong b)
{
var bnValueToSubstract = new BigInteger(BitConverter.GetBytes(b));
return new BigNum(a.bn.Subtract(bnValueToSubstract));
}
+ public static BigNum operator -(BigNum a, long b)
+ {
+ var bnValueToSubstract = new BigInteger(BitConverter.GetBytes(b));
+ return new BigNum(a.bn.Subtract(bnValueToSubstract));
+ }
public static BigNum operator +(BigNum a, uint256 b)
{
return new BigNum(a.bn.Divide(bnDivider));
}
+ public static BigNum operator /(BigNum a, long b)
+ {
+ var bnDivider = new BigInteger(BitConverter.GetBytes(b));
+ return new BigNum(a.bn.Divide(bnDivider));
+ }
+
public static BigNum operator /(BigNum a, uint256 b)
{
var bnDivider = new BigInteger(b);
return new BigNum(a.bn.Multiply(bnMultiplier));
}
+ public static BigNum operator *(BigNum a, long b)
+ {
+ var bnMultiplier = new BigInteger(BitConverter.GetBytes(b));
+ return new BigNum(a.bn.Multiply(bnMultiplier));
+ }
+
public static BigNum operator *(BigNum a, uint256 b)
{
var bnMultiplier = new BigInteger(b);
return new BigNum(ulongValue);
}
+ public static implicit operator BigNum(long ulongValue)
+ {
+ return new BigNum(ulongValue);
+ }
+
public static implicit operator BigNum(uint256 uint256Value)
{
return new BigNum(uint256Value);
return (ulong)a.bn.LongValue;
}
+ public static implicit operator long (BigNum a)
+ {
+ return a.bn.LongValue;
+ }
+
public int CompareTo(BigNum other)
{
return bn.CompareTo(other.bn);
/// <param name="nBits">Packed difficulty representation.</param>
/// <param name="nFees">Amount of fees.</param>
/// <returns>Reward value.</returns>
- public static ulong GetProofOfWorkReward(uint nBits, ulong nFees)
+ public static long GetProofOfWorkReward(uint nBits, long nFees)
{
// NovaCoin: subsidy is cut in half every 64x multiply of PoW difficulty
// A reasonably continuous curve is used to avoid shock to market
bnLowerBound = bnMidValue;
}
- ulong nSubsidy = bnUpperBound;
+ long nSubsidy = (long)bnUpperBound;
nSubsidy = (nSubsidy / CTransaction.nCent) * CTransaction.nCent;
return Math.Min(nSubsidy, NetInfo.nMaxMintProofOfWork) + nFees;
}
- public static ulong GetProofOfStakeReward(ulong nCoinAge, uint nBits, uint nTime)
+ public static long GetProofOfStakeReward(long nCoinAge, uint nBits, uint nTime)
{
- ulong nRewardCoinYear, nSubsidy, nSubsidyLimit = 10 * CTransaction.nCoin;
+ long nRewardCoinYear, nSubsidy, nSubsidyLimit = 10 * CTransaction.nCoin;
if (nTime > NetInfo.nDynamicStakeRewardTime)
{
bool fScriptChecks = cursor.nHeight >= Checkpoints.TotalBlocksEstimate;
var scriptFlags = scriptflag.SCRIPT_VERIFY_NOCACHE | scriptflag.SCRIPT_VERIFY_P2SH;
- ulong nFees = 0;
- ulong nValueIn = 0;
- ulong nValueOut = 0;
+ long nFees = 0;
+ long nValueIn = 0;
+ long nValueOut = 0;
uint nSigOps = 0;
var queuedMerkleNodes = new Dictionary<uint256, CMerkleNode>();
return false; // too many sigops
}
- ulong nTxValueIn = tx.GetValueIn(ref inputs);
- ulong nTxValueOut = tx.nValueOut;
+ long nTxValueIn = tx.GetValueIn(ref inputs);
+ long nTxValueOut = tx.nValueOut;
nValueIn += nTxValueIn;
nValueOut += nTxValueOut;
if (!block.IsProofOfStake)
{
- ulong nBlockReward = CBlock.GetProofOfWorkReward(cursor.nBits, nFees);
+ long nBlockReward = CBlock.GetProofOfWorkReward(cursor.nBits, nFees);
// Check coinbase reward
if (block.vtx[0].nValueOut > nBlockReward)
}
}
- cursor.nMint = (long)(nValueOut - nValueIn + nFees);
- cursor.nMoneySupply = (cursor.prev != null ? cursor.prev.nMoneySupply : 0) + (long)nValueOut - (long)nValueIn;
+ cursor.nMint = nValueOut - nValueIn + nFees;
+ cursor.nMoneySupply = (cursor.prev != null ? cursor.prev.nMoneySupply : 0) + nValueOut - nValueIn;
if (!UpdateDBCursor(ref cursor))
{
if (!tx.IsCoinBase)
{
- ulong nValueIn = 0;
- ulong nFees = 0;
+ long nValueIn = 0;
+ long nFees = 0;
for (uint i = 0; i < tx.vin.Length; i++)
{
var prevout = tx.vin[i].prevout;
if (tx.IsCoinStake)
{
// ppcoin: coin stake tx earns reward instead of paying fee
- ulong nCoinAge;
+ long nCoinAge;
if (!tx.GetCoinAge(ref inputs, out nCoinAge))
{
return false; // unable to get coin age for coinstake
}
- ulong nReward = tx.nValueOut - nValueIn;
+ long nReward = tx.nValueOut - nValueIn;
- ulong nCalculatedReward = CBlock.GetProofOfStakeReward(nCoinAge, cursorBlock.nBits, tx.nTime) - tx.GetMinFee(1, false, CTransaction.MinFeeMode.GMF_BLOCK) + CTransaction.nCent;
+ long nCalculatedReward = CBlock.GetProofOfStakeReward(nCoinAge, cursorBlock.nBits, tx.nTime) - tx.GetMinFee(1, false, CTransaction.MinFeeMode.GMF_BLOCK) + CTransaction.nCent;
if (nReward > nCalculatedReward)
{
}
// Tally transaction fees
- ulong nTxFee = nValueIn - tx.nValueOut;
+ long nTxFee = nValueIn - tx.nValueOut;
if (nTxFee < 0)
{
return false; // nTxFee < 0
/// <summary>
/// One cent = 10000 satoshis.
/// </summary>
- public const ulong nCent = 10000;
+ public const long nCent = 10000;
/// <summary>
/// One coin = 1000000 satoshis.
/// </summary>
- public const ulong nCoin = 1000000;
+ public const long nCoin = 1000000;
/// <summary>
/// Sanity checking threshold.
/// </summary>
- public const ulong nMaxMoney = 2000000000 * nCoin;
+ public const long nMaxMoney = 2000000000 * nCoin;
- public const ulong nMinTxFee = nCent / 10;
- public const ulong nMinRelayTxFee = nCent / 50;
- public const ulong nMinTxoutAmount = nCent / 100;
+ public const long nMinTxFee = nCent / 10;
+ public const long nMinRelayTxFee = nCent / 50;
+ public const long nMinTxoutAmount = nCent / 100;
/// <summary>
/// Maximum transaction size is 250Kb
}
// Check for empty or overflow output values
- ulong nValueOut = 0;
+ long nValueOut = 0;
for (int i = 0; i < vout.Length; i++)
{
CTxOut txout = vout[i];
{
// Fill outputs array
vout[nCurrentOutput] = new CTxOut();
- vout[nCurrentOutput].nValue = reader.ReadUInt64();
+ vout[nCurrentOutput].nValue = reader.ReadInt64();
int nScriptPKLen = (int)VarInt.ReadVarInt(ref reader);
vout[nCurrentOutput].scriptPubKey = new CScript(reader.ReadBytes(nScriptPKLen));
/// <summary>
/// Amount of novacoins spent by this transaction.
/// </summary>
- public ulong nValueOut
+ public long nValueOut
{
get
{
- ulong nValueOut = 0;
+ long nValueOut = 0;
foreach (var txout in vout)
{
nValueOut += txout.nValue;
return sb.ToString();
}
- public static bool MoneyRange(ulong nValue) { return (nValue <= nMaxMoney); }
+ public static bool MoneyRange(long nValue) { return (nValue <= nMaxMoney); }
/// <summary>
/// Get total sigops.
/// </summary>
/// <param name="inputs">Reference to innputs map.</param>
/// <returns>Sum of inputs.</returns>
- public ulong GetValueIn(ref Dictionary<COutPoint, TxOutItem> inputs)
+ public long GetValueIn(ref Dictionary<COutPoint, TxOutItem> inputs)
{
if (IsCoinBase)
{
return 0;
}
- ulong nResult = 0;
+ long nResult = 0;
for (int i = 0; i < vin.Length; i++)
{
nResult += GetOutputFor(vin[i], ref inputs).nValue;
/// <param name="inputs">Inputs set.</param>
/// <param name="nCoinAge">Coin age calculation result.</param>
/// <returns>Result</returns>
- public bool GetCoinAge(ref Dictionary<COutPoint, TxOutItem> inputs, out ulong nCoinAge)
+ public bool GetCoinAge(ref Dictionary<COutPoint, TxOutItem> inputs, out long nCoinAge)
{
BigInteger bnCentSecond = 0; // coin age in the unit of cent-seconds
nCoinAge = 0;
continue; // only count coins meeting min age requirement
}
- ulong nValueIn = input.nValue;
+ long nValueIn = input.nValue;
bnCentSecond += new BigInteger(nValueIn) * (nTime - merkleItem.nTime) / nCent;
}
BigInteger bnCoinDay = bnCentSecond * nCent / nCoin / (24 * 60 * 60);
- nCoinAge = (ulong)bnCoinDay;
+ nCoinAge = (long)bnCoinDay;
return true;
}
- public ulong GetMinFee(uint nBlockSize, bool fAllowFree, MinFeeMode mode)
+ public long GetMinFee(uint nBlockSize, bool fAllowFree, MinFeeMode mode)
{
- ulong nMinTxFee = CTransaction.nMinTxFee, nMinRelayTxFee = CTransaction.nMinRelayTxFee;
+ long nMinTxFee = CTransaction.nMinTxFee, nMinRelayTxFee = CTransaction.nMinRelayTxFee;
uint nBytes = Size;
if (IsCoinStake)
}
// Base fee is either nMinTxFee or nMinRelayTxFee
- ulong nBaseFee = (mode == MinFeeMode.GMF_RELAY) ? nMinRelayTxFee : nMinTxFee;
+ long nBaseFee = (mode == MinFeeMode.GMF_RELAY) ? nMinRelayTxFee : nMinTxFee;
uint nNewBlockSize = nBlockSize + nBytes;
- ulong nMinFee = (1 + (ulong)nBytes / 1000) * nBaseFee;
+ long nMinFee = (1 + (long)nBytes / 1000) * nBaseFee;
if (fAllowFree)
{
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-using System;
using System.Text;
-using System.Collections.Generic;
using System.IO;
namespace Novacoin
{
- /// <summary>
- /// Transaction output.
- /// </summary>
- public class CTxOut
+ /// <summary>
+ /// Transaction output.
+ /// </summary>
+ public class CTxOut
{
/// <summary>
/// Input value.
/// </summary>
- public ulong nValue = ulong.MaxValue;
+ public long nValue = unchecked((long)0xffffffffffffffff);
/// <summary>
/// Second half of script which contains spending instructions.
/// </summary>
/// <param name="nValue">Input value</param>
/// <param name="scriptPubKey">Spending instructions.</param>
- public CTxOut(ulong nValue, CScript scriptPubKey)
+ public CTxOut(long nValue, CScript scriptPubKey)
{
this.nValue = nValue;
this.scriptPubKey = scriptPubKey;
{
// Fill outputs array
vout[nIndex] = new CTxOut();
- vout[nIndex].nValue = reader.ReadUInt64();
+ vout[nIndex].nValue = reader.ReadInt64();
int nScriptPKLen = (int)VarInt.ReadVarInt(ref reader);
vout[nIndex].scriptPubKey = new CScript(reader.ReadBytes(nScriptPKLen));
/// </summary>
public void SetNull()
{
- nValue = ulong.MaxValue;
+ nValue = unchecked((long)0xffffffffffffffff);
scriptPubKey = new CScript();
}
public bool IsNull
{
- get { return (nValue == ulong.MaxValue); }
+ get { return nValue == unchecked((long)0xffffffffffffffff); }
}
public bool IsEmpty
/// Getter for output value.
/// </summary>
[Ignore]
- public ulong nValue
+ public long nValue
{
get { return VarInt.DecodeVarInt(OutputValue); }
set { OutputValue = VarInt.EncodeVarInt(value); }
/// <summary>
/// Maximum possible proof-of-work reward.
/// </summary>
- public const ulong nMaxMintProofOfWork = CTransaction.nCoin * 100;
+ public const long nMaxMintProofOfWork = CTransaction.nCoin * 100;
/// <summary>
/// Maximum possible proof-of-stake reward per coin*year.
/// </summary>
- public const ulong nMaxMintProofOfStake = CTransaction.nCoin * 100;
+ public const long nMaxMintProofOfStake = CTransaction.nCoin * 100;
public static uint GetAdjustedTime()
{
uint256 nTargetPerCoinDay = 0;
nTargetPerCoinDay.Compact = nBits;
- ulong nValueIn = txPrev.vout[prevout.n].nValue;
- uint256 nCoinDayWeight = new uint256(nValueIn) * GetWeight(txPrev.nTime, nTimeTx) / CTransaction.nCoin / (24 * 60 * 60);
+ long nValueIn = txPrev.vout[prevout.n].nValue;
+ uint256 nCoinDayWeight = new uint256((ulong)nValueIn) * GetWeight(txPrev.nTime, nTimeTx) / CTransaction.nCoin / (24 * 60 * 60);
targetProofOfStake = nCoinDayWeight * nTargetPerCoinDay;
}
else
{
- // ulong flag
+ // long flag
prefix = 0xff;
valueBytes = BitConverter.GetBytes(n);
}
/// </summary>
/// <param name="bytes">Byte sequence</param>
/// <returns>Integer value</returns>
- public static ulong DecodeVarInt(byte[] bytes)
+ public static long DecodeVarInt(byte[] bytes)
{
var prefix = bytes[0];
return BitConverter.ToUInt16(bytesArray, 0);
case 0xfe: // uint flag
return BitConverter.ToUInt32(bytesArray, 0);
- case 0xff: // ulong flag
- return BitConverter.ToUInt64(bytesArray, 0);
+ case 0xff: // long flag
+ return BitConverter.ToInt64(bytesArray, 0);
}
}
return prefix; // Values lower than 0xfd are stored directly
}
- public static ulong ReadVarInt(ref BinaryReader reader)
+ public static long ReadVarInt(ref BinaryReader reader)
{
byte prefix = reader.ReadByte();
return reader.ReadUInt16();
case 0xfe: // uint
return reader.ReadUInt32();
- case 0xff: // ulong
- return reader.ReadUInt64();
+ case 0xff: // long
+ return reader.ReadInt64();
default:
return prefix;
}