From a712c1a9fcc4cf97f037eff473c807f0c9c102df Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Sun, 23 Aug 2015 00:11:34 +0300 Subject: [PATCH] Add SignatureOK property, init block signature with zero lengh byte array --- Novacoin/CBlock.cs | 69 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 64 insertions(+), 5 deletions(-) diff --git a/Novacoin/CBlock.cs b/Novacoin/CBlock.cs index 82a8b88..184b5f6 100644 --- a/Novacoin/CBlock.cs +++ b/Novacoin/CBlock.cs @@ -19,10 +19,10 @@ namespace Novacoin /// public CTransaction[] vtx; - /// - /// Block header signature. - /// - public byte[] signature; + /// + /// Block header signature. + /// + public byte[] signature = new byte[0]; public CBlock(CBlock b) { @@ -63,6 +63,63 @@ namespace Novacoin } /// + /// Is this a Proof-of-Stake block? + /// + public bool IsProofOfStake + { + get + { + return (vtx.Length > 1 && vtx[1].IsCoinStake); + } + } + + public bool SignatureOK + { + get + { + IList> solutions; + txnouttype whichType; + + if (IsProofOfStake) + { + if (signature.Length == 0) + { + return false; // No signature + } + + if (!ScriptCode.Solver(vtx[1].vout[1].scriptPubKey, out whichType, out solutions)) + { + return false; // No solutions found + } + + if (whichType == txnouttype.TX_PUBKEY) + { + CPubKey pubkey; + + try + { + pubkey = new CPubKey(solutions[0]); + } + catch (Exception) + { + return false; // Error while loading public key + } + + return pubkey.VerifySignature(header.Hash, signature); + } + } + else + { + // Proof-of-Work blocks have no signature + + return true; + } + + return false; + } + } + + /// /// Convert current instance into sequence of bytes /// /// Byte sequence @@ -99,7 +156,9 @@ namespace Novacoin } sb.AppendFormat("signature={0})\n", Interop.ToHex(signature)); - + sb.AppendFormat("signatureOK={0})\n", SignatureOK); + + // TODO return sb.ToString(); } -- 1.7.1