Пример #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;
     if (table is CachedScriptTable)
     {
         this.script_table = (CachedScriptTable)table;
     }
 }
Пример #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,
                    ConsensusAddress = Blockchain.Default.GetHeader(Blockchain.Default.Height).ConsensusAddress,
                    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);
            }
        }
    }