예제 #1
0
        public static bool Transfer(byte[] from, byte[] to, BigInteger amount)
        {
            if (!ValidateAddress(from) || !ValidateAddress(to))
            {
                throw new Exception("The parameters from and to SHOULD be 20-byte addresses.");
            }
            if (amount <= 0)
            {
                throw new Exception("The parameter amount MUST be greater than 0.");
            }
            if (!IsPayable(to))
            {
                throw new Exception("Receiver cannot receive.");
            }
            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);
            return(true);
        }
예제 #2
0
        public static bool Mint()
        {
            if (Runtime.InvocationCounter != 1)
            {
                throw new Exception("InvocationCounter must be 1.");
            }

            var notifications = Runtime.GetNotifications();

            if (notifications.Length == 0)
            {
                throw new Exception("Contribution transaction not found.");
            }

            BigInteger neo = 0;
            BigInteger gas = 0;

            for (int i = 0; i < notifications.Length; i++)
            {
                var notification = notifications[i];

                if (notification.ScriptHash == NeoToken)
                {
                    neo += GetTransactionAmount(notification.State);
                }
                else if (notification.ScriptHash == GasToken)
                {
                    gas += GetTransactionAmount(notification.State);
                }
            }

            var totalSupply = TotalSupplyStorage.Get();

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

            var avaliable_supply = MaxSupply - totalSupply;

            var contribution = (neo * TokensPerNEO) + (gas * TokensPerGAS);

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

            Transaction tx = (Transaction)ExecutionEngine.ScriptContainer;

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

            OnTransfer(null, tx.Sender, contribution);
            return(true);
        }
예제 #3
0
 public static BigInteger BalanceOf(byte[] account)
 {
     if (!ValidateAddress(account))
     {
         throw new Exception("The parameters account SHOULD be 20-byte addresses.");
     }
     return(AssetStorage.Get(account));
 }
        public static bool Deploy()
        {
            if (!IsOwner())
            {
                throw new Exception("No authorization.");
            }
            if (TotalSupplyStorage.Get() > 0)
            {
                throw new Exception("Contract has been deployed.");
            }

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

            OnTransfer(null, Owner, InitialSupply);
            return(true);
        }