Пример #1
0
        public ProvenBlockHeader(PosBlock block, PosBlockHeader posBlockHeader)
        {
            if (block == null)
            {
                throw new ArgumentNullException(nameof(block));
            }

            // Copy block header properties.
            this.posBlockHeader = posBlockHeader;
            this.posBlockHeader.HashPrevBlock     = block.Header.HashPrevBlock;
            this.posBlockHeader.HashMerkleRoot    = block.Header.HashMerkleRoot;
            this.posBlockHeader.Time              = block.Header.Time;
            this.posBlockHeader.Bits              = block.Header.Bits;
            this.posBlockHeader.Nonce             = block.Header.Nonce;
            this.posBlockHeader.Version           = block.Header.Version;
            this.posBlockHeader.ProvenBlockHeader = this;

            this.signature   = block.BlockSignature;
            this.coinstake   = block.GetProtocolTransaction();
            this.merkleProof = new MerkleBlock(block, new[] { this.coinstake.GetHash() }).PartialMerkleTree;
        }
Пример #2
0
        public ViewResult MAST(MASTModel model)
        {
            try
            {
                var script = new Script(Sanitize(model.Script));
                model.DecomposedScripts = new List <DecomposedScript>();
                var subScripts = script.Decompose();
                var hashes     = subScripts.Select(s => Hashes.Hash256(s.ToBytes())).ToArray();
                model.MerkleRoot = MerkleNode.GetRoot(hashes).Hash;
                int fullScriptSize = script.ToBytes().Length;
                model.FullScriptSize = fullScriptSize;
                int i = 0;
                foreach (var subScript in subScripts)
                {
                    bool[] matches = new bool[hashes.Length];
                    matches[i] = true;
                    PartialMerkleTree partial = new PartialMerkleTree(hashes, matches);
                    DecomposedScript  s       = new DecomposedScript();
                    s.Script            = subScript.ToString();
                    s.Bytes             = Encoders.Hex.EncodeData(subScript.ToBytes());
                    s.Hash              = Hashes.Hash256(subScript.ToBytes());
                    s.PartialMerkleTree = Encoders.Hex.EncodeData(partial.ToBytes());
                    model.DecomposedScripts.Add(s);
                    s.Size   = subScript.ToBytes().Length + partial.ToBytes().Length;
                    s.Saving = (int)(((decimal)(fullScriptSize - s.Size) / fullScriptSize) * 100m);

                    s.Size160   = (int)(subScript.ToBytes().Length + (decimal)partial.ToBytes().Length * 0.625m);
                    s.Saving160 = (int)(((decimal)(fullScriptSize - s.Size160) / fullScriptSize) * 100m);
                    i++;
                }
            }
            catch (FormatException ex)
            {
                ModelState.AddModelError("Script", "Invalid script (" + ex.Message + ")");
                return(View(model));
            }
            return(View(model));
        }
Пример #3
0
 public RegistrationCapsule(PartialMerkleTree merkleTree, Transaction tx)
 {
     this.RegistrationTransaction      = tx;
     this.RegistrationTransactionProof = merkleTree;
 }
Пример #4
0
 public RegistrationRecord(DateTime recordTimeStamp, Guid recordGuid, string recordTxId, string recordTxHex, RegistrationToken record, PartialMerkleTree recordTxProof, int blockReceived = -1)
 {
     RecordTimestamp    = recordTimeStamp;
     RecordGuid         = recordGuid;
     RecordTxId         = recordTxId;
     RecordTxHex        = recordTxHex;
     Record             = record;
     RecordTxProof      = recordTxProof;
     BlockReceived      = blockReceived;
     RegistrationMature = false;
 }
 public RegistrationRecord(DateTime recordTimeStamp, Guid recordGuid, string recordTxId, string recordTxHex, RegistrationToken record, PartialMerkleTree recordTxProof, int blockReceived = -1)
 {
     this.RecordTimestamp = recordTimeStamp;
     this.RecordGuid      = recordGuid;
     this.RecordTxId      = recordTxId;
     this.RecordTxHex     = recordTxHex;
     this.Token           = record;
     this.RecordTxProof   = recordTxProof;
     this.BlockReceived   = blockReceived;
 }