コード例 #1
0
        private void On(CoinEvent e)
        {
            var p = e.Player;

            p.GoldCoins = e.GoldCoins;
            p.BlueCoins = e.BlueCoins;

            var x      = (int)e.X;
            var y      = (int)e.Y;
            var blocks = Blocks.Of(this.BotBits);

            if (!blocks.Area.Contains(new Point(x, y)))
            {
                return;
            }
            var block = blocks.Foreground[x, y].Block.Id;

            switch (block)
            {
            case Foreground.Coin.Gold:
                p.AddGoldCoin(new Point(x, y));
                new GoldCoinEvent(p, e.GoldCoins, x, y)
                .RaiseIn(this.BotBits);
                break;

            case Foreground.Coin.Blue:
                p.AddBlueCoin(new Point(x, y));
                new BlueCoinEvent(p, e.BlueCoins, x, y)
                .RaiseIn(this.BotBits);
                break;
            }
        }
        public async Task MonitoringCoinTransactionJobUnitTest_LostTransactionProcessing()
        {
            string operationId             = "OpId-3";
            QueueTriggeringContext context = new QueueTriggeringContext(DateTimeOffset.UtcNow);
            CoinTransactionMessage coinTransactionMessage = new CoinTransactionMessage()
            {
                PutDateTime     = DateTime.UtcNow,
                TransactionHash = _lostTransactionHash,
                OperationId     = operationId
            };

            #region ArrangeMocks

            ICoinEvent coinEvent = new CoinEvent(operationId,
                                                 _lostTransactionHash, "from", "to", "1000000000000000000", CoinEventType.TransferStarted, "contractAddress", true);
            _ethereumTransactionService.Setup(x => x.IsTransactionInPool(_lostTransactionHash)).Returns(Task.FromResult(false));
            _coinTransactionService.Setup(x => x.ProcessTransaction(coinTransactionMessage)).Returns(Task.FromResult <ICoinTransaction>(null));
            _coinEventService.Setup(x => x.GetCoinEvent(_lostTransactionHash)).Returns(Task.FromResult <ICoinEvent>(coinEvent));
            _coinEventService.Setup(x => x.PublishEvent(coinEvent, It.IsAny <bool>())).Returns(Task.FromResult(0)).Verifiable();
            _pendingOperationService.Setup(x => x.RefreshOperationByIdAsync(operationId)).Returns(Task.FromResult(0)).Verifiable();

            #endregion

            MonitoringCoinTransactionJob job = GetJob();
            await job.Execute(coinTransactionMessage, context);

            _coinEventService.Verify(x => x.PublishEvent(coinEvent, It.IsAny <bool>()), Times.Never);
            _pendingOperationService.Verify(x => x.RefreshOperationByIdAsync(operationId), Times.Once);
        }
コード例 #3
0
ファイル: Lineage.cs プロジェクト: swdee/Terab
        /// <summary>
        /// New production event is consistent if and only if none existing
        /// event comes from ancestry block.
        /// New consumption event is consistent if only if any existing
        /// production event comes from ancestry block, and not yet consumed
        /// in the chain determined by this production block.
        /// </summary>
        public bool IsAddConsistent(Span <CoinEvent> events, CoinEvent toAdd)
        {
            if (toAdd.Kind == CoinEventKind.Production)
            {
                foreach (var coinEvent in events)
                {
                    if (IsAncestor(toAdd.BlockAlias, coinEvent.BlockAlias))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            bool hasBeenProduced = false;

            foreach (var coinEvent in events)
            {
                if (IsAncestor(toAdd.BlockAlias, coinEvent.BlockAlias))
                {
                    if (coinEvent.Kind == CoinEventKind.Production)
                    {
                        hasBeenProduced = true;
                    }
                    else
                    {
                        // already consumed in this chain.
                        return(false);
                    }
                }
            }

            return(hasBeenProduced);
        }
        public async Task MonitoringCoinTransactionJobUnitTest_TransactionIsInBlockchainSenhdEvent()
        {
            string operationId             = "OpId-2";
            QueueTriggeringContext context = new QueueTriggeringContext(DateTimeOffset.UtcNow);
            CoinTransactionMessage coinTransactionMessage = new CoinTransactionMessage()
            {
                PutDateTime     = DateTime.UtcNow,
                TransactionHash = _commitedTransactionHash,
                OperationId     = operationId
            };

            #region ArrangeMocks
            ICoinTransaction coinTransaction = new CoinTransaction()
            {
                ConfirmationLevel = 1,
                TransactionHash   = _commitedTransactionHash
            };
            ICoinEvent coinEvent = new CoinEvent(operationId,
                                                 _commitedTransactionHash, "from", "to", "1000000000000000000", CoinEventType.TransferStarted, "contractAddress", true);
            _ethereumTransactionService.Setup(x => x.IsTransactionInPool(_commitedTransactionHash)).Returns(Task.FromResult(false));
            _coinTransactionService.Setup(x => x.ProcessTransaction(coinTransactionMessage)).Returns(Task.FromResult <ICoinTransaction>(coinTransaction));
            _coinEventService.Setup(x => x.GetCoinEvent(_commitedTransactionHash)).Returns(Task.FromResult <ICoinEvent>(coinEvent));
            _coinEventService.Setup(x => x.PublishEvent(coinEvent, It.IsAny <bool>())).Returns(Task.FromResult(0)).Verifiable();

            #endregion

            MonitoringCoinTransactionJob job = GetJob();
            await job.Execute(coinTransactionMessage, context);

            _coinEventService.Verify(x => x.PublishEvent(coinEvent, It.IsAny <bool>()), Times.Once);
        }
コード例 #5
0
        private void OnCoin(CoinEvent e)
        {
            Player p = e.Player;

            p.GoldCoins = e.GoldCoins;
            p.BlueCoins = e.BlueCoins;
        }
コード例 #6
0
 public FatCoin(Coin coin, CoinEvent production)
 {
     _coinBuffer = new byte[coin.Span.Length];
     coin.Span.CopyTo(_coinBuffer);
     Events = new List <CoinEvent> {
         production
     };
 }
コード例 #7
0
        private void On(CoinEvent e)
        {
            var bytes = new byte[this.Size];

            Buffer.BlockCopy(new[] { e.GoldCoins, e.BlueCoins }, 0, bytes, 0, 8);
            Buffer.BlockCopy(new[] { e.X, e.Y }, 0, bytes, 8, 8);
            this.Receive?.Invoke(this, new Message <Player>(e.Player, e.Player == this.Players.OwnPlayer, bytes));
        }
コード例 #8
0
        public void PruneTest5()
        {
            Span <CoinEvent> events = stackalloc CoinEvent[2];

            events[0] = new CoinEvent(_2, CoinEventKind.Production);
            events[1] = new CoinEvent(_3, CoinEventKind.Consumption);

            Assert.True(_lineage.IsCoinPrunable(events));
        }
コード例 #9
0
ファイル: LineageTests.cs プロジェクト: swdee/Terab
        public void AddConsistencetTest5()
        {
            Span <CoinEvent> events = stackalloc CoinEvent[1];
            var ev = new CoinEvent(_2_0, CoinEventKind.Production);

            events[0] = ev;

            Assert.False(_lineage.IsAddConsistent(events, ev));
        }
コード例 #10
0
ファイル: LineageTests.cs プロジェクト: swdee/Terab
        public void AddConsistentTest3()
        {
            Span <CoinEvent> events = stackalloc CoinEvent[2];

            events[0] = new CoinEvent(_1, CoinEventKind.Production);
            events[1] = new CoinEvent(_1, CoinEventKind.Consumption);

            var consumption = new CoinEvent(_2_0, CoinEventKind.Consumption);

            Assert.False(_lineage.IsAddConsistent(events, consumption));
        }
コード例 #11
0
ファイル: LineageTests.cs プロジェクト: swdee/Terab
        public void ReadConsistentTest3()
        {
            Span <CoinEvent> events = stackalloc CoinEvent[1];

            events[0] = new CoinEvent(_2_0, CoinEventKind.Production);

            var hasEvents = _lineage.TryGetEventsInContext(events, _2_1, out var production, out var consumption);

            Assert.False(production.IsDefined);
            Assert.False(consumption.IsDefined);
            Assert.False(hasEvents);
        }
コード例 #12
0
ファイル: LineageTests.cs プロジェクト: swdee/Terab
        public void ReadConsistentTest1()
        {
            Span <CoinEvent> events = stackalloc CoinEvent[3];

            events[0] = new CoinEvent(_1, CoinEventKind.Production);
            events[1] = new CoinEvent(_2_0, CoinEventKind.Consumption);
            events[2] = new CoinEvent(_2_1, CoinEventKind.Consumption);

            var hasEvents = _lineage.TryGetEventsInContext(events, _2_0, out var production, out var consumption);

            Assert.Equal(production, _1);
            Assert.Equal(consumption, _2_0);
            Assert.True(hasEvents);
        }
コード例 #13
0
    void HandleSpawnCoinEvent(BaseEvent anEvent)
    {
        CoinEvent coinEvent = (CoinEvent)anEvent;

        for (int i = 0; i < myCoinObjects.Count; i++)
        {
            if (myCoinObjects[i].activeSelf == false)
            {
                myCoinObjects[i].transform.position = coinEvent.myPosition;
                myCoinObjects[i].GetComponent <CoinScript>().myGoldValue = coinEvent.myGoldAmount;
                myCoinObjects[i].SetActive(true);
                return;
            }
        }
    }
コード例 #14
0
        public CoinChangeStatus AddConsumption(ulong outpointHash, ref Outpoint outpoint, BlockAlias context,
                                               ILineage lineage)
        {
            if (!_coins.TryGetValue(outpoint, out var fatCoin))
            {
                return(CoinChangeStatus.OutpointNotFound);
            }

            var consumption = new CoinEvent(context, CoinEventKind.Consumption);

            if (fatCoin.Events.Contains(consumption))
            {
                return(CoinChangeStatus.Success);
            }

            fatCoin.Events.Add(consumption);
            return(CoinChangeStatus.Success);
        }
コード例 #15
0
        /// <summary>
        /// Processes the message
        /// </summary>
        /// <param name="connectionBase">The connection base</param>
        /// <param name="message">The playerio message</param>
        /// <param name="handled">Whether the message was already handled</param>
        public void Process(ConnectionBase connectionBase, Message message, bool handled)
        {
            int userId = message.GetInt(0);

            WorldConnection worldCon = (WorldConnection)connectionBase;
            WorldPlayer     player   = worldCon.Players.GetPlayer(userId);

            if (player != null && !handled)
            {
                player.GoldCoins = message.GetInt(1);
                player.BlueCoins = message.GetInt(2);
            }

            CoinEvent coinEvent = new CoinEvent()
            {
                Raw    = message,
                Player = player
            };

            connectionBase.RaiseServerEvent <CoinEvent>(coinEvent);
        }
コード例 #16
0
        public CoinChangeStatus AddProduction(ulong outpointHash, ref Outpoint outpoint, bool isCoinBase, Payload payload,
                                              BlockAlias context, ILineage lineage)
        {
            var production = new CoinEvent(context, CoinEventKind.Production);

            if (_coins.TryGetValue(outpoint, out var fatCoin))
            {
                if (fatCoin.Events.Contains(production))
                {
                    return(CoinChangeStatus.Success); // done
                }
                fatCoin.Events.Add(production);

                return(CoinChangeStatus.Success);
            }

            var coin = new Coin(ref outpoint, isCoinBase, payload, production, _pool);

            _coins.Add(outpoint, new FatCoin(coin, production));

            return(CoinChangeStatus.Success);
        }
コード例 #17
0
 public bool IsAddConsistent(Span <CoinEvent> events, CoinEvent toAdd)
 {
     return(_addConsistentFunc.Invoke());
 }