public Spendable(OutPoint output, TxOut txout) { if(output == null) throw new ArgumentNullException("output"); if(txout == null) throw new ArgumentNullException("txout"); _Out = txout; _OutPoint = output; }
public Vin(NBitcoin.OutPoint prevOut, NBitcoin.Sequence sequence, NBitcoin.Script scriptSig) { if (prevOut.Hash == uint256.Zero) { coinbase = Encoders.Hex.EncodeData(scriptSig.ToBytes()); } else { this.txid = prevOut.Hash.ToString(); this.vout = prevOut.N; this.scriptSig = new Script(scriptSig);; } this.sequence = (uint)sequence; }
public StealthCoin(OutPoint outpoint, TxOut txOut, Script redeem, StealthMetadata stealthMetadata, BitcoinStealthAddress address) : base(outpoint, txOut) { StealthMetadata = stealthMetadata; Address = address; Redeem = redeem; }
public ScriptCoin(OutPoint fromOutpoint, TxOut fromTxOut, Script redeem) : base(fromOutpoint, fromTxOut) { Redeem = redeem; AssertCoherent(); }
public Coin(IndexedTxOut txOut) { Outpoint = new OutPoint(txOut.Transaction.GetHash(), txOut.N); TxOut = txOut.TxOut; }
public Coin(Transaction fromTx, uint fromOutputIndex) { if (fromTx == null) throw new ArgumentNullException("fromTx"); Outpoint = new OutPoint(fromTx, fromOutputIndex); TxOut = fromTx.Outputs[fromOutputIndex]; }
private void ReadWrite(BitcoinStream stream) { if(stream.Serializing) { stream.ReadWrite((byte)0x32); stream.ReadWrite(Flags); } else { if(stream.Inner.ReadByte() != 0x32) throw new FormatException("Invalid magic version"); Flags = (byte)stream.Inner.ReadByte(); } stream.ReadWrite(ref _Nonce); if(stream.Serializing) { uint256 txId = OutPoint.Hash; stream.ReadWrite(ref txId); uint index = OutPoint.N; stream.ReadWrite(ref index); } else { uint256 txId = new uint256(); stream.ReadWrite(ref txId); uint index = 0; stream.ReadWrite(ref index); _OutPoint = new OutPoint(txId, index); } ulong amount = stream.Serializing ? (ulong)_Amount.Satoshi : 0; stream.ReadWrite(ref amount); _Amount = Money.Satoshis(amount); _Signature = stream.Serializing ? _Signature : new byte[8]; stream.ReadWrite(ref _Signature); }
public bool Contains(OutPoint outPoint) { if (outPoint == null) throw new ArgumentNullException("outPoint"); return Contains(outPoint.ToBytes()); }
public Coin(OutPoint fromOutpoint, TxOut fromTxOut) { Outpoint = fromOutpoint; TxOut = fromTxOut; }
public bool Contains(OutPoint outPoint) { return Contains(outPoint.ToBytes()); }
public void Insert(OutPoint outPoint) { Insert(outPoint.ToBytes()); }
public ICoin FindCoin(OutPoint outPoint) { var result = _BuilderGroups.Select(c => c.Coins.TryGet(outPoint)).FirstOrDefault(r => r != null); if(result == null && CoinFinder != null) result = CoinFinder(outPoint); return result; }
public WitScriptCoin(OutPoint fromOutpoint, TxOut fromTxOut, Script witRedeem) : base(fromOutpoint, fromTxOut) { SetAll(fromTxOut.ScriptPubKey, witRedeem); }
public TxIn(OutPoint prevout) { this.prevout = prevout; }
public OutPoint(OutPoint outpoint) { this.FromBytes(outpoint.ToBytes()); }
public Coin(uint256 fromTxHash, uint fromOutputIndex, Money amount, Script scriptPubKey) { Outpoint = new OutPoint(fromTxHash, fromOutputIndex); TxOut = new TxOut(amount, scriptPubKey); }
public void Insert(OutPoint outPoint) { if (outPoint == null) throw new ArgumentNullException("outPoint"); Insert(outPoint.ToBytes()); }
private void AddTxOut(OutPoint outpoint, TxOut txOut) { _TxOutByOutpoint.Add(outpoint, txOut); }
public static TxoRef ToTxoRef(this OutPoint me) => new TxoRef(me);
public Coin(OutPoint fromOutpoint, TxOut fromTxOut) { this.Outpoint = fromOutpoint; this.TxOut = fromTxOut; }
public Coin(Transaction fromTx, TxOut fromOutput) { if (fromTx == null) throw new ArgumentNullException("fromTx"); if (fromOutput == null) throw new ArgumentNullException("fromOutput"); uint outputIndex = (uint)fromTx.Outputs.FindIndex(r => Object.ReferenceEquals(fromOutput, r)); Outpoint = new OutPoint(fromTx, outputIndex); TxOut = fromOutput; }
public ScriptCoin(OutPoint fromOutpoint, TxOut fromTxOut, Script redeem) : base(fromOutpoint, fromTxOut) { this.Redeem = redeem; }
public IssuanceCoin(OutPoint outpoint, TxOut txout) { this.Bearer = new Coin(outpoint, txout); }
public IssuanceCoin(OutPoint outpoint, TxOut txout) { Bearer = new Coin(outpoint, txout); }
public static ScriptCoin Create(Network network, OutPoint fromOutpoint, TxOut fromTxOut, Script redeem) { return(new ScriptCoin(fromOutpoint, fromTxOut, redeem).AssertCoherent(network)); }
// Stratis kernel protocol // coinstake must meet hash target according to the protocol: // kernel (input 0) must meet the formula // hash(nStakeModifier + txPrev.block.nTime + txPrev.nTime + txPrev.vout.hash + txPrev.vout.n + nTime) < bnTarget * nWeight // this ensures that the chance of getting a coinstake is proportional to the // amount of coins one owns. // The reason this hash is chosen is the following: // nStakeModifier: scrambles computation to make it very difficult to precompute // future proof-of-stake // txPrev.block.nTime: prevent nodes from guessing a good timestamp to // generate transaction for future advantage, // obsolete since v3 // txPrev.nTime: slightly scrambles computation // txPrev.vout.hash: hash of txPrev, to reduce the chance of nodes // generating coinstake at the same time // txPrev.vout.n: output number of txPrev, to reduce the chance of nodes // generating coinstake at the same time // nTime: current timestamp // block/tx hash should not be used here as they can be generated in vast // quantities so as to generate blocks faster, degrading the system back into // a proof-of-work situation. // private static bool CheckStakeKernelHashV2(ChainedBlock pindexPrev, uint nBits, uint nTimeBlockFrom, BlockStake prevBlockStake, Transaction txPrev, OutPoint prevout, uint nTimeTx, out uint256 hashProofOfStake, out uint256 targetProofOfStake, bool fPrintProofOfStake) { targetProofOfStake = null; hashProofOfStake = null; if (nTimeTx < txPrev.Time) // Transaction timestamp violation { return(false); //error("CheckStakeKernelHash() : nTime violation"); } // Base target var bnTarget = new Target(nBits).ToBigInteger(); // Weighted target var nValueIn = txPrev.Outputs[prevout.N].Value.Satoshi; var bnWeight = BigInteger.ValueOf(nValueIn); bnTarget = bnTarget.Multiply(bnWeight); // todo: investigate this issue, is the convertion to uint256 similar to the c++ implementation //targetProofOfStake = Target.ToUInt256(bnTarget); var nStakeModifier = prevBlockStake.StakeModifier; //pindexPrev.Header.BlockStake.StakeModifier; uint256 bnStakeModifierV2 = prevBlockStake.StakeModifierV2; //pindexPrev.Header.BlockStake.StakeModifierV2; int nStakeModifierHeight = pindexPrev.Height; var nStakeModifierTime = pindexPrev.Header.Time; // Calculate hash using (var ms = new MemoryStream()) { var serializer = new BitcoinStream(ms, true); if (IsProtocolV3((int)nTimeTx)) { serializer.ReadWrite(bnStakeModifierV2); } else { serializer.ReadWrite(nStakeModifier); serializer.ReadWrite(nTimeBlockFrom); } serializer.ReadWrite(txPrev.Time); serializer.ReadWrite(prevout.Hash); serializer.ReadWrite(prevout.N); serializer.ReadWrite(nTimeTx); hashProofOfStake = Hashes.Hash256(ms.ToArray()); } if (fPrintProofOfStake) { //LogPrintf("CheckStakeKernelHash() : using modifier 0x%016x at height=%d timestamp=%s for block from timestamp=%s\n", // nStakeModifier, nStakeModifierHeight, // DateTimeStrFormat(nStakeModifierTime), // DateTimeStrFormat(nTimeBlockFrom)); //LogPrintf("CheckStakeKernelHash() : check modifier=0x%016x nTimeBlockFrom=%u nTimeTxPrev=%u nPrevout=%u nTimeTx=%u hashProof=%s\n", // nStakeModifier, // nTimeBlockFrom, txPrev.nTime, prevout.n, nTimeTx, // hashProofOfStake.ToString()); } // Now check if proof-of-stake hash meets target protocol var hashProofOfStakeTarget = new BigInteger(hashProofOfStake.ToBytes(false)); if (hashProofOfStakeTarget.CompareTo(bnTarget) > 0) { return(false); } // if (fDebug && !fPrintProofOfStake) // { // LogPrintf("CheckStakeKernelHash() : using modifier 0x%016x at height=%d timestamp=%s for block from timestamp=%s\n", // nStakeModifier, nStakeModifierHeight, // DateTimeStrFormat(nStakeModifierTime), // DateTimeStrFormat(nTimeBlockFrom)); // LogPrintf("CheckStakeKernelHash() : pass modifier=0x%016x nTimeBlockFrom=%u nTimeTxPrev=%u nPrevout=%u nTimeTx=%u hashProof=%s\n", // nStakeModifier, // nTimeBlockFrom, txPrev.nTime, prevout.n, nTimeTx, // hashProofOfStake.ToString()); // } return(true); }
public static bool CheckKernel(INBitcoinBlockRepository blockStore, ITransactionRepository trasnactionStore, IBlockTransactionMapStore mapStore, StakeChain stakeChain, ChainedBlock pindexPrev, uint nBits, long nTime, OutPoint prevout, ref long pBlockTime) { uint256 hashProofOfStake = null, targetProofOfStake = null; var txPrev = trasnactionStore.Get(prevout.Hash); if (txPrev == null) { return(false); } // Read block header var blockHashPrev = mapStore.GetBlockHash(prevout.Hash); var block = blockHashPrev == null ? null : blockStore.GetBlock(blockHashPrev); if (block == null) { return(false); } if (IsProtocolV3((int)nTime)) { int nDepth = 0; if (IsConfirmedInNPrevBlocks(blockStore, txPrev, pindexPrev, StakeMinConfirmations - 1, ref nDepth)) { return(false); // tx.DoS(100, error("CheckProofOfStake() : tried to stake at depth %d", nDepth + 1)); } } else { var nTimeBlockFrom = block.Header.Time; if (nTimeBlockFrom + StakeMinAge > nTime) { return(false); // error("CheckProofOfStake() : min age violation"); } } var prevBlockStake = stakeChain.Get(pindexPrev.HashBlock); if (prevBlockStake == null) { return(false); // the stake proof of the previous block is not set } // todo: check this unclear logic //if (pBlockTime) // pBlockTime = block.Header.Time; return(CheckStakeKernelHash(pindexPrev, nBits, block, txPrev, prevBlockStake, prevout, (uint)nTime, out hashProofOfStake, out targetProofOfStake, false)); }