Ejemplo n.º 1
0
    // This method tests Enjin's non-runtime API methods mostly used in the editor window.
    private void TestStaticEndpoints()
    {
        // Helper methods.
        TestMethod(() => { Enjin.StoreUserData(new User(), "test"); }, "user data storage");
        TestMethod <Boolean>(() => { return(Enjin.ValidateAddress("0xf629cbd94d3791c9250152bd8dfbdf380e2a3b9c")); }, true, "address validation");
        TestMethod(() => { Enjin.URLGetData("https://enjincoin.io/", new System.Collections.Generic.Dictionary <string, string>()); }, "fetching URL data");
        TestMethod <String>(() => { return(Enjin.URLGetData("bad URL", new System.Collections.Generic.Dictionary <string, string>())); }, string.Empty, "expected result from bad URL data");
        TestMethod(() => { Enjin.ResetErrorReport(); }, "error report reset");


        // CryptoItems methods.
        TestMethod(() => { Enjin.GetCryptoItemBalance(testingIdentityID, TESTING_ITEM_ID); }, "balance by identity");
        TestMethod(() => { Enjin.GetMintableItems(TESTING_ITEM_ID); }, "mintable item retrieval");
        TestMethod(() => {
            CryptoItem item = Enjin.GetCryptoItem(TESTING_ITEM_ID);
            Enjin.GetCryptoItemIDByName(item.name);
        }, "item identity by name");
        TestMethod(() => { Enjin.GetCryptoItemBalances(testingIdentityID); }, "all balances by identity");
        TestMethod(() => { Enjin.UpdateCryptoItem(new CryptoItem()); }, "item updating");
        TestMethod(() => { Enjin.GetAllCryptoItems(); }, "searching all items");
        TestMethod(() => {
            CryptoItem item = Enjin.GetCryptoItem(TESTING_ITEM_ID);
            Enjin.GetCryptoItemIDByName(item.name);
        }, "searching for item name");
        TestMethod(() => { Enjin.GetAllItems(0, 0, DEVELOPER_IDENTITY_ID); }, "getting all items by page");
        TestMethod(() => { Enjin.GetAllItems(DEVELOPER_IDENTITY_ID); }, "getting all items");

        // Enjin Platform API methods.
        TestMethod(() => { Enjin.GetTotalActiveTokens(DEVELOPER_IDENTITY_ID); }, "getting all active tokens");
        TestMethod(() => { Enjin.GetAppsByUserID(loginUser.id); }, "getting apps for user");
        TestMethod(() => { Enjin.GetAppByID(APP_ID); }, "getting app by id");

        // Identity methods.
        TestMethod(() => { Enjin.UpdateBalances(new Identity()); }, "identity balance updates");
        TestMethod(() => { Enjin.GetIdentity(testingIdentityID); }, "identity retrieval");
        TestMethod(() => { Enjin.GetAllIdentities(); }, "bulk identity retrieval");
        TestMethod(() => { Enjin.SearchIdentities("enjin"); }, "identity search");
        Identity sampleIdentity = new Identity
        {
            user = new Identity.User
            {
                name = loginUser.name,
                id   = loginUser.id
            },
            id     = testingIdentityID,
            fields = new Fields[] { new Fields("test", "enjin", 0, 0, 0) }
        };

        TestMethod(() => { Enjin.UpdateIdentity(sampleIdentity); }, "identity update");
        Enjin.AccessToken = TESTER_TOKEN;
        TestMethod(() => { Enjin.UpdateIdentityFields(testingIdentityID, new Fields[] { new Fields("test", "enjin!", 0, 0, 0) }); }, "identity field update");
        TestMethod(() => { Enjin.LinkIdentity(sampleIdentity); }, "identity link");
        TestMethod(() => { Enjin.UnLinkIdentity(testingIdentityID); }, "identity unlinking");
        TestMethod(() => { Enjin.DeleteIdentity(testingIdentityID + ""); }, "identity deletion");
        TestMethod(() => { Enjin.CreateIdentity(sampleIdentity); }, "identity creation");
        TestMethod(() => { Enjin.GetRoles(); }, "fetching identity roles");
        TestMethod(() => { Enjin.GetIdentities(0, 0); }, "fetching identity pages");
    }
Ejemplo n.º 2
0
        internal Request ProcessCryptoItem(ProcessTasks task, CryptoItem cryptoItem, Dictionary <string, object> properties)
        {
            Request request         = new Request();
            string  editMetaDataURI = "";

            switch (task)
            {
            case ProcessTasks.CREATE:
                string minValue = GraphQLClient.GraphQuery.GetEndPointData(Enjin.MeltValueURL + cryptoItem.reserve);

                if (properties.ContainsKey("MeltValue"))
                {
                    decimal actual = (decimal)((float)properties["MeltValue"] * Mathf.Pow(10, 18));

                    if (actual < System.Convert.ToInt64(minValue))
                    {
                        cryptoItem.meltValue = minValue;
                    }
                    else
                    {
                        cryptoItem.meltValue = actual.ToString("0");
                    }
                }
                else
                {
                    cryptoItem.meltValue = minValue;
                }


                if (properties.ContainsKey("MetaDataURI"))
                {
                    request = Enjin.CreateCryptoItem(cryptoItem, EnjinEditor.CurrentUserIdentity.id, ItemCreated => { HandleChainedRequestAction(request, ItemCreated, ProcessTasks.SETURI, cryptoItem, properties); });
                }
                else
                {
                    request = Enjin.CreateCryptoItem(cryptoItem, EnjinEditor.CurrentUserIdentity.id, ItemCreated => { HandleRequestAction(request); });
                }

                return(request);

            case ProcessTasks.DELETE:
                break;

            case ProcessTasks.EDIT:
                if (cryptoItem.isCreator)
                {
                    // handle name changes
                    if (properties.ContainsKey("ItemName"))
                    {
                        string editItemName = (string)properties["ItemName"];

                        if (editItemName != cryptoItem.name)
                        {
                            Debug.Log("running name change");
                            string temp = cryptoItem.name;
                            cryptoItem.name = editItemName;
                            request         = Enjin.UpdateCryptoItem(EnjinEditor.CurrentUserIdentity.id, cryptoItem, CryptoItemFieldType.NAME, ItemUpdated => { HandleRequestAction(request); });
                            cryptoItem.name = temp;
                        }
                    }

                    // handle metadata URI changes
                    if (properties.ContainsKey("MetaDataURI"))
                    {
                        editMetaDataURI = (string)properties["MetaDataURI"];

                        if (editMetaDataURI != cryptoItem.itemURI)
                        {
                            Debug.Log("running meta data URI update");
                            request = Enjin.SetCryptoItemURI(EnjinEditor.CurrentUserIdentity.id, cryptoItem, editMetaDataURI, URISet => { HandleRequestAction(request); });
                        }
                    }

                    return(request);
                }
                return(null);

            case ProcessTasks.MELT:
                int numToMelt = 1;
                if (properties.ContainsKey("NumToMelt"))
                {
                    numToMelt = (int)properties["NumToMelt"];
                }

                if (cryptoItem.nonFungible)
                {
                    Debug.Log("running melt request for non-fungible CI");
                    request = Enjin.MeltTokens(EnjinEditor.CurrentUserIdentity.id, cryptoItem.token_id, cryptoItem.index, numToMelt, MeltItem => { HandleRequestAction(request); });
                }
                else
                {
                    Debug.Log("running melt request for fungible CI");
                    request = Enjin.MeltTokens(EnjinEditor.CurrentUserIdentity.id, cryptoItem.token_id, numToMelt, MeltItem => { HandleRequestAction(request); });
                }

                return(request);

            case ProcessTasks.MINT:
                string[] addresses = new string[] { };
                if (properties.ContainsKey("RecieverAddress"))
                {
                    addresses = (string[])properties["RecieverAddress"];
                }

                if (!cryptoItem.nonFungible)
                {
                    int numToMint = 0;
                    if (properties.ContainsKey("NumToMint"))
                    {
                        numToMint = (int)properties["NumToMint"];
                    }

                    // Request should be pushed to event system to register the request by id, then the action callback should push to a method that fires off the seturi method once executed.
                    request = Enjin.MintFungibleItem(EnjinEditor.CurrentUserIdentity.id, addresses, cryptoItem.token_id, numToMint, ItemMinted => { HandleRequestAction(request); });
                }
                else
                {
                    // Request should be pushed to event system to register the request by id, then the action callback should push to a method that fires off the seturi method once executed.
                    request = Enjin.MintNonFungibleItem(EnjinEditor.CurrentUserIdentity.id, addresses, cryptoItem.token_id, ItemMinted => { HandleRequestAction(request); });
                }

                return(request);

            case ProcessTasks.SETURI:
                // handle metadata URI changes
                if (properties.ContainsKey("MetaDataURI"))
                {
                    editMetaDataURI = (string)properties["MetaDataURI"];

                    if (editMetaDataURI != cryptoItem.itemURI)
                    {
                        Debug.Log("running meta data URI update");
                        request = Enjin.SetCryptoItemURI(EnjinEditor.CurrentUserIdentity.id, cryptoItem, editMetaDataURI, URISet => { HandleRequestAction(request); });
                    }
                }

                return(request);

            default:
                break;
            }

            return(null);
        }