private TriggerPatterns CreatePattern(ETriggerType triggerType) { (string specialIntiBodyFileName, string specialMainBodyFileName) = GetSpeciaBodyPartlFileNames(triggerType); string specialInitBody = _reader.ReadTriggerPart(specialIntiBodyFileName); string specialMainBody = _reader.ReadTriggerPart(specialMainBodyFileName); TriggerPatterns triggerPattern = new TriggerPatterns(triggerType.GetName(), MainBody, specialMainBody, specialInitBody); return(triggerPattern); }
/// <summary> /// Constructor /// </summary> /// <param name="e">Arguments</param> protected IExecutionEngine(ExecutionEngineArgs e) { if (e == null) { return; } InteropService = e.InteropService; ScriptTable = e.ScriptTable; MessageProvider = e.MessageProvider; Trigger = e.Trigger; Logger = e.Logger; }
public StateMachine( Block persistingBlock, DataCache <UInt160, Account> accounts, DataCache <UInt256, Asset> assets, DataCache <UInt160, Contract> contracts, DataCache <StorageKey, StorageValue> storages, InteropService interopService, IBlockchainContext blockchainContext, IBlockRepository blockRepository, ITransactionRepository transactionRepository, ETriggerType trigger) : base(accounts, assets, contracts, storages, interopService, blockchainContext, blockRepository, transactionRepository, trigger) { _persistingBlock = persistingBlock; _blockchainContext = blockchainContext; _accounts = accounts?.CreateSnapshot(); _assets = assets?.CreateSnapshot(); _contracts = contracts?.CreateSnapshot(); _storages = storages?.CreateSnapshot(); // Standard Library interopService.Register("System.Contract.GetStorageContext", Contract_GetStorageContext); interopService.Register("System.Contract.Destroy", Contract_Destroy); interopService.RegisterStackMethod("System.Storage.Put", Storage_Put); interopService.RegisterStackMethod("System.Storage.Delete", Storage_Delete); // Neo Specified interopService.Register("Neo.Asset.Create", Asset_Create); interopService.RegisterStackMethod("Neo.Asset.Renew", Asset_Renew); interopService.Register("Neo.Contract.Create", Contract_Create); interopService.Register("Neo.Contract.Migrate", Contract_Migrate); #region Old APIs interopService.Register("AntShares.Asset.Create", Asset_Create); interopService.RegisterStackMethod("AntShares.Asset.Renew", Asset_Renew); interopService.Register("AntShares.Contract.Create", Contract_Create); interopService.Register("AntShares.Contract.Migrate", Contract_Migrate); interopService.Register("Neo.Contract.GetStorageContext", Contract_GetStorageContext); interopService.Register("AntShares.Contract.GetStorageContext", Contract_GetStorageContext); interopService.Register("Neo.Contract.Destroy", Contract_Destroy); interopService.Register("AntShares.Contract.Destroy", Contract_Destroy); interopService.RegisterStackMethod("Neo.Storage.Put", Storage_Put); interopService.RegisterStackMethod("AntShares.Storage.Put", Storage_Put); interopService.RegisterStackMethod("Neo.Storage.Delete", Storage_Delete); interopService.RegisterStackMethod("AntShares.Storage.Delete", Storage_Delete); #endregion }
public static ITrigger CreateTrigger(ETriggerType type, string param) { switch (type) { case ETriggerType.CLICK_WIDGET: case ETriggerType.CLICK_MASK: return(new GuideTriggerClick(type, param)); case ETriggerType.CLICK_SYS_BTN: return(new ClickSysBtn(type, param)); case ETriggerType.CLICK_IN_BAG: return(new GuideTriggerClickInBag(type, param)); default: return(null); } }
public void TestInvoke(UInt160 contractHash, ETriggerType trigger, string operation = null, [PromptCommandParameterBody] object[] parameters = null) { if (_scriptTable.GetScript(contractHash.ToArray(), false) == null) { throw new ArgumentNullException("Contract not found"); } var args = new ExecutionEngineArgs { ScriptTable = _scriptTable, Logger = new ExecutionEngineLogger(ELogVerbosity.StepInto), Trigger = trigger }; var log = new StringBuilder(); args.Logger.OnStepInto += context => { log.AppendLine(context.NextInstruction.ToString()); }; using (var script = new ScriptBuilder()) using (var vm = _vmFactory.Create(args)) { script.EmitMainPush(operation, parameters); script.EmitAppCall(contractHash.ToArray()); vm.LoadScript(script); var ret = vm.Execute(); var result = new { vm.State, Result = vm.ResultStack, vm.ConsumedGas }; _consoleHandler.WriteObject(result, PromptOutputStyle.json); } //_logger.LogDebug("Execution opcodes:" + Environment.NewLine + log.ToString()); }
private (string SpecialInitBody, string SpecialMainBody) GetSpeciaBodyPartlFileNames(ETriggerType triggerType) { if (triggerType == ETriggerType.Insert) { return(FileNames.InsertSpecialInitBodyFileName, FileNames.InsertSpecialMainBodyFileName); } else if (triggerType == ETriggerType.Update) { return(FileNames.UpdateSpecialInitBodyFileName, FileNames.UpdateSpecialMainBodyFileName); } else if (triggerType == ETriggerType.Delete) { return(FileNames.DeleteSpecialInitBodyFileName, FileNames.DeleteSpecialMainBodyFileName); } else { throw new ArgumentException(nameof(triggerType)); } }
/// <summary> /// 通过触发条件和参数进行初始化 /// </summary> /// <param name="type"></param> /// <param name="param"></param> public ITrigger(ETriggerType type, string param) { TriggerType = type; Finished = false; Init(param); }
public GuideTriggerClickInBag(ETriggerType type, string param) : base(type, param) { }
public ClickSysBtn(ETriggerType type, string param) : base(type, param) { }
public static string GetName(this ETriggerType value) { return(System.Enum.GetName(typeof(ETriggerType), value)); }
public StateReader( DataCache <UInt160, Account> accounts, DataCache <UInt256, Asset> assets, DataCache <UInt160, Contract> contracts, DataCache <StorageKey, StorageValue> storages, InteropService interopService, IBlockchainContext blockchainContext, IBlockRepository blockRepository, ITransactionRepository transactionRepository, ETriggerType trigger) { Accounts = accounts; Assets = assets; Contracts = contracts; Storages = storages; _blockchainContext = blockchainContext; _blockRepository = blockRepository; _transactionRepository = transactionRepository; _trigger = trigger; _interopService = interopService; //Standard Library interopService.RegisterStackMethod("System.Runtime.GetTrigger", Runtime_GetTrigger); interopService.Register("System.Runtime.CheckWitness", Runtime_CheckWitness); interopService.Register("System.Runtime.Notify", Runtime_Notify); interopService.Register("System.Runtime.Log", Runtime_Log); interopService.RegisterStackMethod("System.Runtime.GetTime", Runtime_GetTime); interopService.RegisterStackMethod("System.Blockchain.GetHeight", Blockchain_GetHeight); interopService.RegisterStackMethod("System.Blockchain.GetHeader", Blockchain_GetHeader); interopService.RegisterStackMethod("System.Blockchain.GetBlock", Blockchain_GetBlock); interopService.RegisterStackMethod("System.Blockchain.GetTransaction", Blockchain_GetTransaction); interopService.RegisterStackMethod("System.Blockchain.GetTransactionHeight", Blockchain_GetTransactionHeight); interopService.RegisterStackMethod("System.Blockchain.GetContract", Blockchain_GetContract); interopService.RegisterStackMethod("System.Header.GetIndex", Header_GetIndex); interopService.RegisterStackMethod("System.Header.GetHash", Header_GetHash); interopService.RegisterStackMethod("System.Header.GetPrevHash", Header_GetPrevHash); interopService.RegisterStackMethod("System.Header.GetTimestamp", Header_GetTimestamp); interopService.RegisterStackMethod("System.Block.GetTransactionCount", Block_GetTransactionCount); interopService.RegisterStackMethod("System.Block.GetTransactions", Block_GetTransactions); interopService.RegisterStackMethod("System.Block.GetTransaction", Block_GetTransaction); interopService.RegisterStackMethod("System.Transaction.GetHash", Transaction_GetHash); interopService.Register("System.Storage.GetContext", Storage_GetContext); interopService.Register("System.Storage.GetReadOnlyContext", Storage_GetReadOnlyContext); interopService.RegisterStackMethod("System.Storage.Get", Storage_Get); interopService.RegisterStackMethod("System.StorageContext.AsReadOnly", StorageContext_AsReadOnly); //Neo Specified interopService.RegisterStackMethod("Neo.Blockchain.GetAccount", Blockchain_GetAccount); interopService.RegisterStackMethod("Neo.Blockchain.GetValidators", Blockchain_GetValidators); interopService.RegisterStackMethod("Neo.Blockchain.GetAsset", Blockchain_GetAsset); interopService.RegisterStackMethod("Neo.Header.GetVersion", Header_GetVersion); interopService.RegisterStackMethod("Neo.Header.GetMerkleRoot", Header_GetMerkleRoot); interopService.RegisterStackMethod("Neo.Header.GetConsensusData", Header_GetConsensusData); interopService.RegisterStackMethod("Neo.Header.GetNextConsensus", Header_GetNextConsensus); interopService.RegisterStackMethod("Neo.Transaction.GetType", Transaction_GetType); interopService.RegisterStackMethod("Neo.Transaction.GetAttributes", Transaction_GetAttributes); interopService.RegisterStackMethod("Neo.Transaction.GetInputs", Transaction_GetInputs); interopService.RegisterStackMethod("Neo.Transaction.GetOutputs", Transaction_GetOutputs); interopService.RegisterStackMethod("Neo.Transaction.GetReferences", Transaction_GetReferences); interopService.RegisterStackMethod("Neo.Transaction.GetUnspentCoins", Transaction_GetUnspentCoins); interopService.RegisterStackMethod("Neo.InvocationTransaction.GetScript", InvocationTransaction_GetScript); interopService.RegisterStackMethod("Neo.Attribute.GetUsage", Attribute_GetUsage); interopService.RegisterStackMethod("Neo.Attribute.GetData", Attribute_GetData); interopService.RegisterStackMethod("Neo.Input.GetHash", Input_GetHash); interopService.RegisterStackMethod("Neo.Input.GetIndex", Input_GetIndex); interopService.RegisterStackMethod("Neo.Output.GetAssetId", Output_GetAssetId); interopService.RegisterStackMethod("Neo.Output.GetValue", Output_GetValue); interopService.RegisterStackMethod("Neo.Output.GetScriptHash", Output_GetScriptHash); interopService.RegisterStackMethod("Neo.Account.GetScriptHash", Account_GetScriptHash); interopService.RegisterStackMethod("Neo.Account.GetVotes", Account_GetVotes); interopService.RegisterStackMethod("Neo.Account.GetBalance", Account_GetBalance); interopService.RegisterStackMethod("Neo.Asset.GetAssetId", Asset_GetAssetId); interopService.RegisterStackMethod("Neo.Asset.GetAssetType", Asset_GetAssetType); interopService.RegisterStackMethod("Neo.Asset.GetAmount", Asset_GetAmount); interopService.RegisterStackMethod("Neo.Asset.GetAvailable", Asset_GetAvailable); interopService.RegisterStackMethod("Neo.Asset.GetPrecision", Asset_GetPrecision); interopService.RegisterStackMethod("Neo.Asset.GetOwner", Asset_GetOwner); interopService.RegisterStackMethod("Neo.Asset.GetAdmin", Asset_GetAdmin); interopService.RegisterStackMethod("Neo.Asset.GetIssuer", Asset_GetIssuer); interopService.RegisterStackMethod("Neo.Contract.GetScript", Contract_GetScript); interopService.RegisterStackMethod("Neo.Contract.IsPayable", Contract_IsPayable); interopService.RegisterStackMethod("Neo.Storage.Find", Storage_Find); #region Old APIs interopService.RegisterStackMethod("Neo.Runtime.GetTrigger", Runtime_GetTrigger); interopService.Register("Neo.Runtime.CheckWitness", Runtime_CheckWitness); interopService.Register("AntShares.Runtime.CheckWitness", Runtime_CheckWitness); interopService.Register("Neo.Runtime.Notify", Runtime_Notify); interopService.Register("AntShares.Runtime.Notify", Runtime_Notify); interopService.Register("Neo.Runtime.Log", Runtime_Log); interopService.Register("AntShares.Runtime.Log", Runtime_Log); interopService.RegisterStackMethod("Neo.Runtime.GetTime", Runtime_GetTime); interopService.RegisterStackMethod("Neo.Blockchain.GetHeight", Blockchain_GetHeight); interopService.RegisterStackMethod("AntShares.Blockchain.GetHeight", Blockchain_GetHeight); interopService.RegisterStackMethod("Neo.Blockchain.GetHeader", Blockchain_GetHeader); interopService.RegisterStackMethod("AntShares.Blockchain.GetHeader", Blockchain_GetHeader); interopService.RegisterStackMethod("Neo.Blockchain.GetBlock", Blockchain_GetBlock); interopService.RegisterStackMethod("AntShares.Blockchain.GetBlock", Blockchain_GetBlock); interopService.RegisterStackMethod("Neo.Blockchain.GetTransaction", Blockchain_GetTransaction); interopService.RegisterStackMethod("AntShares.Blockchain.GetTransaction", Blockchain_GetTransaction); interopService.RegisterStackMethod("Neo.Blockchain.GetTransactionHeight", Blockchain_GetTransactionHeight); interopService.RegisterStackMethod("AntShares.Blockchain.GetAccount", Blockchain_GetAccount); interopService.RegisterStackMethod("AntShares.Blockchain.GetValidators", Blockchain_GetValidators); interopService.RegisterStackMethod("AntShares.Blockchain.GetAsset", Blockchain_GetAsset); interopService.RegisterStackMethod("Neo.Blockchain.GetContract", Blockchain_GetContract); interopService.RegisterStackMethod("AntShares.Blockchain.GetContract", Blockchain_GetContract); interopService.RegisterStackMethod("Neo.Header.GetIndex", Header_GetIndex); interopService.RegisterStackMethod("Neo.Header.GetHash", Header_GetHash); interopService.RegisterStackMethod("AntShares.Header.GetHash", Header_GetHash); interopService.RegisterStackMethod("AntShares.Header.GetVersion", Header_GetVersion); interopService.RegisterStackMethod("Neo.Header.GetPrevHash", Header_GetPrevHash); interopService.RegisterStackMethod("AntShares.Header.GetPrevHash", Header_GetPrevHash); interopService.RegisterStackMethod("AntShares.Header.GetMerkleRoot", Header_GetMerkleRoot); interopService.RegisterStackMethod("Neo.Header.GetTimestamp", Header_GetTimestamp); interopService.RegisterStackMethod("AntShares.Header.GetTimestamp", Header_GetTimestamp); interopService.RegisterStackMethod("AntShares.Header.GetConsensusData", Header_GetConsensusData); interopService.RegisterStackMethod("AntShares.Header.GetNextConsensus", Header_GetNextConsensus); interopService.RegisterStackMethod("Neo.Block.GetTransactionCount", Block_GetTransactionCount); interopService.RegisterStackMethod("AntShares.Block.GetTransactionCount", Block_GetTransactionCount); interopService.RegisterStackMethod("Neo.Block.GetTransactions", Block_GetTransactions); interopService.RegisterStackMethod("AntShares.Block.GetTransactions", Block_GetTransactions); interopService.RegisterStackMethod("Neo.Block.GetTransaction", Block_GetTransaction); interopService.RegisterStackMethod("AntShares.Block.GetTransaction", Block_GetTransaction); interopService.RegisterStackMethod("Neo.Transaction.GetHash", Transaction_GetHash); interopService.RegisterStackMethod("AntShares.Transaction.GetHash", Transaction_GetHash); interopService.RegisterStackMethod("AntShares.Transaction.GetType", Transaction_GetType); interopService.RegisterStackMethod("AntShares.Transaction.GetAttributes", Transaction_GetAttributes); interopService.RegisterStackMethod("AntShares.Transaction.GetInputs", Transaction_GetInputs); interopService.RegisterStackMethod("AntShares.Transaction.GetOutputs", Transaction_GetOutputs); interopService.RegisterStackMethod("AntShares.Transaction.GetReferences", Transaction_GetReferences); interopService.RegisterStackMethod("AntShares.Attribute.GetUsage", Attribute_GetUsage); interopService.RegisterStackMethod("AntShares.Attribute.GetData", Attribute_GetData); interopService.RegisterStackMethod("AntShares.Input.GetHash", Input_GetHash); interopService.RegisterStackMethod("AntShares.Input.GetIndex", Input_GetIndex); interopService.RegisterStackMethod("AntShares.Output.GetAssetId", Output_GetAssetId); interopService.RegisterStackMethod("AntShares.Output.GetValue", Output_GetValue); interopService.RegisterStackMethod("AntShares.Output.GetScriptHash", Output_GetScriptHash); interopService.RegisterStackMethod("AntShares.Account.GetScriptHash", Account_GetScriptHash); interopService.RegisterStackMethod("AntShares.Account.GetVotes", Account_GetVotes); interopService.RegisterStackMethod("AntShares.Account.GetBalance", Account_GetBalance); interopService.RegisterStackMethod("AntShares.Asset.GetAssetId", Asset_GetAssetId); interopService.RegisterStackMethod("AntShares.Asset.GetAssetType", Asset_GetAssetType); interopService.RegisterStackMethod("AntShares.Asset.GetAmount", Asset_GetAmount); interopService.RegisterStackMethod("AntShares.Asset.GetAvailable", Asset_GetAvailable); interopService.RegisterStackMethod("AntShares.Asset.GetPrecision", Asset_GetPrecision); interopService.RegisterStackMethod("AntShares.Asset.GetOwner", Asset_GetOwner); interopService.RegisterStackMethod("AntShares.Asset.GetAdmin", Asset_GetAdmin); interopService.RegisterStackMethod("AntShares.Asset.GetIssuer", Asset_GetIssuer); interopService.RegisterStackMethod("AntShares.Contract.GetScript", Contract_GetScript); interopService.Register("Neo.Storage.GetContext", Storage_GetContext); interopService.Register("AntShares.Storage.GetContext", Storage_GetContext); interopService.Register("Neo.Storage.GetReadOnlyContext", Storage_GetReadOnlyContext); interopService.RegisterStackMethod("Neo.Storage.Get", Storage_Get); interopService.RegisterStackMethod("AntShares.Storage.Get", Storage_Get); interopService.RegisterStackMethod("Neo.StorageContext.AsReadOnly", StorageContext_AsReadOnly); #endregion }