예제 #1
0
        public async Task <int> GetCounter(Atomix.Tezos tezos, string address)
        {
            var rpc = new Rpc(tezos.RpcProvider);

            var head = await rpc
                       .GetHeader()
                       .ConfigureAwait(false);

            return(await GetCounter(tezos, address, head)
                   .ConfigureAwait(false));
        }
예제 #2
0
        public async Task <int> GetCounter(Atomix.Tezos tezos, string address, JObject head)
        {
            var rpc = new Rpc(tezos.RpcProvider);

            var account = await rpc
                          .GetAccountForBlock(head["hash"].ToString(), address)
                          .ConfigureAwait(false);

            var counter = int.Parse(account["counter"].ToString());

            lock (_syncRoot)
            {
                if (_counters.TryGetValue(address, out var offlineCounter))
                {
                    if (offlineCounter.Value > counter &&
                        DateTime.UtcNow - offlineCounter.LastUpdatedTimeUtc <= ExpirationTimeOut)
                    {
                        return(++offlineCounter.Value);
                    }
                    else
                    {
                        ++counter;
                        _counters[address] = new CounterEntry
                        {
                            Value = counter,
                            LastUpdatedTimeUtc = DateTime.UtcNow
                        };

                        return(counter);
                    }
                }
                else
                {
                    ++counter;
                    _counters.Add(address, new CounterEntry
                    {
                        Value = counter,
                        LastUpdatedTimeUtc = DateTime.UtcNow
                    });

                    return(counter);
                }
            }
        }