public static bool Deploy() { Runtime.Log("Deploy called"); if (!Runtime.CheckWitness(AppGlobals.FishEffectScriptHash)) { return(false); } BigInteger totalSupply = FishCoinDao.GetTotalSupply(); if (totalSupply != 0) { //Already deployed return(false); } BigInteger maximumSupply = MaxSupplyUnits * DecimalsFactor; FishCoinDao.SetTotalSupply(maximumSupply); UtilityDao.UpdateRandomStep(1); FishCoinDao.UpdateBalance(AppGlobals.FishEffectScriptHash, maximumSupply); Notifier.Transfer(null, AppGlobals.FishEffectScriptHash, maximumSupply); Runtime.Log("Deploy ok"); return(true); }
public static BigInteger BalanceOf(object[] args) { if (args.Length != 1) { return(-1); } byte[] ownerScriptHash = AppGlobals.FishEffectScriptHash; byte[] userAdressScriptHash = (byte[])args[0]; return(FishCoinDao.BalanceOf(userAdressScriptHash)); }
public static bool Transfer(object[] args) { Runtime.Log("Transfer called"); if (args.Length != 3) { return(false); } byte[] from = (byte[])args[0]; byte[] to = (byte[])args[1]; BigInteger value = (BigInteger)args[2]; if (from.Length == 0) { return(false); } if (to.Length == 0) { return(false); } if (!Runtime.CheckWitness(from)) { return(false); } BigInteger fromBalance = FishCoinDao.BalanceOf(from); BigInteger toBalance = FishCoinDao.BalanceOf(to); if (fromBalance < value) { return(false); } BigInteger finalFromBalance = fromBalance - value; BigInteger finalToBalance = toBalance + value; FishCoinDao.UpdateBalance(from, finalFromBalance); FishCoinDao.UpdateBalance(to, finalToBalance); //Notifier.PublishTransferNotification(from, to, value); Runtime.Log("Transfer ok"); return(true); }
public bool CalculateCanExchange(byte[] scriptHash, BigInteger amount) { BigInteger height = Blockchain.GetHeight(); BigInteger currentInCirculation = FishCoinDao.GetCurrentInCirculation(); BigInteger newAmount = currentInCirculation + amount; if (newAmount > FishCoinDao.GetTotalSupply()) { return(false); } if (height < IcoInitialBlock) { return(false); } if (amount > MaxExchangeLimitPerRound) { return(false); } if (height <= IcoFinalBlock) { BigInteger exchangedByThisScriptHash = FishCoinDao.GetExchangedGasByScriptHash(scriptHash); BigInteger finalAmount = exchangedByThisScriptHash + amount; if (finalAmount > MaxExchangeLimitPerRound) { return(false); } } //Mudar de local //FishCoinDao.UpdateExchangeByScriptHash(scriptHash, finalAmount); return(true); }
public static bool KycRegister(object[] args) { if (args.Length != 1) { return(false); } byte[] scriptHash = (byte[])args[0]; if (!Runtime.CheckWitness(AppGlobals.FishEffectScriptHash)) { return(false); } BigInteger status = (BigInteger)args[1]; FishCoinDao.UpdateKYCStatus(scriptHash, 1); return(true); }
public static BigInteger GetKycStatus(byte[] scriptHash) { BigInteger kycStatus = FishCoinDao.GetKycStatus(scriptHash); return(kycStatus); }
public static string FeedReef(object[] args) { if (args.Length != 1) { Runtime.Log("* No Args"); return("no args"); } byte[] reef = (byte[])args[0]; // I am the only one who can feed my reef if (!Runtime.CheckWitness(reef)) { Runtime.Log("* Not the Owner"); return("not owner"); } BigInteger currentBlockHeight = BlockchainHelper.GetHeight(); // used in the whole method BigInteger lastFedBH = ReefDao.GetBlockHeightFedReef(reef).AsBigInteger(); if (currentBlockHeight == lastFedBH) { Runtime.Log("* Fishes are not hungry"); return("not hungry"); } byte[] fishesAlive = ReefDao.GetReefFishesAlive(reef); // fishes alive on the reef, used in the whole method BigInteger fishesAliveLength = ListManager.GetLength(fishesAlive, FishManager.GetSize()); // used in the whole method Runtime.Log(" "); Runtime.Log("Fishes Alive:"); Runtime.Log(fishesAliveLength.AsByteArray().AsString()); Runtime.Log("------------"); BigInteger balance = FishCoinDao.BalanceOf(reef) / FishCoinProcess.DecimalsFactor; // if there is not enough food, there is nothing to do, the food will not be consumed if (balance < fishesAliveLength || balance <= 0) { Runtime.Log("* Not enough food"); return("no food"); } // variables used to generate random BigInteger consensusData = BlockchainHelper.GetConsensusData(); BigInteger randomStep = BlockchainHelper.GetRandomStep(); // a stepper to use a new random next time BigInteger aRandom = 0; // the random variable // if there is less than 2 fishes in the reef if (fishesAliveLength < 2) { Runtime.Log("* There is less than 2 fishes alive in the reef"); aRandom = BlockchainHelper.Random(consensusData, randomStep); randomStep = randomStep + 1; // 25% probability to arrive a new fish that got interested by the food you give away if (aRandom % 4 == 0) { Runtime.Log("* Immigrant arrived"); byte[] newImmigrant = FishManager.BuildImmigrant(reef, consensusData, randomStep); randomStep = randomStep + 4; // it was used 4 times inside the method fishesAlive = ListManager.Add(fishesAlive, newImmigrant); fishesAliveLength = fishesAliveLength + 1; Notifier.ImmigrantFish(reef, newImmigrant); } else { Runtime.Log("* No Immigrant today"); } } // if there is 2 or more fishes in the reef else { Runtime.Log("* There is 2 or more fishes in the reef"); aRandom = BlockchainHelper.Random(consensusData, randomStep); randomStep = randomStep + 1; // 33.3% probability to fishes get laid if (aRandom % 3 == 0) { Runtime.Log("* Fishs in love"); byte[] newBaby = new byte[0]; BigInteger indexFather; BigInteger indexMother; // if there is only 2 fishes they are the only possibility to mate if (fishesAliveLength == 2) { Runtime.Log("* Exactly 2 lovers"); indexFather = 0; indexMother = 1; } else { Runtime.Log("* More than 2 possible lovers"); // get a random fish to be the father aRandom = BlockchainHelper.Random(consensusData, randomStep); randomStep = randomStep + 1; indexFather = aRandom % fishesAliveLength; do { // get a random fish to be the mother, but a different fish of the father aRandom = BlockchainHelper.Random(consensusData, randomStep); randomStep = randomStep + 1; indexMother = aRandom % fishesAliveLength; Runtime.Log("* Looking for a pretty female"); } while (indexFather == indexMother); } byte[] father = ListManager.GetAt(fishesAlive, FishManager.GetSize(), indexFather); byte[] mother = ListManager.GetAt(fishesAlive, FishManager.GetSize(), indexMother); Runtime.Log("* Gestation"); newBaby = FishManager.BuildFromParents(consensusData, randomStep, father, mother); randomStep = randomStep + father.Length; // tried random that many times Runtime.Log("* Its a ... Fish!"); fishesAlive = ListManager.Add(fishesAlive, newBaby); fishesAliveLength = fishesAliveLength + 1; BigInteger newBornIndex = fishesAliveLength - 1; Notifier.NewBornFish(reef, newBaby); byte[] fatherFishType = FishManager.GetPropCarnivorous(father); byte[] motherFishType = FishManager.GetPropCarnivorous(mother); // if one of the parents are carnivorous and there is another silly fish ready to be a pray if (fatherFishType[0] == 0 || motherFishType[0] == 0 || fishesAliveLength > 3) { Runtime.Log("* There is pray for the predator"); BigInteger fathersFedWithFishBlockHeight = FishManager.GetFedWithFishBlockHeight(father).AsBigInteger(); BigInteger mothersFedWithFishBlockHeight = FishManager.GetFedWithFishBlockHeight(mother).AsBigInteger(); BigInteger indexPredator = -1; // zero means carnivorous // if has been more than 20 blocks since last time the father eat a fish if (fatherFishType[0] == 0 && currentBlockHeight - fathersFedWithFishBlockHeight > 20) { Runtime.Log("* The father is hungry"); indexPredator = indexFather; } else if (motherFishType[0] == 0 && currentBlockHeight - mothersFedWithFishBlockHeight > 20) { Runtime.Log("* The mother is hungry"); indexPredator = indexMother; } if (indexPredator > -1) { Runtime.Log("* It means that one of them is having a lunch"); byte[] predator = ListManager.GetAt(fishesAlive, FishManager.GetSize(), indexPredator); BigInteger indexPrey = 0; do { // get a random fish to be eaten, but a different fish of the father and the mother aRandom = BlockchainHelper.Random(consensusData, randomStep); randomStep = randomStep + 1; indexPrey = aRandom % fishesAliveLength; } while (indexPrey == indexMother || indexPrey == indexFather || indexPrey == newBornIndex); // saving the last blockheight when fish was fed with fish predator = FishManager.SetFedWithFishBlockHeight(predator, currentBlockHeight.AsByteArray()); fishesAlive = ListManager.EditAt(fishesAlive, FishManager.GetSize(), indexPredator, predator); // saving the predator dna inside the prey byte[] prey = ListManager.GetAt(fishesAlive, FishManager.GetSize(), indexPrey); // removing the prey from alive list (after everything, to not lose the right position after removing) fishesAlive = ListManager.RemoveAt(fishesAlive, FishManager.GetSize(), indexPrey); fishesAliveLength = fishesAliveLength - 1; byte[] fishesDead = ReefDao.GetReefFishesDead(reef); // fishes alive on the reef fishesDead = ListManager.Add(fishesDead, prey); ReefDao.UpdateReefFishesDead(reef, fishesDead); Notifier.FishEaten(reef, prey, predator); } else { Runtime.Log("* The predators are not hungry"); } } else { Runtime.Log("* No deaths today"); } } else { Runtime.Log("* They are not in the mood"); } } Runtime.Log("* Let's go sleep"); fishesAlive = IncrementQuantityOfFeeds(fishesAlive, fishesAliveLength); ReefDao.UpdateReefFishesAlive(reef, fishesAlive); FishCoinDao.SetTotalSupply(balance - fishesAliveLength); ReefDao.UpdateBlockHeightFedReef(reef, currentBlockHeight.AsByteArray()); BlockchainHelper.UpdateRandomStep(randomStep); Runtime.Log("* End :)"); return("success"); }