예제 #1
0
        public async Task <Sp8deTransaction> Create(ProtocolTransaction request, UserInfo userInfo)
        {
            var contributorCommit = await contributorService.Commit();

            await ProcessFee(userInfo);

            return(null);
        }
예제 #2
0
        public async Task <ActionResult <GameStartResponse> > Start([FromBody] GameStartRequest model)
        {
            switch (model.Type)
            {
            case GameType.Dice:
                if (model.Bet == null || model.Bet.Length < 1 || model.Bet.Length > 5 || model.Bet.Any(x => x < 1 || x > 6))
                {
                    return(BadRequest(ErrorResult.Create("Invalid Bet")));
                }
                break;

            case GameType.TossCoin:
                if (model.Bet == null || model.Bet.Length != 1 || model.Bet.Single() < 0 || model.Bet.Single() > 1)
                {
                    return(BadRequest(ErrorResult.Create("Invalid Bet")));
                }
                break;

            default:
                throw new NotImplementedException();
            }

            var commit = await randomContributorService.Commit(DateTime.UtcNow.Ticks.ToString());

            var list = new List <SignedItem>
            {
                new SignedItem()
                {
                    Type   = UserType.Contributor,
                    PubKey = model.PubKey,
                    Nonce  = model.Nonce.ToString(),
                    Sign   = model.Sign
                },
                commit.ToSignedItem()
            };

            var tx = await protocol.CreateTransaction(list, ChaosProtocolSettings.ByGameType(model.Type));

            var rs = new GameStartResponse()
            {
                GameId       = Guid.NewGuid().ToString("n"),
                ValidationTx = tx.Id,
                GameType     = model.Type,
                Bet          = model.Bet,
                BetAmount    = model.BetAmount,
                Items        = tx.Items,
                IpfsHash     = tx.Anchor?.Data
            };

            var game = cache.Set(rs.GameId, rs);

            return(rs);
        }