/// <inheritdoc/>
        public override async Task <GameItem[]> GetGameItems(HoardID address)
        {
            var items       = new List <GameItem>();
            var balanceData = await plasmaComm.GetBalanceData(address, contract.Address);

            if (balanceData is FCBalanceData)
            {
                string symbol = await contract.GetSymbol();

                string state = (await(contract as ERC223GameItemContract).GetTokenState()).ToHex(true);

                ERC223GameItemContract.Metadata meta = new ERC223GameItemContract.Metadata(contract.Address, (balanceData as FCBalanceData).Amount);
                items.Add(new GameItem(game, symbol, meta));
            }
            return(items.ToArray());
        }
Beispiel #2
0
            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                JToken tokens    = JToken.Load(reader);
                var    gameItems = new List <GameItem>();

                foreach (var token in tokens)
                {
                    if (token["contract_type"].ToString() == "ERC721")
                    {
                        string     symbol          = token["item_type"].ToString();
                        string     contractAddress = token["contract_address"].ToString();
                        byte[]     stateBytes      = token["state"].ToString().HexToByteArray();
                        BigInteger tokenId         = BigInteger.Parse(token["token_id"].ToString());

                        var meta = new ERC721GameItemContract.Metadata(contractAddress, tokenId);
                        var item = new GameItem(HoardService.Instance.DefaultGame, symbol, meta);
                        item.State = stateBytes;

                        gameItems.Add(item);
                    }
                    else if (token["contract_type"].ToString() == "ERC223")
                    {
                        string     symbol          = token["item_type"].ToString();
                        string     contractAddress = token["contract_address"].ToString();
                        byte[]     stateBytes      = token["state"].ToString().HexToByteArray();
                        BigInteger balance         = BigInteger.Parse(token["balance"].ToString());

                        var meta = new ERC223GameItemContract.Metadata(contractAddress, balance);
                        var item = new GameItem(HoardService.Instance.DefaultGame, symbol, meta);
                        item.State = stateBytes;

                        gameItems.Add(item);
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }

                return(gameItems);
            }