Exemple #1
0
        public async Task <ActionResult <GameFinishResponse> > End([FromBody] GameFinishRequest model)
        {
            var game = cache.Get <GameStartResponse>(model.GameId);

            if (game == null)
            {
                return(NotFound());
            }

            var requesterCommit = game.Items.First(x => x.Type == UserType.Requester);

            var revealItem = await randomContributorService.Reveal(requesterCommit);

            var list = new List <RevealItem>
            {
                new RevealItem()
                {
                    Type   = UserType.Contributor,
                    PubKey = model.PubKey,
                    Nonce  = model.Nonce.ToString(),
                    Seed   = model.Seed,
                    Sign   = model.Sign
                },
                revealItem
            };

            var tx = await protocol.RevealTransaction(game.ValidationTx, list);

            var seedItems = tx.Items.Select(x => x.Seed).ToArray();

            var seed = SharedSeedGenerator.CreateSharedSeed(seedItems);

            DemoGameLogic(game, seed, out int[] winNumbers, out decimal winAmount, out bool isWinner);

            return(new GameFinishResponse()
            {
                GameId = model.GameId,
                SharedSeedArray = seed.seedArray,
                SharedSeedHash = seed.seedHash,
                ValidationTxHash = tx.Id, //TODO
                Items = list,

                IsWinner = isWinner,
                WinAmount = winAmount,
                WinNumbers = winNumbers,

                IpfsHash = tx.Anchor?.Data
            });
        }
Exemple #2
0
        public async Task <Sp8deTransaction> AggregatedReveal(ProtocolTransaction request, UserInfo userInfo, Sp8deTransaction original)
        {
            var createRequest = new CreateTransactionRequest()
            {
                Type      = Sp8deTransactionType.AggregatedReveal,
                DependsOn = request.DependsOn
            };

            var rtx = original.InternalTransactions.First(x => x.Type == Sp8deTransactionType.InternalValidator);

            createRequest.InnerTransactions = request.Items.Select(x => MapToInternalTransaction(x)).ToList();

            var validatorCommit = new SignedItem()
            {
                Type = UserType.Validator, PubKey = rtx.From, Nonce = rtx.Nonce, Sign = rtx.Sign
            };

            var reveal = await contributorService.Reveal(validatorCommit);

            createRequest.InnerTransactions.Add(new InternalTransaction()
            {
                Type  = MapUserType(reveal.Type),
                From  = reveal.PubKey,
                Nonce = reveal.Nonce,
                Sign  = reveal.Sign,
                Data  = reveal.Seed
            });

            createRequest.AddOriginalRandomSettings(original.InputData?.Items);
            createRequest.AddExtended(request.Extended);

            var result = await transactionNode.AddTransaction(createRequest);

            await ProcessFee(userInfo);

            return(result);
        }