/// <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> /// 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); }
/// <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); }