示例#1
0
        /// <summary>
        /// Withdraws the sold item
        /// </summary>
        /// <param name="from">Withdrawing profile</param>
        /// <param name="tokenAddress">type of sold item</param>
        /// <param name="tokenId">identifier of sold item</param>
        /// <returns></returns>
        public async Task <bool> WithdrawERC721(Profile from, string tokenAddress, BigInteger tokenId)
        {
            var function = GetFunctionWithdrawTokenERC721();
            var receipt  = await BCComm.EvaluateOnBC(web3, from, function, tokenAddress, tokenId);

            return(receipt.Status.Value == 1);
        }
示例#2
0
        /// <summary>
        /// Consumes an order and pays for the ERC721 Items
        /// </summary>
        /// <param name="from">Profile of the buyer</param>
        /// <param name="tokenGet">currency</param>
        /// <param name="amountGet">price in currency</param>
        /// <param name="tokenGive">item to buy</param>
        /// <param name="tokenId">identifier of ERC721 item to buy</param>
        /// <param name="expires">expiration date of the order</param>
        /// <param name="nonce">transaction identifier</param>
        /// <param name="orderOwner">order's creator</param>
        /// <param name="amount">must be 1</param>
        /// <returns></returns>
        public async Task <bool> TradeERC721(
            Profile from,
            string tokenGet,
            BigInteger amountGet,
            string tokenGive,
            BigInteger tokenId,
            BigInteger expires,
            BigInteger nonce,
            string orderOwner,
            BigInteger amount)
        {
            var testTradeFun = GetFunctionTestTradeERC721();

            var test = await testTradeFun.CallAsync <bool>(
                tokenGet,
                amountGet,
                tokenGive,
                tokenId,
                expires,
                nonce,
                orderOwner,
                amount,
                from.ID);

            if (!test)
            {
                return(false);
            }

            var function = GetFunctionTradeERC721();
            var receipt  = await BCComm.EvaluateOnBC(web3, from, function, tokenGet, amountGet, tokenGive, tokenId, expires, nonce, orderOwner, amount);

            return(receipt.Status.Value == 1);
        }
        /// <summary>
        /// Creates new instance of BCGameItemProvider for a particular game using supplied blockchain communication interfase
        /// </summary>
        /// <param name="game"></param>
        /// <param name="comm"></param>
        public BCGameItemProvider(GameID game, IBCComm comm)
        {
            Game   = game;
            BCComm = (BCComm)comm;

            RegisterContractInterfaceID(ERC223GameItemContract.InterfaceID, typeof(ERC223GameItemContract));
            RegisterContractInterfaceID(ERC721GameItemContract.InterfaceID, typeof(ERC721GameItemContract));
        }
示例#4
0
        public async Task <bool> Transfer(Profile from, string to, BigInteger amount)
        {
            var function = GetFunctionTransfer();

            object[] functionInput = { to.RemoveHexPrefix(), amount };
            var      receipt       = await BCComm.EvaluateOnBC(web3, from, function, functionInput);

            return(receipt.Status.Value == 1);
        }
示例#5
0
        /// <summary>
        /// Removes admin from game contract
        /// </summary>
        /// <param name="adminAddr">Admin address</param>
        /// <param name="profile">signer profile</param>
        /// <returns></returns>
        public async Task <TransactionReceipt> RemoveAdminAsync(string adminAddr, Profile profile)
        {
            if (profile.ID == adminAddr)
            {
                throw new HoardException("Can't remove my self");
            }
            var function = GetFunctionRemoveAdmin();

            return(await BCComm.EvaluateOnBC(web3, profile, function, adminAddr));
        }
        /// <summary>
        /// Transfers <paramref name="amount"/> of <paramref name="item"/> from account <paramref name="from"/>
        /// to address <paramref name="addressTo"/>
        /// </summary>
        /// <param name="from">Account of items owner</param>
        /// <param name="addressTo">address of destination account</param>
        /// <param name="item">item to transfer</param>
        /// <param name="amount">amount of items to transfer</param>
        /// <returns></returns>
        public override async Task <bool> Transfer(Profile from, string addressTo, GameItem item, BigInteger amount)
        {
            var        function = GetFunctionTransfer();
            BigInteger tokenId  = (item.Metadata as ERC721GameItemContract.Metadata).ItemId;

            object[] functionInput = { from.ID.ToString(), addressTo.RemoveHexPrefix(), tokenId };
            var      receipt       = await BCComm.EvaluateOnBC(web3, from, function, functionInput);

            return(receipt.Status.Value == 1);
        }
示例#7
0
        public bool UpdateItemState(GameItem gameItem, Profile profile)
        {
            ERC721GameItemMockContract contract = (ERC721GameItemMockContract)BCComm.GetGameItemContract(gameItem.Game, ItemContracts[gameItem.Symbol].Address, typeof(ERC721GameItemMockContract));

            if (contract != null)
            {
                contract.SetTokenState(((ERC721GameItemContract.Metadata)gameItem.Metadata).ItemId, gameItem.State, profile).Wait();
                return(true);
            }
            return(false);
        }
示例#8
0
        /// <summary>
        /// Cancels ERC721 order
        /// </summary>
        /// <param name="from">Profile that cancels order (must be creator of order)</param>
        /// <param name="tokenGet">currency</param>
        /// <param name="amountGet">price</param>
        /// <param name="tokenGive">item to sell</param>
        /// <param name="tokenIdGive">identifier of item to sell</param>
        /// <param name="expires">expiration date</param>
        /// <param name="nonce">transaction number</param>
        /// <returns></returns>
        public async Task <bool> CancelOrderERC721(
            Profile from,
            string tokenGet,
            BigInteger amountGet,
            string tokenGive,
            BigInteger tokenIdGive,
            BigInteger expires,
            BigInteger nonce)
        {
            var function = GetFunctionCancelOrderERC721();
            var receipt  = await BCComm.EvaluateOnBC(web3, from, function, tokenGet, amountGet, tokenGive, tokenIdGive, expires, nonce);

            return(receipt.Status.Value == 1);
        }
示例#9
0
        /// <summary>
        /// Creates a trade order for an ERC223 tokens in currency expressed in ERC233 tokens
        /// </summary>
        /// <param name="from">seller profile</param>
        /// <param name="tokenGet">type of currency</param>
        /// <param name="amountGet">price in given currency</param>
        /// <param name="tokenGive">type of token to sell</param>
        /// <param name="amountGive">amount of tokens to sell</param>
        /// <param name="blockTimeDuration">expiration time of order in block number</param>
        /// <returns>true if order has been created, false otherwise</returns>
        public async Task <bool> Order(
            Profile from,
            string tokenGet,
            BigInteger amountGet,
            string tokenGive,
            BigInteger amountGive,
            ulong blockTimeDuration)
        {
            // FIXME: should NOT take nonce from web3
            var        nonceService = new InMemoryNonceService(from.ID, web3.Client);
            BigInteger nonce        = await nonceService.GetNextNonceAsync();

            var blockNumber = await web3.Eth.Blocks.GetBlockNumber.SendRequestAsync();

            var expires = blockNumber.Value + blockTimeDuration;

            var function = GetFunctionOrder();
            var receipt  = await BCComm.EvaluateOnBC(web3, from, function, tokenGet, amountGet, tokenGive, amountGive, expires, nonce);

            return(receipt.Status.Value == 1);
        }
示例#10
0
        /// <summary>
        /// Adds game item contract address
        /// </summary>
        /// <param name="address">Item contract address</param>
        /// <param name="profile">signer profile</param>
        /// <returns></returns>
        public async Task <TransactionReceipt> AddGameItemAsync(string address, Profile profile)
        {
            var function = GetFunctionAddGameItemContract();

            return(await BCComm.EvaluateOnBC(web3, profile, function, address));
        }
示例#11
0
        /// <summary>
        /// Sets new Game Server URL in contract
        /// </summary>
        /// <param name="url">new URL of Game Server</param>
        /// <param name="profile">signer profile</param>
        /// <returns>receipt of the transaction</returns>
        public async Task <TransactionReceipt> SetGameServerURLAsync(string url, Profile profile)
        {
            var function = GetFunctionSetGameServerURL();

            return(await BCComm.EvaluateOnBC(web3, profile, function, url));
        }
        /// <summary>
        /// Sets contract to be the Hoard Token
        /// </summary>
        /// <param name="address">Hoard Token contract address</param>
        /// <param name="profile">payer</param>
        /// <returns></returns>
        public async Task <TransactionReceipt> SetHoardTokenAddress(string address, Profile profile)
        {
            var function = GetFunctionSetHoardTokenAddress();

            return(await BCComm.EvaluateOnBC(web3, profile, function, address));
        }
        /// <summary>
        /// Adds new game to game center
        /// </summary>
        /// <param name="gameAddr">addres of game contract</param>
        /// <param name="profile">profile that will pay for transaction</param>
        /// <returns></returns>
        public async Task <TransactionReceipt> AddGame(string gameAddr, Profile profile)
        {
            var function = GetFunctionAddGame();

            return(await BCComm.EvaluateOnBC(web3, profile, function, gameAddr));
        }
示例#14
0
 public BCGameItemMockProvider(GameID game, BCComm comm) : base(game, comm)
 {
     RegisterContractInterfaceID(ERC721GameItemMockContract.InterfaceID, typeof(ERC721GameItemMockContract));
 }
示例#15
0
        public async Task <TransactionReceipt> SetTokenState(BigInteger tokenID, byte[] tokenState, Profile profile)
        {
            Function function = GetFunctionSetTokenState();

            return(await BCComm.EvaluateOnBC(web3, profile, function, tokenID, tokenState));
        }
示例#16
0
        public async Task <TransactionReceipt> MintToken(string ownerAddress, BigInteger tokenID, byte[] tokenState, Profile profile)
        {
            Function function = GetFunctionMintToken();

            return(await BCComm.EvaluateOnBC(web3, profile, function, ownerAddress, tokenID, tokenState));
        }