Esempio n. 1
0
 public static void OnNEP17Payment(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!");
     }
 }
Esempio n. 2
0
        public static bool Transfer(UInt160 from, UInt160 to, BigInteger amount, object data)
        {
            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 (ContractManagement.GetContract(to) != null)
            {
                Contract.Call(to, "onNEP17Payment", CallFlags.All, new object[] { from, amount, data });
            }
            return(true);
        }
Esempio n. 3
0
 public static void DisablePayment()
 {
     if (!IsOwner())
     {
         throw new Exception("No authorization.");
     }
     AssetStorage.Disable();
 }
Esempio n. 4
0
        public static void _deploy(object data, 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);
        }
Esempio n. 5
0
        private static void Mint(BigInteger amount)
        {
            var totalSupply = TotalSupplyStorage.Get();

            var avaliable_supply = MaxSupply - totalSupply;

            if (amount <= 0)
            {
                throw new Exception("Amount must be greater than 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);
        }
Esempio n. 6
0
 public static BigInteger BalanceOf(UInt160 account) => AssetStorage.Get(account);