コード例 #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);
        }
コード例 #2
0
        public bool Transfer(Address from, Address to, ulong qty)
        {
            // This is for testing batched transaction sequence
            TransactionStartTimes.SetValue(Api.GetTransaction().GetHash(), Now());

            var fromBal = Balances.GetValue(from);

            var toBal = Balances.GetValue(to);

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

            Balances.SetValue(from, newFromBal);
            Balances.SetValue(to, newToBal);

            // This is for testing batched transaction sequence
            TransactionEndTimes.SetValue(Api.GetTransaction().GetHash(), Now());
            return(true);
        }