Exemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] AddPlayerRequest request)
        {
            if (ModelState.IsValid)
            {
                var newPlayer = new Player
                {
                    Id               = Guid.NewGuid(),
                    Email            = request.Email,
                    Nickname         = request.Nickname,
                    LousySecurityKey = Guid.NewGuid()
                };

                _context.Players.Add(newPlayer);
                await _context.SaveChangesAsync();

                return(Ok(newPlayer.LousySecurityKey));
            }

            return(BadRequest());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] InitAccountRequest initRequest)
        {
            if (string.IsNullOrEmpty(initRequest?.Address))
            {
                return(BadRequest());
            }

            var userId = new Guid(User.Claims.Single(cl => cl.Type == ClaimTypes.NameIdentifier).Value);
            var player = _context.Players.Single(x => x.Id == userId);

            player.Address = initRequest.Address;
            await _context.SaveChangesAsync();

            var web3 = new Nethereum.Web3.Web3(_account.Value.Address);

            var txCount = await web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(_account.Value.MasterAccountAddress);

            var encoded = web3.OfflineTransactionSigner.SignTransaction(_account.Value.MasterAccountPrivateKey, initRequest.Address, 10, txCount.Value);

            return(Ok(await web3.Eth.Transactions.SendRawTransaction.SendRequestAsync("0x" + encoded)));
        }