예제 #1
0
        public void OnReceive(Address source, Address destination, string symbol, BigInteger amount)
        {
            if (!Runtime.HasGenesis)
            {
                return;
            }

            Runtime.Expect(symbol == DomainSettings.FuelTokenSymbol, "cannot accept this token");
            Runtime.Expect(amount > 0, "invalid amount");

            Runtime.Expect(source.IsUser, "can only accept fuel from user addresses");

            string leaderboardName = SESLeaderboardName;
            var    leaderboard     = (Leaderboard)Runtime.CallContext(NativeContractKind.Ranking, "GetLeaderboard", leaderboardName).ToObject();

            var currentSeason = GetSeason();

            if (currentSeason != _lastSeason)
            {
                FinishSeason();
            }

            BombEntry entry;

            if (_entries.ContainsKey <Address>(source))
            {
                entry = _entries.Get <Address, BombEntry>(source);
                if (entry.round > leaderboard.round)
                {
                    entry.amount = 0;
                    entry.round  = leaderboard.round;
                }
                else
                {
                    Runtime.Expect(entry.round == leaderboard.round, "invalid round on bomb entry");
                }
            }
            else
            {
                entry = new BombEntry()
                {
                    amount = 0,
                    round  = leaderboard.round
                };
            }

            entry.amount += amount;
            _entries.Set <Address, BombEntry>(source, entry);

            Runtime.CallContext(NativeContractKind.Ranking, "InsertScore", this.Address, source, leaderboardName, entry.amount);
        }
예제 #2
0
        public void OnReceive(Address from, string symbol, BigInteger amount)
        {
            if (!Runtime.Nexus.HasGenesis)
            {
                return;
            }

            Runtime.Expect(symbol == DomainSettings.FuelTokenSymbol, "cannot accept this token");
            Runtime.Expect(amount > 0, "invalid amount");

            string leaderboardName = SESLeaderboardName;
            var    leaderboard     = (Leaderboard)Runtime.CallContext(NativeContractKind.Ranking, "GetLeaderboard", leaderboardName).ToObject();

            BombEntry entry;

            if (_entries.ContainsKey <Address>(from))
            {
                entry = _entries.Get <Address, BombEntry>(from);
                if (entry.round > leaderboard.round)
                {
                    entry.amount = 0;
                    entry.round  = leaderboard.round;
                }
                else
                {
                    Runtime.Expect(entry.round == leaderboard.round, "invalid round on bomb entry");
                }
            }
            else
            {
                entry = new BombEntry()
                {
                    amount = 0,
                    round  = leaderboard.round
                };
            }

            entry.amount += amount;
            _entries.Set <Address, BombEntry>(from, entry);

            Runtime.CallContext(NativeContractKind.Ranking, "InsertScore", this.Address, from, leaderboardName, entry.amount);
        }