Пример #1
0
        public static ApplicationEngine RunWithDebug(byte[] script, IScriptContainer container = null, Block persisting_block = null)
        {
            if (persisting_block == null)
            {
                persisting_block = new Block
                {
                    Version       = 0,
                    PrevHash      = Blockchain.Default.CurrentBlockHash,
                    MerkleRoot    = new UInt256(),
                    Timestamp     = Blockchain.Default.GetHeader(Blockchain.Default.Height).Timestamp + Blockchain.SecondsPerBlock,
                    Index         = Blockchain.Default.Height + 1,
                    ConsensusData = 0,
                    NextConsensus = Blockchain.Default.GetHeader(Blockchain.Default.Height).NextConsensus,
                    Script        = new Witness
                    {
                        InvocationScript   = new byte[0],
                        VerificationScript = new byte[0]
                    },
                    Transactions = new Transaction[0]
                }
            }
            ;
            DataCache <UInt160, AccountState>   accounts  = Blockchain.Default.GetStates <UInt160, AccountState>();
            DataCache <UInt256, AssetState>     assets    = Blockchain.Default.GetStates <UInt256, AssetState>();
            DataCache <UInt160, ContractState>  contracts = Blockchain.Default.GetStates <UInt160, ContractState>();
            DataCache <StorageKey, StorageItem> storages  = Blockchain.Default.GetStates <StorageKey, StorageItem>();
            CachedScriptTable script_table = new CachedScriptTable(contracts);
            StateMachine      service      = new StateMachine(persisting_block, accounts, assets, contracts, storages);
            ApplicationEngine engine       = new ApplicationEngine(TriggerType.Application, container, script_table, service, Fixed8.Zero, true);

            engine.BeginDebug();
            engine.LoadScript(script, false);
            engine.Execute();
            return(engine);
        }
Пример #2
0
        public static ApplicationEngine Run(byte[] script, Snapshot snapshot,
                                            IScriptContainer container = null, Block persistingBlock = null, bool testMode = false, Fixed8 extraGAS = default(Fixed8), bool beginDebug = false)
        {
            snapshot.PersistingBlock = persistingBlock ?? snapshot.PersistingBlock ?? new Block
            {
                Version       = 0,
                PrevHash      = snapshot.CurrentBlockHash,
                MerkleRoot    = new UInt256(),
                Timestamp     = snapshot.Blocks[snapshot.CurrentBlockHash].TrimmedBlock.Timestamp + Blockchain.SecondsPerBlock,
                Index         = snapshot.Height + 1,
                ConsensusData = 0,
                NextConsensus = snapshot.Blocks[snapshot.CurrentBlockHash].TrimmedBlock.NextConsensus,
                Witness       = new Witness
                {
                    InvocationScript   = new byte[0],
                    VerificationScript = new byte[0]
                },
                Transactions = new Transaction[0]
            };
            ApplicationEngine engine = new ApplicationEngine(TriggerType.Application, container, snapshot, extraGAS, testMode);

            if (beginDebug)
            {
                engine.BeginDebug();
            }
            engine.LogScript(script);
            engine.LoadScript(script);
            engine.Execute();
            return(engine);
        }