private BigInteger GetTaskTimeFromBlock(TaskFrequencyMode mode, Block block) { switch (mode) { case TaskFrequencyMode.Blocks: { return(block.Height); } case TaskFrequencyMode.Time: { return(block.Timestamp.Value); } default: throw new ChainException("Unknown task mode: " + mode); } }
public ITask StartTask(StorageContext storage, Address from, string contractName, ContractMethod method, int frequency, TaskFrequencyMode mode, BigInteger gasLimit) { if (!IsContractDeployed(storage, contractName)) { return(null); } var taskID = GenerateUID(storage); var task = new ChainTask(taskID, from, contractName, method.name, (uint)frequency, mode, gasLimit, true); var taskKey = GetTaskKey(taskID, "task_info"); var taskBytes = task.ToByteArray(); this.Storage.Put(taskKey, taskBytes); var taskList = new StorageList(TaskListTag, this.Storage); taskList.Add <BigInteger>(taskID); return(task); }
public ChainTask(BigInteger ID, Address payer, string contractName, string method, uint frequency, uint delay, TaskFrequencyMode mode, BigInteger gasLimit, BigInteger height, bool state) { this.ID = ID; this.Owner = payer; this.ContextName = contractName; this.Method = method; this.Frequency = frequency; this.Delay = delay; this.Mode = mode; this.GasLimit = gasLimit; this.Height = height; this.State = state; }