示例#1
0
    // On each update, check the current game state and handle logic appropriately.
    void Update()
    {
        // Handle any events posted here from an asynchronous Enjin task.
        for (int i = 0; i < pendingActions.Count; i++)
        {
            System.Action action = pendingActions[i];
            action();
        }
        pendingActions.Clear();

        // Reward the users with a token every time they get 15 clicks.
        if (score >= SCORE_THRESHOLD)
        {
            score = 0;
            SetStatus("Linked successfully.\nYour score is: " + score, false);
            rewardMask.transform.localScale = new Vector3(1, 1, 1);

            // Mint a new token directly from the developer wallet.
            CryptoItem item             = Enjin.GetCryptoItem(REWARD_TOKEN_ID);
            string     reserveCount     = item.reserve;
            int        developerBalance = Enjin.GetCryptoItemBalance(DEVELOPER_IDENTITY_ID, REWARD_TOKEN_ID);
            if (!reserveCount.Equals("0"))
            {
                pending += 1;
                Enjin.MintFungibleItem(DEVELOPER_IDENTITY_ID, new string[] { userAddress }, REWARD_TOKEN_ID, 1,
                                       (requestEvent) =>
                {
                    if (requestEvent.event_type.Equals("tx_executed"))
                    {
                        pending -= 1;
                        count   += 1;
                        pendingActions.Add(() =>
                        {
                            inventory.text = (tokenName + "\nYou have: " + count + "\nCurrently pending: " + pending);
                        });
                    }
                });
                inventory.text = (tokenName + "\nYou have: " + count + "\nCurrently pending: " + pending);
            }

            // If the developer wallet is unable to mint reward tokens from the reserve, try to send it from the developer wallet.
            else if (developerBalance > 0)
            {
                pending += 1;
                Enjin.SendCryptoItemRequest(DEVELOPER_IDENTITY_ID, REWARD_TOKEN_ID, identityId, 1,
                                            (requestEvent) =>
                {
                    if (requestEvent.event_type.Equals("tx_executed"))
                    {
                        pending -= 1;
                        count   += 1;
                        pendingActions.Add(() =>
                        {
                            inventory.text = (tokenName + "\nYou have: " + count + "\nCurrently pending: " + pending);
                        });
                    }
                });
                inventory.text = (tokenName + "\nYou have: " + count + "\nCurrently pending: " + pending);
            }

            // Otherwise there really is nothing of this token left for the developer to give out.
            else
            {
                SetStatus("Uh oh! The game developer is out of reward items!", true);
            }
        }
    }
示例#2
0
    private void Update()
    {
        // Sequence lock to wait for a successful callback on linking a wallet.
        if (sequenceOne)
        {
            sequenceOne = false;
            Debug.Log("(5/8) Sending an item from the developer account to the testing account ... ");
            Enjin.AccessToken = DEVELOPER_TOKEN;

            // Mint a new token directly from the developer wallet.
            CryptoItem item             = Enjin.GetCryptoItem(TESTING_ITEM_ID);
            string     reserveCount     = item.reserve;
            int        developerBalance = Enjin.GetCryptoItemBalance(DEVELOPER_IDENTITY_ID, TESTING_ITEM_ID);
            if (!reserveCount.Equals("0"))
            {
                Enjin.MintFungibleItem(DEVELOPER_IDENTITY_ID, new string[] { USER_ADDRESS }, TESTING_ITEM_ID, 1,
                                       (requestEvent) =>
                {
                    if (requestEvent.event_type.Equals("tx_executed"))
                    {
                        Debug.Log(" ... PASSED: MINTED.");
                        sequenceTwo = true;
                    }
                });
            }

            // If the developer wallet is unable to mint reward tokens from the reserve, try to send it from the developer wallet.
            else if (developerBalance > 0)
            {
                Enjin.SendCryptoItemRequest(DEVELOPER_IDENTITY_ID, TESTING_ITEM_ID, testingIdentityID, 1, sendData =>
                {
                    if (sendData.event_type.Equals("tx_executed"))
                    {
                        Debug.Log(" ... PASSED: SENT.");
                        sequenceTwo = true;
                    }
                });
            }

            // Otherwise there really is nothing of this token left for the developer to give out.
            else
            {
                Debug.Log(" ... FAILED: NO RESERVE TO MINT OR BALANCE TO SEND.");
            }
        }

        // Sequence lock to wait for a successful callback on sending an item.
        if (sequenceTwo)
        {
            sequenceTwo = false;
            Debug.Log("(6/8) Trading an item from the testing account to the developer account ... ");
            Enjin.AccessToken = TESTER_TOKEN;
            CryptoItem tradeToItem = new CryptoItem
            {
                token_id    = TESTING_ITEM_ID,
                nonFungible = false
            };
            CryptoItem tradeFromItem = new CryptoItem
            {
                token_id    = TESTING_ITEM_ID,
                nonFungible = false
            };
            testingIdentity = Enjin.GetIdentity(testingIdentityID);
            Identity developerIdentity = Enjin.GetIdentity(DEVELOPER_IDENTITY_ID);
            Enjin.CreateTradeRequest(testingIdentityID, new CryptoItem[] { tradeToItem }, new int[] { 1 },
                                     DEVELOPER_IDENTITY_ID, new CryptoItem[] { tradeFromItem }, new int[] { 1 }, tradeData =>
            {
                tradeId = tradeData.request_id;
                Debug.Log(" ... PASSED.");
                sequenceThree = true;
            });
        }

        // Sequence lock to wait for successful trade creation before completion.
        if (sequenceThree)
        {
            sequenceThree = false;
            Debug.Log("(7/8) Completing trade from the testing account to the developer account ... ");
            Enjin.AccessToken = DEVELOPER_TOKEN;
            Enjin.CompleteTradeRequest(DEVELOPER_IDENTITY_ID, "" + tradeId, tradeData =>
            {
                Debug.Log(" ... PASSED.");
                sequenceFour = true;
            });
        }

        // Sequence lock to wait for successful trade of item before melting.
        if (sequenceFour)
        {
            sequenceFour = false;
            Debug.Log("(8/8) Melting an item on the testing account ... ");
            Enjin.AccessToken = TESTER_TOKEN;
            Enjin.MeltTokens(testingIdentityID, TESTING_ITEM_ID, 1, meltData =>
            {
                Debug.Log(" ... PASSED.");
                sequenceFive = true;
            });
        }

        // Sequence lock to wait for successful completion of all tests before running static suite.
        if (sequenceFive)
        {
            sequenceFive = false;

            // Execute additional tests for non-runtime SDK calls.
            TestStaticEndpoints();
            Debug.Log("=== All tests executed successfully. ===");
        }
    }
示例#3
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);
        }