/// <summary>
        /// Release 0 generation gladiators to the auction house
        /// </summary>
        private static bool CreateGenerationZeroAuction(byte strength, byte power, byte agile, byte speed, byte generation)
        {
            byte[] tokenOwner = ExecutionEngine.ExecutingScriptHash;
            if (Runtime.CheckWitness(ContractMain.MintOwner))
            {
                object[]   args    = new object[] { tokenOwner, strength, power, agile, speed, generation };
                BigInteger tokenId = (BigInteger)ContractMain.NftContractCall("createGenerationZeroFromAuction_app", args);
                if (tokenId == 0)
                {
                    return(false);
                }

                BigInteger auctionStartPrice = GenerationZeroMaxPrice;
                BigInteger auctionEndPrice   = GenerationZeroMinPrice;
                BigInteger auctionDuration   = GenerationZeroAuctionDuration;

                object[] rawPrice = DataAccess.GetGenerationZeroPricesAsObjects();
                if (rawPrice.Length > 0)
                {
                    GenerationZeroPrice price = (GenerationZeroPrice)(object)rawPrice;
                    auctionStartPrice = price.MaxPrice;
                    auctionEndPrice   = price.MinPrice;
                    auctionDuration   = price.Duration;
                }

                return(SaleGenerationZero(
                           ContractMain.ContractOwner, tokenId,
                           auctionStartPrice, auctionEndPrice,
                           auctionDuration, 0));
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// Store 0 generation gladiator price range
        /// </summary>
        public static bool SetGenerationZeroPrice(GenerationZeroPrice model)
        {
            //Make a minimum judgment to prevent the setting too small
            if (model.MinPrice < AdminOperations.GenerationZeroMinPrice)
            {
                model.MaxPrice = AdminOperations.GenerationZeroMaxPrice;
                model.MinPrice = AdminOperations.GenerationZeroMinPrice;
                model.Duration = AdminOperations.GenerationZeroAuctionDuration;
            }

            byte[] bytes = Helper.Serialize(model);
            Storage.Put(Storage.CurrentContext, Keys.GenerationZeroPricesKey, bytes);

            return(true);
        }
        public static OperationResult HandleAdminOperation(string operation, params object[] args)
        {
            var result = new OperationResult {
                IsComplete = true
            };

            if (operation == "setCgasScriptHash")
            {
                if (Runtime.CheckWitness(ContractMain.ContractOwner))
                {
                    Storage.Put(Storage.CurrentContext, Keys.SGasKey, (byte[])args[0]);
                    result.Value = new byte[] { 0x01 };
                    return(result);
                }

                result.Value = new byte[] { 0x00 };
            }
            else if (operation == "setGenerationZeroPrice")
            {
                if (Runtime.CheckWitness(ContractMain.ContractOwner))
                {
                    BigInteger          maxPrice = (BigInteger)args[0];
                    BigInteger          minPrice = (BigInteger)args[1];
                    BigInteger          duration = (BigInteger)args[2];
                    GenerationZeroPrice price    = new GenerationZeroPrice
                    {
                        MaxPrice = maxPrice,
                        MinPrice = minPrice,
                        Duration = duration
                    };

                    result.Value = DataAccess.SetGenerationZeroPrice(price);
                    return(result);
                }

                result.Value = false;
            }
            else if (operation == "createGenerationZeroAuction")
            {
                if (args.Length != 5)
                {
                    result.Value = 0;
                    return(result);
                }

                byte strength   = (byte)args[0];
                byte power      = (byte)args[1];
                byte agile      = (byte)args[2];
                byte speed      = (byte)args[3];
                byte generation = (byte)args[4];

                result.Value = CreateGenerationZeroAuction(strength, power, agile, speed, generation);
            }
            else if (operation == "adminWithdraw")
            {
                if (args.Length != 2)
                {
                    result.Value = 0;
                    return(result);
                }
                ;

                BigInteger flag  = (BigInteger)args[0];
                BigInteger count = (BigInteger)args[1];

                result.Value = Withdraw(flag, count);
            }
            else
            {
                result.IsComplete = false;
            }

            return(result);
        }