Esempio n. 1
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);
                }
                else if (notification.ScriptHash == GasToken)
                {
                    gas += GetTransactionAmount(notification);
                }
            }

            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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 public static BigInteger TotalSupply() => TotalSupplyStorage.Get();