Esempio n. 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);
        }
Esempio n. 2
0
 public void InlineTxnBackToSelf(int recurseCount)
 {
     if (recurseCount > 0)
     {
         Api.SendInline(Api.GetContractAddress(), "InlineTxnBackToSelf", recurseCount - 1);
     }
 }
Esempio n. 3
0
 private Address GetAddress()
 {
     return(Address.FromRawBytes(
                Hash.FromTwoHashes(
                    Api.GetChainId(),
                    Hash.FromMessage(
                        new UInt64Value()
     {
         Value = SerialNumber
     })
                    ).ToByteArray()
                ));
 }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
 public void SleepMilliseconds(int milliSeconds)
 {
     // Used to test timeout
     Api.Sleep(milliSeconds);
 }