Exemple #1
0
        public void ValidateValue(ulong commission)
        {
            var len      = (Transfers?.Count ?? 0) + (Stakes?.Count ?? 0);
            var outValue = commission * GasPrice * (ulong)len;

            if (Transfers != null)
            {
                outValue = Transfers.Aggregate(outValue, (current, txOut) =>
                                               current + txOut.Value);
            }

            if (Stakes != null)
            {
                outValue = Stakes.Aggregate(outValue, (current, txOut) =>
                                            current + txOut.Value);
            }

            if (Messages != null)
            {
                outValue = Messages.Aggregate(outValue, (current, txOut) =>
                                              current + txOut.Value + txOut.Gas * GasPrice);
            }

            var inValue = Inputs.Aggregate((ulong)0, (current, txIn) =>
                                           current + txIn.Value);

            if (inValue != outValue)
            {
                throw new Exception($"Wrong sum in transaction, inValue: {inValue}, outValue: {outValue}");
            }
        }
        public ActionResult Main(bool isStatic, int?id)
        {
            short state;

            Game[]    table;
            GameState currentGameState = new GameState();

            if (isStatic)
            {
                if (id == null)
                {
                    id = 0;
                }
                table = Unit.PokerBetSrvc.GetTableById(id.Value);
                state = 3;
                // currentGameState = Unit.PokerBetSrvc.GetCurrentState();
            }
            else
            {
                table        = Unit.PokerBetSrvc.GetTable(out state);
                currentState = state;
                if (state == 0 && !hasRiverFinderStarted)
                {
                    stakes = new Stakes();
                    hasRiverFinderStarted = true;
                }
                if (state == 3 && hasRiverFinderStarted)
                {
                    hasRiverFinderStarted = false;
                    riverNumber           = Unit.PokerBetSrvc.GetBestPrizeNumber(table);
                }
                currentGameState = Unit.PokerBetSrvc.GetCurrentState();
            }

            string finalWinners = "";

            JObject mainJson =
                new JObject(
                    CreateGameJSON(table[2], state, 2, isStatic, ref finalWinners),
                    new JProperty("timestamp", currentGameState == null ? 0 : currentGameState.StartTime.Second),
                    CreateGameJSON(table[0], state, 0, isStatic, ref finalWinners),
                    CreateGameJSON(table[1], state, 1, isStatic, ref finalWinners),
                    new JProperty("ts", (DateTime.Now - currentGameState.StartTime).TotalSeconds)
                    );

            if (state == 0 && firstTimeHistoryAdd == true)
            {
                firstTimeHistoryAdd = false;
                finalWinners        = "";
            }

            if (state == 3 && !String.IsNullOrEmpty(finalWinners) && firstTimeHistoryAdd == false)
            {
                firstTimeHistoryAdd = true;
            }

            return(Content(mainJson.ToString(Newtonsoft.Json.Formatting.None)));
        }
Exemple #3
0
 public TransactionRequest AddStake(string address, ulong value, string nodeId)
 {
     Stakes ??= new List <StakeDto>();
     Stakes.Add(new StakeDto
     {
         Address = address,
         Value   = value,
         NodeId  = nodeId,
     });
     return(this);
 }