Пример #1
0
        public NeoEventMonitor1(NeoAPI api, Transaction deployTx, uint startBlock)
        {
            this._api        = api;
            this._startBlock = startBlock;

            this._listenerVM = new SnapshotVM(this);

            List <AVMInstruction> deployTxScript = NeoTools.Disassemble(deployTx.script);

            for (int i = 1; i < deployTxScript.Count; i++)
            {
                var instruction = deployTxScript[i];
                if (instruction.opcode == OpCode.SYSCALL && instruction.data != null)
                {
                    var method = Encoding.ASCII.GetString(instruction.data);

                    if (method == "Neo.Contract.Create")
                    {
                        Console.WriteLine($"method == Neo.Contract.Create");
                        var prevInstruction = deployTxScript[i - 1];
                        this._contractBytecode   = prevInstruction.data;
                        this._contractScriptHash = _contractBytecode.ToScriptHash();
                        Console.WriteLine($"_contractBytecode: {_contractBytecode.Length}\tcontractScriptHash: {this._contractScriptHash.ToString()}");
                        break;
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Find line of next diff
        /// </summary>
        /// <param name="line">cursor line</param>
        /// <returns>true if diffs found</returns>
        public bool TryGetNextDiff(SnapshotVM currrent, SnapshotVM parent, int line, ref int nextLine)
        {
            if (parent == null)
            {
                return(false);
            }

            var parentLine = GetParentLineNumber(currrent, parent, line);

            var nextUpdatesLine = DiffsChanged[currrent.Index][parent.Index].Keys.FirstOrDefault(e => e > line);
            var nextDeletedLine = DiffsDeleted[currrent.Index][parent.Index].Keys.FirstOrDefault(e => e > parentLine);

            if (nextUpdatesLine == 0 && nextDeletedLine == 0)
            {
                return(false);
            }

            var isChanges = true;

            if (nextUpdatesLine == 0)
            {
                isChanges = false;
            }
            if (nextDeletedLine != 0 && nextUpdatesLine > nextDeletedLine)
            {
                isChanges = false;
            }

            nextLine = isChanges ? nextUpdatesLine : GetParentLineNumber(parent, currrent, nextDeletedLine);

            return(true);
        }
Пример #3
0
        /// <summary>
        /// Select next snapshot according to viewed history
        /// </summary>
        private void FindPreferredDownWay(SnapshotVM snapshot)
        {
            ParentSnapshotSha = "";
            if (Snapshot.Parents.Count > 0)
            {
                string p = "";
                // Try to find next snapshot from history
                if (preferredDowntWay.Keys.Contains(snapshot.Sha))
                {
                    p = preferredDowntWay[snapshot.Sha];
                }
                // Try to fin next snapshot from the same line
                if (string.IsNullOrEmpty(p))
                {
                    p = Snapshot.Parents.FirstOrDefault(e => ShaDictionary[e].TreeOffset == Snapshot.TreeOffset);
                }
                // In other case take first snapshot
                if (string.IsNullOrEmpty(p))
                {
                    p = Snapshot.Parents.First();
                }

                ParentSnapshotSha = p;
            }
        }
Пример #4
0
        /// <summary>
        /// Select previous snapshot according to viewed history
        /// </summary>
        private SnapshotVM FindPreferredUpWay(SnapshotVM snapshot)
        {
            if (Snapshot.Childs.Count > 0)
            {
                string c = "";
                // Try to find next snapshot from history
                if (preferredUpWay.Keys.Contains(snapshot.Sha))
                {
                    c = preferredUpWay[snapshot.Sha];
                }
                // Try to fin next snapshot from the same line
                if (string.IsNullOrEmpty(c))
                {
                    c = Snapshot.Childs.FirstOrDefault(e => ShaDictionary[e].TreeOffset == Snapshot.TreeOffset);
                }
                // In other case take first snapshot
                if (string.IsNullOrEmpty(c))
                {
                    c = Snapshot.Childs.First();
                }

                return(ShaDictionary[c]);
            }

            return(null);
        }
Пример #5
0
        /// <summary>
        /// Find line of prev diff
        /// </summary>
        /// <param name="line">cursor line</param>
        /// <returns>true if diffs found</returns>
        public bool TryGetPrevtDiff(SnapshotVM currrent, SnapshotVM parent, int line, ref int nextLine)
        {
            if (parent == null)
            {
                return(false);
            }

            var parentLine = GetParentLineNumber(currrent, parent, line);

            var prevUpdatesLine = DiffsChanged[currrent.Index][parent.Index].Keys.LastOrDefault(e => e < line);
            var prevDeletedLine = DiffsDeleted[currrent.Index][parent.Index].Keys.LastOrDefault(e => e < parentLine);

            if (prevUpdatesLine == 0 && prevDeletedLine == 0)
            {
                return(false);
            }

            // TODO: Unit tests...
            var isChanges = true;

            if (prevUpdatesLine == 0)
            {
                isChanges = false;
            }
            if (prevDeletedLine != 0 && prevUpdatesLine < prevDeletedLine)
            {
                isChanges = false;
            }

            nextLine = isChanges ? prevUpdatesLine : GetParentLineNumber(parent, currrent, prevDeletedLine);

            return(true);
        }
Пример #6
0
        /// <summary>
        /// Return number of the same line in parent file
        /// </summary>
        public int GetParentLineNumber(SnapshotVM currrent, SnapshotVM parent, int line)
        {
            // return -1 if it's last commit
            if (parent == null)
            {
                return(-1);
            }
            // Check is child commit analysed
            if (!DiffsParentLineNum.Keys.Contains(currrent.Index))
            {
                Compare(currrent, parent);
            }
            // Check is parent commit analysed
            if (!DiffsParentLineNum[currrent.Index].Keys.Contains(parent.Index))
            {
                Compare(currrent, parent);
            }
            // Unknown
            if (!DiffsParentLineNum[currrent.Index][parent.Index].Keys.Contains(line))
            {
                return(-1);
            }

            return(DiffsParentLineNum[currrent.Index][parent.Index][line]);
        }
Пример #7
0
 /// <summary>
 /// Show information about commit
 /// </summary>
 /// <param name="commit">Selected commit</param>
 private void UpdateCommitDetails(SnapshotVM snapshot)
 {
     lblCommitSha.Text         = snapshot.Sha;
     lblCommitAuthor.Text      = snapshot.Author;
     lblCommitDate.Text        = snapshot.Date.ToString();
     lblCommitMessageText.Text = snapshot.Description;
     lblFilePath.Text          = snapshot.FilePath;
 }
Пример #8
0
 /// <summary>
 /// Get list of deletions
 /// </summary>
 public Dictionary <int, LineState> GetDeletions(SnapshotVM currrent, SnapshotVM parent)
 {
     if (!IsCompared(DiffsDeleted, currrent, parent))
     {
         return(null);
     }
     return(DiffsDeleted[currrent.Index][parent.Index]);
 }
Пример #9
0
 /// <summary>
 /// Answer is line was deleted
 /// </summary>
 public bool IsDeleted(SnapshotVM currrent, SnapshotVM parent, int line)
 {
     if (!IsCompared(DiffsDeleted, currrent, parent))
     {
         return(false);
     }
     return(DiffsDeleted[currrent.Index][parent.Index].Keys.Contains(line));
 }
Пример #10
0
        /// <summary>
        /// Compare changes between snapshots and add to cache
        /// </summary>
        private void Compare(SnapshotVM currrent, SnapshotVM parent)
        {
            if (parent == null)
            {
                return;
            }
            DiffsDeleted[currrent.Index] = new Dictionary <int, Dictionary <int, LineState> >();
            DiffsDeleted[currrent.Index][parent.Index] = new Dictionary <int, LineState>();
            DiffsChanged[currrent.Index] = new Dictionary <int, Dictionary <int, LineState> >();
            DiffsChanged[currrent.Index][parent.Index]       = new Dictionary <int, LineState>();
            DiffsParentLineNum[currrent.Index]               = new Dictionary <int, Dictionary <int, int> >();
            DiffsParentLineNum[currrent.Index][parent.Index] = new Dictionary <int, int>();

            var fileComparer = new InlineDiffBuilder(new Differ());
            var diff         = fileComparer.BuildDiffModel(parent.File, currrent.File);
            int updatedLines = -1;
            int deletedLines = -1;
            int parentLineIn = -1;

            foreach (var line in diff.Lines)
            {
                updatedLines++;
                deletedLines++;
                parentLineIn++;

                switch (line.Type)
                {
                case ChangeType.Modified:
                    DiffsChanged[currrent.Index][parent.Index][updatedLines] = LineState.Modified;
                    break;

                case ChangeType.Inserted:
                    DiffsChanged[currrent.Index][parent.Index][updatedLines] = LineState.Inserted;
                    deletedLines--;
                    parentLineIn--;
                    break;

                case ChangeType.Deleted:
                    DiffsDeleted[currrent.Index][parent.Index][deletedLines] = LineState.Deleted;
                    updatedLines--;
                    break;

                default:
                    break;
                }

                if (line.Type != ChangeType.Deleted)
                {
                    DiffsParentLineNum[currrent.Index][parent.Index][updatedLines] = parentLineIn;
                }
            }
        }
Пример #11
0
        public BridgeManager(NeoAPI api, ISwarm swarm, KeyPair owner_keys, UInt160 contract_hash, uint lastBlock)
        {
            this.neo_api    = api;
            this.swarm      = swarm;
            this.owner_keys = owner_keys;

            this.bluzelle_contract_hash = contract_hash;

            this.listenerVM = new SnapshotVM(this);

            // TODO: The last block should persistent between multiple sessions, in order to not miss any block
            this.lastBlock = lastBlock;
        }
Пример #12
0
        /// <summary>
        /// Return type of changes (if any)
        /// </summary>
        public LineState GetChangesType(SnapshotVM currrent, SnapshotVM parent, int line)
        {
            if (!IsCompared(DiffsChanged, currrent, parent))
            {
                return(LineState.Unknown);
            }

            // Check line mentions
            if (!DiffsChanged[currrent.Index][parent.Index].Keys.Contains(line))
            {
                return(LineState.Unchanged);
            }

            return(DiffsChanged[currrent.Index][parent.Index][line]);
        }
Пример #13
0
        /// <summary>
        /// Index of the first commit with provided line nuber
        /// </summary>
        public int GetLineBirth(SnapshotVM snapshot, int lineID)
        {
            var selectedLineId = snapshot.FileDetails.LineHistory[lineID];

            if (selectedLineId == 0)
            {
                return(0);
            }

            // TODO: Investigate how to avoid .ToList()
            // TODO: Investigate how to avoid All.ContainsKey(e) for preventing KeyNotFoundException
            var selectedLineCommits = CodeFile.LineBase[selectedLineId].ToList().Where(e => IdDictionary.ContainsKey(e));

            return(selectedLineCommits.Max(e => IdDictionary[e].Index));
        }
Пример #14
0
        public BridgeManager(NeoAPI api, ISwarm swarm, string ownerWIF, string contractPath)
        {
            this.neo_api    = api;
            this.swarm      = swarm;
            this.owner_keys = KeyPair.FromWIF(ownerWIF);

            if (File.Exists(contractPath))
            {
                this.contract_bytecode      = File.ReadAllBytes(contractPath);
                this.bluzelle_contract_hash = contract_bytecode.ToScriptHash();
            }
            else
            {
                throw new Exception($"Could not find contract avm at location {contractPath}");
            }

            this.listenerVM = new SnapshotVM(this);
        }
Пример #15
0
        /// <summary>
        /// Return true if commits in the same line in the same branch and nothing in between
        /// *
        /// |
        /// |
        /// *
        /// </summary>
        private bool IsCommitsInOneLine(SnapshotVM a, SnapshotVM p)
        {
            if (p.TreeOffset != a.TreeOffset)
            {
                return(false);
            }
            if (p.BranchLineId == a.BranchLineId)
            {
                return(true);
            }

            for (int i = a.Index + 1; i < p.Index; i++)
            {
                if (RenderedSnapshots[i].IsCommitVisible && RenderedSnapshots[i].TreeOffset == p.TreeOffset)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #16
0
        /// <summary>
        /// Get line background color based on line birth date (index)
        /// </summary>
        protected Brush GetLineBackgroundBrush(SnapshotVM snapshot, int linenum)
        {
            var lineSnapshotsNumber = host.Snapshots.Count - host.GetLineBirth(snapshot, linenum);

            if (lineSnapshotsNumber < 0)
            {
                lineSnapshotsNumber = 0;                                      // In case if host.Snapshot not yet updated with new commits.
            }
            var lineLifeTimePercent = (lineSnapshotsNumber * 100.0 / (host.Snapshots.Count - host.Snapshot.Index)) / 100;

            if (lineLifeTimePercent > 1)
            {
                lineLifeTimePercent = 1;
            }
            if (host.Snapshots.Count == 1)
            {
                lineLifeTimePercent = 0;
            }
            var byteColor = Convert.ToByte(255 - (5 + 249 * lineLifeTimePercent));

            return(new SolidColorBrush(Color.FromRgb(byteColor, 0xff, byteColor)));
        }
Пример #17
0
        /// <summary>
        /// Return true is we can draw simple down line
        ///        *
        ///        |
        ///        |
        ///        |
        ///        /
        /// *____ /
        /// </summary>
        private bool IsSimpleDownLine(SnapshotVM s, SnapshotVM p)
        {
            if (!s.IsLastInLine)
            {
                return(false);
            }
            if (p.TreeOffset == s.TreeOffset)
            {
                return(false);
            }

            var requiredEmptySpace = (p.Index - s.Index) * 0.6;

            if (RenderedSnapshots
                .Where(e => e.IsCommitVisible)
                .Where(e => s.Index < e.Index && e.Index < s.Index + requiredEmptySpace)
                .Any(e => e.TreeOffset == s.TreeOffset)
                )
            {
                return(false);
            }

            return(true);
        }
Пример #18
0
 /// <summary>
 /// Check is commits already compared
 /// </summary>
 private bool IsCompared(Dictionary <int, Dictionary <int, Dictionary <int, LineState> > > dictionary, SnapshotVM currrent, SnapshotVM parent)
 {
     // return false if it's last commit
     if (parent == null)
     {
         return(false);
     }
     // Check is child commit analysed
     if (!dictionary.Keys.Contains(currrent.Index))
     {
         Compare(currrent, parent);
     }
     // Check is parent commit analysed
     if (!dictionary[currrent.Index].Keys.Contains(parent.Index))
     {
         Compare(currrent, parent);
     }
     return(true);
 }
Пример #19
0
        public NeoEventMonitor0(NeoAPI api)
        {
            this._api = api;

            this._listenerVM = new SnapshotVM(this);
        }