Exemplo n.º 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);
        }
Exemplo n.º 2
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));
 }