Exemplo n.º 1
0
        public Snapshot(NEP5 token, uint startBlock, uint endBlock = 0)
        {
            var api = token.api;

            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 == token.scriptHash)
                            {
                                MergeTransaction(api, tx);
                                snapCount++;
                                break;
                            }
                        }

                        break;
                    }

                    case TransactionType.InvocationTransaction:
                    {
                        List <AVMInstruction> ops;
                        try
                        {
                            ops = NeoTools.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 scriptHash = new UInt160(op.data);

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

                        break;
                    }
                    }
                }

                if (snapCount > 0)
                {
                    blocks[block.Hash] = block;
                }
            }
        }
Exemplo n.º 2
0
        public static Transaction Deploy(NEP5 token, KeyPair owner_key)
        {
            var response = token.api.CallContract(owner_key, token.scriptHash, "deploy", new object[] { });

            return(response);
        }
Exemplo n.º 3
0
 public Storage GetStorage(NEP5 token)
 {
     return(GetStorage(token.scriptHash));
 }
Exemplo n.º 4
0
 public Snapshot(NEP5 token, uint startBlock, uint endBlock = 0) : this(token.ScriptHash, token.api, startBlock, endBlock)
 {
 }