コード例 #1
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);
            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);
        }
コード例 #2
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;
     }
 }
コード例 #3
0
        public static ApplicationEngine Run(byte[] script, IScriptContainer container = null)
        {
            DataCache <UInt160, AccountState>   accounts   = blockchain.GetTable <UInt160, AccountState>();
            DataCache <ECPoint, ValidatorState> validators = blockchain.GetTable <ECPoint, ValidatorState>();
            DataCache <UInt256, AssetState>     assets     = blockchain.GetTable <UInt256, AssetState>();
            DataCache <UInt160, ContractState>  contracts  = blockchain.GetTable <UInt160, ContractState>();
            DataCache <StorageKey, StorageItem> storages   = blockchain.GetTable <StorageKey, StorageItem>();
            CachedScriptTable script_table = new CachedScriptTable(contracts);
            StateMachine      service      = new StateMachine(accounts, validators, assets, contracts, storages);
            ApplicationEngine engine       = new ApplicationEngine(TriggerType.Application, container, script_table, service, Fixed8.Zero, true);

            engine.LoadScript(script, false);
            return(engine.Execute() ? engine : null);
        }