Exemple #1
0
        public static uint FindBlock(CronAPI api, DateTime date)
        {
            uint min = 0;
            var  max = api.GetBlockHeight();

            var timestamp = date.ToTimestamp();

            return(FindBlock(api, timestamp, min, max));
        }
Exemple #2
0
        public void SyncWithNode(CronAPI api)
        {
            var max = api.GetBlockHeight();

            var min = (uint)_blocks.Count;

            for (uint i = min; i <= max; i++)
            {
                var block = api.GetBlock(i);
                AddBlock(block);
            }
        }
Exemple #3
0
 public BlockIterator(CronAPI api)
 {
     this.currentBlock       = api.GetBlockHeight();
     this.currentTransaction = 0;
 }
Exemple #4
0
        public Snapshot(UInt160 scriptHash, CronAPI api, uint startBlock, uint endBlock = 0)
        {
            if (endBlock == 0)
            {
                endBlock = api.GetBlockHeight();
            }

            if (endBlock < startBlock)
            {
                throw new ArgumentException("End block cannot be smaller than start block");
            }

            for (uint height = startBlock; height <= endBlock; height++)
            {
                var block = api.GetBlock(height);

                var snapCount = 0;

                foreach (var tx in block.transactions)
                {
                    switch (tx.type)
                    {
                    case TransactionType.ContractTransaction:
                    {
                        foreach (var output in tx.outputs)
                        {
                            if (output.scriptHash == scriptHash)
                            {
                                MergeTransaction(api, tx);
                                snapCount++;
                                break;
                            }
                        }

                        break;
                    }

                    case TransactionType.InvocationTransaction:
                    {
                        List <AVMInstruction> ops;
                        try
                        {
                            ops = CronTools.Disassemble(tx.script);
                        }
                        catch
                        {
                            continue;
                        }

                        for (int i = 0; i < ops.Count; i++)
                        {
                            var op = ops[i];

                            if (op.opcode == OpCode.APPCALL && op.data != null && op.data.Length == 20)
                            {
                                var otherScriptHash = new UInt160(op.data);

                                if (otherScriptHash == scriptHash)
                                {
                                    MergeTransaction(api, tx);
                                    snapCount++;
                                    break;
                                }
                            }
                        }

                        break;
                    }
                    }
                }

                if (snapCount > 0)
                {
                    blocks[block.Hash] = block;
                }
            }
        }