//Issue tokens to an address
        //called only by owner of the smart contract
        private static bool Issue(byte[] account, BigInteger value)
        {
            if (!Runtime.CheckWitness(TOK.Owner)) //authorization
            {
                Error("Authorization_failed");
                return(false);
            }
            if (value <= 0) //valid amount to be issued
            {
                Error("Invalid_amount_to_issue");
                return(false);
            }
            bool isActiveUser = (bool)FIP.KYC("isActiveUser", new object[] { account });

            if (isActiveUser == false)
            {
                Error("Inactive_user");
                return(false);
            }
            //issue
            BigInteger currentBalance = Storage.Get(Storage.CurrentContext, account).AsBigInteger();

            Storage.Put(Storage.CurrentContext, account, currentBalance + value);
            currentBalance = Storage.Get(Storage.CurrentContext, account).AsBigInteger();
            Issued(account, value, currentBalance);
            return(true);
        }
Example #2
0
        internal static object ApplicationMethods(string operation, object[] args)
        {
            if (operation == "PRO_MaxFundAdjust")
            {
                return(solveMaxFund((bool)args[0], (string)args[1], (BigInteger)args[2]));
            }

            /******
            *
            * sec 1: only one participants
            * ****/
            if (!(bool)FIP.KYC("isActiveUser", new object[] { args[0] }))
            {
                Error("In_active_user1" + ((byte[])args[0]).AsString());
                return(false);
            }
            if (operation == "PRO_PullPayment")
            {
                return(PullPayment((byte[])args[0], (BigInteger)args[1]));
            }

            /******
            *
            * sec 2: 2 participants required
            * ****/
            switch (operation)
            {
            }
            if (!(bool)FIP.KYC("isActiveUser", new object[] { args[1] }))
            {
                Error("In_active_user2" + ((byte[])args[0]).AsString());
                return(false);
            }
            if (operation == "PRO_InstantPay")
            {
                return(InstantPay((byte[])args[0], (byte[])args[1], (BigInteger)args[2]));
            }
            if (operation == "PRO_SinglePay")
            {
                return(SinglePay((byte[])args[0], (byte[])args[1], (BigInteger)args[2]));
            }
            if (operation == "PRO_Agreement")
            {
                return(MakeAgreement((byte[])args[0], (byte[])args[1], (BigInteger)args[2], (BigInteger)args[3], (BigInteger)args[4], (BigInteger)args[5], (uint)args[6]));
            }
            if (operation == "PRO_PullSchedule")
            {
                return(PullSchedulePayment((byte[])args[0], (byte[])args[1], (BigInteger)args[2], (byte[])args[3]));
            }
            if (operation == "PRO_CancelSchedulePay")
            {
                return(CancelSchedulePayment((byte[])args[0], (byte[])args[1], (byte[])args[2]));
            }
            Error("unsupported_protocol_function");
            return(null);
        }
 /// <summary>
 /// withdraw token
 /// </summary>
 /// <param name="address"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 private static bool withdrawToken(byte[] zyaddress, byte[] withdrawlAddress, BigInteger value)
 {
     if (!Runtime.CheckWitness(zyaddress))
     {
         Error("Authorization_failed");
         return(false);
     }
     if (!(bool)FIP.KYC("isActiveUser", new object[] { zyaddress }))
     {
         Error("In_active_user" + zyaddress.AsString());
         return(false);
     }
     byte[] id = (byte[])FIP.KYC("getRegisteredAddress", new object[] { withdrawlAddress, ModuleNEP5.Symbol() });
     if (id != zyaddress)
     {
         Error("Invalid_addresses");
         return(false);
     }
     return(ModuleNEP5.Transfer(zyaddress, TOK.Owner, value, 0));
 }
 private static bool IssueByDeposit(byte[] account, BigInteger value)
 {
     byte[] address = (byte[])FIP.KYC("getRegisteredAddress", new object[] { account, ModuleNEP5.Symbol() });
     return(Issue(address, value));
 }