/// <summary>
        /// Get all gladiator ids owned by an address, not currently supported
        /// </summary>
        private static BigInteger[] TokensOfOwner(byte[] owner)
        {
            BigInteger tokenCount = NepOperations.BalanceOf(owner);

            BigInteger[] result = new BigInteger[(int)tokenCount];

            if (tokenCount == 0)
            {
                return(result);
            }
            else
            {
                // We count on the fact that all NFTInfo have IDs starting at 1 and increasing
                // sequentially up to the totalCat count.
                for (BigInteger idx = 1; idx < tokenCount + 1; idx += 1)
                {
                    var tokenId = DataAccess.GetOwnersTokenIdByIndexAsBytes(owner, idx);
                    result[(int)idx - 1] = tokenId.AsBigInteger();
                }

                return(result);
            }
        }
示例#2
0
 /// <summary>
 /// Release Promotion Gladiator
 /// </summary>
 private static BigInteger MintToken(
     byte[] tokenOwner, byte strength, byte power, byte agile, byte speed, BigInteger generation) =>
 NepOperations.CreateToken(tokenOwner, strength, power, agile, speed, generation);
示例#3
0
        /// <summary>
        /// Attepts to handle the current operation
        /// </summary>
        public static OperationResult HandleTokenOperation(string operation, params object[] args)
        {
            OperationResult result = new OperationResult {
                IsComplete = true
            };

            byte[] callingScript = ExecutionEngine.CallingScriptHash;
            if (operation == "getMarketAddress")
            {
                result.Value = GetMarketAddress();
            }
            else if (operation == "getAttrConfig")
            {
                result.Value = DataAccess.GetAttrConfigAsObjects();
            }
            else if (operation == "getTxInfo")
            {
                if (args.Length != 1)
                {
                    result.Value = 0;
                    return(result);
                }

                byte[] transactionId = (byte[])args[0];

                result.Value = DataAccess.GetTransactionInfoAsObjects(transactionId);
            }
            else if (operation == "getTokenData")
            {
                BigInteger tokenId = (BigInteger)args[0];

                result.Value = DataAccess.GetToken(tokenId.AsByteArray());
            }
            else if (operation == "getTokenOfOwnerByIndex")
            {
                byte[]     owner = (byte[])args[0];
                BigInteger index = (BigInteger)args[1];

                result.Value = DataAccess.GetOwnersTokenIdByIndexAsBytes(owner, index);
            }
            else if (operation == "getApprovedAddress")
            {
                BigInteger tokenId = (BigInteger)args[0];

                result.Value = GetApprovedAddress(tokenId);
            }

            else if (operation == "transferFrom")
            {
                if (args.Length != 3)
                {
                    result.Value = false;
                    return(result);
                }

                byte[]     from    = (byte[])args[0];
                byte[]     to      = (byte[])args[1];
                BigInteger tokenId = (BigInteger)args[2];

                result.Value = TransferFrom(from, to, tokenId);
            }
            else if (operation == "mintToken")
            {
                if (args.Length != 6)
                {
                    result.Value = 0;
                    return(result);
                }

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

                result.Value = MintToken(owner, strength, power, agile, speed, generation);
            }
            else if (operation == "approve")
            {
                byte[]     approvedAddress = (byte[])args[0];
                BigInteger tokenId         = (BigInteger)args[1];
                BigInteger duration        = 0;
                if (args.Length == 3)
                {
                    duration = (BigInteger)args[2];
                }

                result.Value = Approve(approvedAddress, tokenId, duration);
            }

            else if (operation == "approveDuration")
            {
                byte[]     approvedAddress = (byte[])args[0];
                BigInteger tokenId         = (BigInteger)args[1];
                BigInteger duration        = (BigInteger)args[2];

                result.Value = Approve(approvedAddress, tokenId, duration);
            }

            else if (operation == "transferFrom_app")
            {
                if (args.Length != 3)
                {
                    result.Value = false;
                    return(result);
                }

                byte[]     from    = (byte[])args[0];
                byte[]     to      = (byte[])args[1];
                BigInteger tokenId = (BigInteger)args[2];

                if (!Runtime.CheckWitness(from))
                {
                    result.Value = false;
                    return(result);
                }

                byte[] marketAddress = DataAccess.GetMarketAddressAsBytes();
                if (callingScript.AsBigInteger() != marketAddress.AsBigInteger())
                {
                    result.Value = false;
                    return(result);
                }

                result.Value = NepOperations.Transfer(from, to, tokenId);
            }
            else if (operation == "transfer_app")
            {
                if (args.Length != 3)
                {
                    result.Value = false;
                    return(result);
                }

                byte[]     from    = (byte[])args[0];
                byte[]     to      = (byte[])args[1];
                BigInteger tokenId = (BigInteger)args[2];

                if (from.AsBigInteger() != callingScript.AsBigInteger())
                {
                    result.Value = false;
                    return(result);
                }

                result.Value = NepOperations.Transfer(from, to, tokenId);
            }
            else if (operation == "transfer_Syn")
            {
                if (args.Length != 4)
                {
                    result.Value = false;
                    return(result);
                }

                byte[]     from    = (byte[])args[0];
                byte[]     to      = (byte[])args[1];
                BigInteger tokenId = (BigInteger)args[2];
                byte[]     scHash  = (byte[])args[3];

                if (scHash.AsBigInteger() != callingScript.AsBigInteger())
                {
                    result.Value = false;
                    return(result);
                }

                result.Value = NepOperations.Transfer(from, to, tokenId);
            }
            else
            {
                result.IsComplete = false;
            }

            return(result);
        }
示例#4
0
        /// <summary>
        /// Attepts to handle the current operation
        /// </summary>
        public static OperationResult HandleGameOperation(string operation, params object[] args)
        {
            var callingScript = ExecutionEngine.CallingScriptHash;
            var result        = new OperationResult {
                IsComplete = true
            };

            if (operation == "getIsPregnant")
            {
                if (args.Length != 1)
                {
                    result.Value = 0;
                    return(result);
                }

                BigInteger tokenId = (BigInteger)args[0];
                result.Value = GameOperations.IsPregnant(tokenId);
            }
            else if (operation == "getCanBreedWithById")
            {
                if (args.Length != 2)
                {
                    result.Value = 0;
                    return(result);
                }

                BigInteger motherId = (BigInteger)args[0];
                BigInteger fatherId = (BigInteger)args[1];
                result.Value = GameOperations.CanBreedWithById(motherId, fatherId);
            }
            else if (operation == "getIsCloneApplySucc")
            {
                if (args.Length != 1)
                {
                    result.Value = 0;
                    return(result);
                }

                BigInteger tokenId = (BigInteger)args[0];
                result.Value = GameOperations.IsCloneApplySuccessful(tokenId);
            }
            else if (operation == "getIsReadyToBreed")
            {
                if (args.Length != 1)
                {
                    result.Value = 0;
                    return(result);
                }

                BigInteger tokenId = (BigInteger)args[0];
                result.Value = GameOperations.IsReadyToBreed(tokenId);
            }

            else if (operation == "giveBirth")
            {
                if (args.Length != 1)
                {
                    result.Value = 0;
                    return(result);
                }

                BigInteger motherId = (BigInteger)args[0];
                result.Value = GameOperations.GiveBirth(motherId);
            }

            else if (operation == "bidOnClone_app")
            {
                if (args.Length != 3)
                {
                    result.Value = 0;
                    return(result);
                }

                byte[]     owner    = (byte[])args[0];
                BigInteger motherId = (BigInteger)args[1];
                BigInteger fatherId = (BigInteger)args[2];

                byte[] marketAddress = DataAccess.GetMarketAddressAsBytes();
                if (callingScript.AsBigInteger() != marketAddress.AsBigInteger())
                {
                    result.Value = false;
                    return(result);
                }

                result.Value = GameOperations.BreedWithId_app(owner, motherId, fatherId);
            }

            else if (operation == "breedWithMy_app")
            {
                if (args.Length != 3)
                {
                    result.Value = 0;
                    return(result);
                }

                byte[]     owner    = (byte[])args[0];
                BigInteger motherId = (BigInteger)args[1];
                BigInteger fatherId = (BigInteger)args[2];

                byte[] marketAddress = DataAccess.GetMarketAddressAsBytes();
                if (callingScript.AsBigInteger() != marketAddress.AsBigInteger())
                {
                    result.Value = false;
                    return(result);
                }

                object[] rawFatherToken = DataAccess.GetTokenAsObjects(fatherId.AsByteArray());
                if (rawFatherToken.Length > 0)
                {
                    TokenInfo fatherInfo = (TokenInfo)(object)rawFatherToken;
                    if (fatherInfo.Owner.AsBigInteger() == owner.AsBigInteger())
                    {
                        result.Value = GameOperations.BreedWithId_app(owner, motherId, fatherId);
                        return(result);
                    }
                }

                result.Value = false;
            }
            else if (operation == "createGenerationZeroFromAuction_app")
            {
                byte[]     tokenOwner = (byte[])args[0];
                byte       strength   = (byte)args[1];
                byte       power      = (byte)args[2];
                byte       agile      = (byte)args[3];
                byte       speed      = (byte)args[4];
                BigInteger generation = (int)args[5];

                byte[] marketAddress = DataAccess.GetMarketAddressAsBytes();
                if (callingScript.AsBigInteger() != marketAddress.AsBigInteger())
                {
                    result.Value = false;
                    return(result);
                }

                result.Value = NepOperations.CreateToken(tokenOwner, strength, power, agile, speed, generation);
            }
            else
            {
                result.IsComplete = false;
            }

            return(result);
        }
        /// <summary>
        /// Attepts to handle the current operation
        /// </summary>
        public static OperationResult HandleNepOperation(string operation, params object[] args)
        {
            var result = new OperationResult {
                IsComplete = true
            };

            if (operation == "version")
            {
                result.Value = NepOperations.Version();
            }
            else if (operation == "name")
            {
                result.Value = NepOperations.Name();
            }
            else if (operation == "symbol")
            {
                result.Value = NepOperations.Symbol();
            }
            else if (operation == "totalSupply")
            {
                result.Value = NepOperations.TotalSupply();
            }
            else if (operation == "decimals")
            {
                result.Value = 0;
            }
            else if (operation == "ownerOf")
            {
                BigInteger tokenId = (BigInteger)args[0];

                result.Value = NepOperations.OwnerOf(tokenId);
            }
            else if (operation == "tokenURI")
            {
                BigInteger tokenId = (BigInteger)args[0];

                result.Value = NepOperations.TokenURI(tokenId);
            }
            else if (operation == "balanceOf")
            {
                if (args.Length != 1)
                {
                    result.Value = 0;
                    return(result);
                }

                byte[] account = (byte[])args[0];

                result.Value = NepOperations.BalanceOf(account);
            }
            else if (operation == "tokensOfOwner")
            {
                byte[] owner = (byte[])args[0];

                result.Value = NepOperations.TokensOfOwner(owner);
            }

            else if (operation == "transfer")
            {
                if (args.Length != 3)
                {
                    result.Value = false;
                    return(result);
                }

                byte[]     from    = (byte[])args[0];
                byte[]     to      = (byte[])args[1];
                BigInteger tokenId = (BigInteger)args[2];

                if (!Runtime.CheckWitness(from))
                {
                    result.Value = false;
                    return(result);
                }

                var callingScript = ExecutionEngine.CallingScriptHash;
                if (ExecutionEngine.EntryScriptHash.AsBigInteger() != callingScript.AsBigInteger())
                {
                    result.Value = false;
                    return(result);
                }

                result.Value = NepOperations.Transfer(from, to, tokenId);
            }
            else
            {
                result.IsComplete = false;
            }

            return(result);
        }
 /// <summary>
 /// Release Promotion Gladiator
 /// </summary>
 private static BigInteger MintToken(
     byte[] owner, byte health, byte mana, byte agility,
     byte stamina, byte criticalStrike, byte attackSpeed, byte versatility, byte mastery, BigInteger level) =>
 NepOperations.CreateToken(owner, health, mana, agility,
                           stamina, criticalStrike, attackSpeed, versatility, mastery, level);
        /// <summary>
        /// Attepts to handle the current operation
        /// </summary>
        public static OperationResult HandleTokenOperation(string operation, params object[] args)
        {
            OperationResult result = new OperationResult {
                IsComplete = true
            };

            byte[] callingScript = ExecutionEngine.CallingScriptHash;
            if (operation == "getMarketAddress")
            {
                result.Value = GetMarketAddress();
            }
            else if (operation == "getAttrConfig")
            {
                result.Value = DataAccess.GetAttrConfigAsObjects();
            }
            else if (operation == "getTxInfo")
            {
                if (args.Length != 1)
                {
                    result.Value = 0;
                    return(result);
                }

                byte[] transactionId = (byte[])args[0];

                result.Value = DataAccess.GetTransactionInfoAsObjects(transactionId);
            }
            else if (operation == "getTokenData")
            {
                BigInteger tokenId = (BigInteger)args[0];

                result.Value = DataAccess.GetToken(tokenId.AsByteArray());
            }
            else if (operation == "getTokenOfOwnerByIndex")
            {
                byte[]     owner = (byte[])args[0];
                BigInteger index = (BigInteger)args[1];

                result.Value = DataAccess.GetOwnersTokenIdByIndexAsBytes(owner, index);
            }
            else if (operation == "getApprovedAddress")
            {
                BigInteger tokenId = (BigInteger)args[0];

                result.Value = GetApprovedAddress(tokenId);
            }

            else if (operation == "transferFrom")
            {
                if (args.Length != 3)
                {
                    result.Value = false;
                    return(result);
                }

                byte[]     from    = (byte[])args[0];
                byte[]     to      = (byte[])args[1];
                BigInteger tokenId = (BigInteger)args[2];

                result.Value = TransferFrom(from, to, tokenId);
            }
            else if (operation == "mintToken")
            {
                if (args.Length != 10)
                {
                    result.Value = 0;
                    return(result);
                }

                byte[]     tokenOwner     = (byte[])args[0];
                byte       health         = (byte)args[1];
                byte       mana           = (byte)args[2];
                byte       agility        = (byte)args[3];
                byte       stamina        = (byte)args[4];
                byte       criticalStrike = (byte)args[5];
                byte       attackSpeed    = (byte)args[6];
                byte       versatility    = (byte)args[7];
                byte       mastery        = (byte)args[8];
                BigInteger level          = (byte)args[9];

                result.Value = MintToken(tokenOwner, health, mana, agility, stamina,
                                         criticalStrike, attackSpeed, versatility, mastery, level);
            }
            else if (operation == "approve")
            {
                byte[]     approvedAddress = (byte[])args[0];
                BigInteger tokenId         = (BigInteger)args[1];

                result.Value = Approve(approvedAddress, tokenId);
            }

            else if (operation == "transferFrom_app")
            {
                if (args.Length != 3)
                {
                    result.Value = false;
                    return(result);
                }

                byte[]     from    = (byte[])args[0];
                byte[]     to      = (byte[])args[1];
                BigInteger tokenId = (BigInteger)args[2];

                if (!Runtime.CheckWitness(from))
                {
                    result.Value = false;
                    return(result);
                }

                byte[] marketAddress = DataAccess.GetMarketAddressAsBytes();
                if (callingScript.AsBigInteger() != marketAddress.AsBigInteger())
                {
                    result.Value = false;
                    return(result);
                }

                result.Value = NepOperations.Transfer(from, to, tokenId);
            }
            else if (operation == "transfer_app")
            {
                if (args.Length != 3)
                {
                    result.Value = false;
                    return(result);
                }

                byte[]     from    = (byte[])args[0];
                byte[]     to      = (byte[])args[1];
                BigInteger tokenId = (BigInteger)args[2];

                if (from.AsBigInteger() != callingScript.AsBigInteger())
                {
                    result.Value = false;
                    return(result);
                }

                result.Value = NepOperations.Transfer(from, to, tokenId);
            }
            else if (operation == "transfer_Syn")
            {
                if (args.Length != 4)
                {
                    result.Value = false;
                    return(result);
                }

                byte[]     from    = (byte[])args[0];
                byte[]     to      = (byte[])args[1];
                BigInteger tokenId = (BigInteger)args[2];
                byte[]     scHash  = (byte[])args[3];

                if (scHash.AsBigInteger() != callingScript.AsBigInteger())
                {
                    result.Value = false;
                    return(result);
                }

                result.Value = NepOperations.Transfer(from, to, tokenId);
            }
            else
            {
                result.IsComplete = false;
            }

            return(result);
        }