/// <inheritdoc/> public async Task <GameItem[]> GetItems(GameItemsParams[] gameItemsParams) { List <GameItem> items = new List <GameItem>(); foreach (var param in gameItemsParams) { GameItemContract itemContract = await GetGameItemContractByInterface(param.ContractAddress); items.Add(await itemContract.GetGameItem(param)); } return(items.ToArray()); }
/// <summary> /// Creates game item adapter for given game and game item contract /// </summary> /// <param name="game">game id</param> /// <param name="contract">game item contract</param> /// <returns></returns> public GameItemAdapter GetGameItemAdater(GameID game, GameItemContract contract) { if (contract is ERC223GameItemContract) { return((GameItemAdapter)Activator.CreateInstance(typeof(ERC20GameItemAdapter), this, game, contract)); } else if (contract is ERC721GameItemContract) { return((GameItemAdapter)Activator.CreateInstance(typeof(ERC721GameItemAdapter), this, game, contract)); } throw new NotSupportedException(); }
/// <summary> /// Helper function to automatically register all contracts for given game /// </summary> public async Task RegisterHoardGameContracts() { string[] contracts = await BCComm.GetGameItemContracts(Game); if (contracts != null) { foreach (string c in contracts) { GameItemContract gameItemContract = await GetGameItemContractByInterface(c); if (gameItemContract != null) { RegisterGameItemContract(await gameItemContract.GetSymbol(), gameItemContract); } else { throw new HoardException("Invalid contract"); } } return; } throw new HoardException($"Cannot find any contracts for Game: {Game.ID}!"); }
private void RegisterGameItemContract(string symbol, GameItemContract contract) { System.Diagnostics.Debug.Assert(!ItemContracts.ContainsKey(symbol), string.Format("ERROR: contract with this symbol has been already registered for Game: '{0}' with ID {1}", Game.Name, Game.ID)); ItemContracts.Add(symbol, contract); }
/// <inheritdoc/> public Task <bool> Transfer(Profile from, string addressTo, GameItem item, BigInteger amount) { GameItemContract gameItemContract = ItemContracts[item.Symbol]; return(gameItemContract.Transfer(from, addressTo, item, amount)); }
/// <summary> /// Constructor of base game item adapter /// </summary> /// <param name="_plasmaComm">plasma communication</param> /// <param name="_game">game that manages these items</param> /// <param name="_contract">ethereum game item contract</param> public GameItemAdapter(PlasmaComm _plasmaComm, GameID _game, GameItemContract _contract) { contract = _contract; game = _game; plasmaComm = _plasmaComm; }
/// <summary> /// Constructor of erc721 game item adapter /// </summary> /// <param name="_plasmaComm">plasma communication</param> /// <param name="_game">game that manages these items</param> /// <param name="_contract">ethereum game item contract</param> public ERC721GameItemAdapter(PlasmaComm _plasmaComm, GameID _game, GameItemContract _contract) : base(_plasmaComm, _game, _contract) { }