Exemplo n.º 1
0
        /// <summary>
        /// A Smart Contract is an Execution Engine,
        /// firing methods, counting the cost, incrementing/decrementing funds  and imposing a
        /// throttle on execution against available "funds"; and,
        /// ultimately writing data to the blockchain
        /// </summary>
        public virtual void Execute(Int64 GasLimit)
        {
            long loopcount = 0;

            foreach (Tuple <DelegateMethod, string, long, string, long> tup in delegates)
            {
                try
                {
                    loopcount++;
                    ulong start, end;
                    start = ThreadCycleCounter.ThreadCycles();
                    tup.Item1.Invoke(tup.Item3);
                    end = ThreadCycleCounter.ThreadCycles();
                    ulong cycles = end - start;

                    if ((cycles > 0) && (long)cycles > tup.Item5) //Note: tup.Item5 = GasLimit for This Delegate
                    {
                        Print(ConsoleColor.Red, String.Format("Gas Limit Exceeded for Delegate#{0} - GasSpent: {1}; GasLimit: {2}",
                                                              loopcount, cycles, tup.Item5));
                    }

                    Console.WriteLine(String.Format("Executed Delegate#{0} - GasSpent: {1}; GasLimit: {2}",
                                                    loopcount, cycles, tup.Item5));
                    Console.WriteLine("-----------------------------");
                }
                catch (Exception)
                {
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public SmartContract()
        {
            //initialize threadcycle timer
            for (int i = 0; i < 5; i++)
            {
                ThreadCycleCounter.ThreadCycles();
            }
            //delegates.Add(Tuple.Create(new DelegateMethod(DoShortLoop),"NumLoops", (long)10, "GasLimit", (long)100));

            //delegates.Add(Tuple.Create(new DelegateMethod(DoComplexLoop), "NumLoops", (long)100, "GasLimit", (long)1000));
        }