示例#1
0
        public static bool Transfer(UInt160 from, UInt160 to, BigInteger amount, object data)
        {
            if (!ValidateAddress(from) || !ValidateAddress(to))
            {
                throw new Exception("The parameters from and to SHOULD be 20-byte non-zero addresses.");
            }
            if (amount <= 0)
            {
                throw new Exception("The parameter amount MUST be greater than 0.");
            }
            if (!Runtime.CheckWitness(from) && !from.Equals(ExecutionEngine.CallingScriptHash))
            {
                throw new Exception("No authorization.");
            }
            if (AssetStorage.Get(from) < amount)
            {
                throw new Exception("Insufficient balance.");
            }
            if (from == to)
            {
                return(true);
            }

            AssetStorage.Reduce(from, amount);
            AssetStorage.Increase(to, amount);

            OnTransfer(from, to, amount);

            // Validate payable
            if (IsDeployed(to))
            {
                Contract.Call(to, "onPayment", new object[] { from, amount, data });
            }
            return(true);
        }
示例#2
0
        private static void Mint(BigInteger amount)
        {
            var totalSupply = TotalSupplyStorage.Get();

            if (totalSupply <= 0)
            {
                throw new Exception("Contract not deployed.");
            }

            var avaliable_supply = MaxSupply - totalSupply;

            if (amount <= 0)
            {
                throw new Exception("Amount cannot be zero.");
            }
            if (amount > avaliable_supply)
            {
                throw new Exception("Insufficient supply for mint tokens.");
            }

            Transaction tx = (Transaction)ExecutionEngine.ScriptContainer;

            AssetStorage.Increase(tx.Sender, amount);
            TotalSupplyStorage.Increase(amount);

            OnTransfer(null, tx.Sender, amount);
        }
示例#3
0
 public static void OnPayment(UInt160 from, BigInteger amount, object data)
 {
     if (AssetStorage.GetPaymentStatus())
     {
         if (ExecutionEngine.CallingScriptHash == NEO.Hash)
         {
             Mint(amount * TokensPerNEO);
         }
         else if (ExecutionEngine.CallingScriptHash == GAS.Hash)
         {
             if (from != null)
             {
                 Mint(amount * TokensPerGAS);
             }
         }
         else
         {
             throw new Exception("Wrong calling script hash");
         }
     }
     else
     {
         throw new Exception("Payment is disable on this contract!");
     }
 }
示例#4
0
 public static void DisablePayment()
 {
     if (!IsOwner())
     {
         throw new Exception("No authorization.");
     }
     AssetStorage.Disable();
 }
示例#5
0
 public static BigInteger BalanceOf(UInt160 account)
 {
     if (!ValidateAddress(account))
     {
         throw new Exception("The parameters account SHOULD be a 20-byte non-zero address.");
     }
     return(AssetStorage.Get(account));
 }
示例#6
0
        public static void _deploy(bool update)
        {
            if (update)
            {
                return;
            }
            if (TotalSupplyStorage.Get() > 0)
            {
                throw new Exception("Contract has been deployed.");
            }

            TotalSupplyStorage.Increase(InitialSupply);
            AssetStorage.Increase(Owner, InitialSupply);

            OnTransfer(null, Owner, InitialSupply);
        }