///<remarks> /// END user configurable fields ///</remarks> /// <summary> /// the entry point for smart contract execution /// </summary> /// <param name="operation">string to determine execution operation performed</param> /// <param name="args">optional arguments, context specific depending on operation</param> /// <returns></returns> public static object Main(string operation, params object[] args) { if (Runtime.Trigger == TriggerType.Application) { // test if a nep5 method is being invoked foreach (string nepMethod in NEP5.GetNEP5Methods()) { if (nepMethod == operation) { return(NEP5.HandleNEP5Operation(operation, args, ExecutionEngine.CallingScriptHash, ExecutionEngine.EntryScriptHash)); } } // test if a kyc method is being invoked foreach (string kycMethod in KYC.GetKYCMethods()) { if (kycMethod == operation) { return(KYC.HandleKYCOperation(operation, args)); } } // test if a helper/misc method is being invoked foreach (string helperMethod in Helpers.GetHelperMethods()) { if (helperMethod == operation) { return(Helpers.HandleHelperOperation(operation, args)); } } if (operation == "admin" && Helpers.VerifyIsAdminAccount()) { // allow access to administration methods string adminOperation = (string)args[0]; foreach (string adminMethod in Administration.GetAdministrationMethods()) { if (adminMethod == adminOperation) { return(Administration.HandleAdministrationOperation(adminOperation, args)); } } return(false); } } else if (Runtime.Trigger == TriggerType.Verification) { if (Helpers.VerifyIsAdminAccount()) { return(true); } // test if this transaction is allowed object[] transactionData = Helpers.GetTransactionAndSaleData(); return(TokenSale.CanUserParticipateInSale(transactionData)); } return(false); }
/// <summary> /// mint tokens is called when a user wishes to purchase tokens /// </summary> /// <returns></returns> public static bool MintTokens() { object[] transactionData = Helpers.GetTransactionAndSaleData(); Transaction tx = (Transaction)transactionData[0]; byte[] sender = (byte[])transactionData[1]; byte[] receiver = (byte[])transactionData[2]; ulong receivedNEO = (ulong)transactionData[3]; ulong receivedGAS = (ulong)transactionData[4]; BigInteger whiteListGroupNumber = (BigInteger)transactionData[5]; BigInteger crowdsaleAvailableAmount = (BigInteger)transactionData[6]; BigInteger groupMaximumContribution = (BigInteger)transactionData[7]; BigInteger totalTokensPurchased = (BigInteger)transactionData[8]; BigInteger neoRemainingAfterPurchase = (BigInteger)transactionData[9]; BigInteger gasRemainingAfterPurchase = (BigInteger)transactionData[10]; BigInteger totalContributionBalance = (BigInteger)transactionData[11]; if (Helpers.GetBlockTimestamp() >= ICOTemplate.PublicSaleEndTime()) { Runtime.Notify("MintTokens() failed. Token Sale is closed.", false); return(false); } if (!CanUserParticipateInSale(transactionData)) { Runtime.Notify("MintTokens() CanUserParticipate failed", false); return(false); } byte[] lastTransactionHash = Storage.Get(Storage.CurrentContext, StorageKeys.MintTokensLastTX()); if (lastTransactionHash == tx.Hash) { // ensure that minTokens doesnt process the same transaction more than once Runtime.Notify("MintTokens() not processing duplicate tx.Hash", tx.Hash); return(false); } Storage.Put(Storage.CurrentContext, StorageKeys.MintTokensLastTX(), tx.Hash); Runtime.Notify("MintTokens() receivedNEO / receivedGAS", receivedNEO, receivedGAS); if (neoRemainingAfterPurchase > 0 || gasRemainingAfterPurchase > 0) { // this purchase would have exceed the allowed max supply so we spent what we could and will refund the remainder refund(sender, neoRemainingAfterPurchase, gasRemainingAfterPurchase); } BigInteger senderAmountSubjectToVesting = SubjectToVestingPeriod(sender); BigInteger newTokenBalance = NEP5.BalanceOf(sender) + totalTokensPurchased + senderAmountSubjectToVesting; Helpers.SetBalanceOf(sender, newTokenBalance); Helpers.SetBalanceOfSaleContribution(sender, totalContributionBalance); Helpers.SetTotalSupply(totalTokensPurchased); transfer(null, sender, totalTokensPurchased); return(true); }
///<remarks> /// END user configurable fields ///</remarks> /// <summary> /// the entry point for smart contract execution /// </summary> /// <param name="operation">string to determine execution operation performed</param> /// <param name="args">optional arguments, context specific depending on operation</param> /// <returns></returns> public static object Main(string operation, params object[] args) { if (Runtime.Trigger == TriggerType.Application) { //Only allow InitSmartContract if contract not initialized and not calling whitelist/KYC operations if(!Helpers.ContractInitialised() && ((operation != "admin" && (string) args[0] != "InitSmartContract") && operation != "AddAddress" && operation != "RevokeAddress" && operation != "GetGroupNumber" && operation != "crowdsale_status")) { Runtime.Log("Smart Contract not Initialised"); return false; } if (operation == "admin" && Helpers.VerifyIsAdminAccount()) { // allow access to administration methods string adminOperation = (string)args[0]; foreach (string adminMethod in Administration.GetAdministrationMethods()) { if (adminMethod == adminOperation) { return Administration.HandleAdministrationOperation(adminOperation, args); } } return false; } // test if a nep5 method is being invoked foreach (string nepMethod in NEP5.GetNEP5Methods()) { if (nepMethod == operation) { return NEP5.HandleNEP5Operation(operation, args, ExecutionEngine.CallingScriptHash, ExecutionEngine.EntryScriptHash); } } // test if a kyc method is being invoked foreach (string kycMethod in KYC.GetKYCMethods()) { if (kycMethod == operation) { return KYC.HandleKYCOperation(operation, args); } } // test if a helper/misc method is being invoked foreach (string helperMethod in Helpers.GetHelperMethods()) { if (helperMethod == operation) { return Helpers.HandleHelperOperation(operation, args); } } //If MintTokensEth operation if(operation == "MintTokensEth") { // Method can only be called by the ETH contributions listener account if (Helpers.VerifyWitness(ICOTemplate.EthContributionListenerKey) && Helpers.RequireArgumentLength(args,3)) { return EthSale.MintTokensEth((string)args[0], (byte[])args[1], (ulong)args[2]); } } } else if (Runtime.Trigger == TriggerType.Verification) { if (Helpers.VerifyIsAdminAccount()) { return true; } // test if this transaction is allowed object[] transactionData = Helpers.GetTransactionAndSaleData(); return TokenSale.CanUserParticipateInSale(transactionData); } return false; }