Beispiel #1
0
        public bool Transfer(Address from, Address to, UInt64Value qty)
        {
            Console.WriteLine("From: " + from.DumpHex());
            Console.WriteLine("To: " + to.DumpHex());

            // This is for testing batched transaction sequence
            TransactionStartTimes.SetValue(Api.GetTransaction().GetHash(), Now());
            var fromBal = Balances.GetValue(from);

            Console.WriteLine("Old From Balance: " + fromBal);

            var toBal = Balances.GetValue(to);

            Console.WriteLine("Old To Balance: " + toBal);

            Console.WriteLine("Assertion: " + (fromBal >= qty.Value));
            Api.Assert(fromBal >= qty.Value, $"Insufficient balance, {qty.Value} is required but there is only {fromBal}.");

            var newFromBal = fromBal - qty.Value;
            var newToBal   = toBal + qty.Value;

            Console.WriteLine("New From Balance: " + newFromBal);
            Console.WriteLine("New To Balance: " + newToBal);
            Balances.SetValue(from, newFromBal);
            Balances.SetValue(to, newToBal);

            // This is for testing batched transaction sequence
            TransactionEndTimes.SetValue(Api.GetTransaction().GetHash(), Now());
            return(true);
        }
Beispiel #2
0
        public bool Transfer(Address from, Address to, ulong qty)
        {
            var fromBal = Balances.GetValue(from);
            // Console.WriteLine("from pass");

            var toBal = Balances.GetValue(to);
            // Console.WriteLine("to pass");
            var newFromBal = fromBal - qty;

            Api.Assert(fromBal > qty, $"Insufficient balance, {qty} is required but there is only {fromBal}.");

            var newToBal = toBal + qty;

            Balances.SetValue(from, newFromBal);
            // Console.WriteLine("set from pass");

            Balances.SetValue(to, newToBal);
            // Console.WriteLine("set to pass");
            // Console.WriteLine($"After transfer: {from.DumpHex()} - {newFromBal} || {to.DumpHex()} - {newToBal}");
            return(true);
        }