示例#1
0
        public ApplicationEngine(TriggerType trigger, IScriptContainer container, IScriptTable table, InteropService service, Fixed8 gas, bool testMode = false)
            : base(container, Cryptography.Crypto.Default, table, service)
        {
            this.gas_amount = gas_free + gas.GetData();
            this.testMode   = testMode;
            this.Trigger    = trigger;
            var scriptTable = table as CachedScriptTable;

            if (scriptTable != null)
            {
                this.script_table = scriptTable;
            }
        }
示例#2
0
        public static ApplicationEngine Run(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);

            using (StateMachine service = new StateMachine(persisting_block, accounts, assets, contracts, storages))
            {
                ApplicationEngine engine = new ApplicationEngine(TriggerType.Application, container, script_table, service, Fixed8.Zero, true);
                engine.LoadScript(script, false);
                engine.Execute();
                return(engine);
            }
        }
    }