Ejemplo n.º 1
0
        static void CheckCoinJoinRoundStatus()
        {
            try
            {
                var wasabiApiEndpoint = Config.Get <string>("WASABI_BOT_WASABI_URL");
                var satoshiClient     = new SatoshiClient(new Uri(wasabiApiEndpoint));
                var states            = satoshiClient.GetAllRoundStatesAsync().GetAwaiter().GetResult();
                var state             = states.First();

                Logger.Info("Checking coinjoin round status");
                if (IsNewStateImportant(state))
                {
                    var tweetContent = $"@WasabiWallet's just helped another {state.RegisteredPeerCount} people improve their financial privacy. {Config.Get<string>("WASABI_BOT_TAGS")}";
                    Logger.Info($"Tweeting: {tweetContent}");

                    try
                    {
                        if (!CanTweet)
                        {
                            return;
                        }

                        ExceptionHandler.SwallowWebExceptions = false;
                        Auth.SetUserCredentials(
                            Config.Get <string>("WASABI_BOT_TWITTER_CONSUMER_KEY"),
                            Config.Get <string>("WASABI_BOT_TWITTER_CONSUMER_SECRET"),
                            Config.Get <string>("WASABI_BOT_TWITTER_USER_ACCESS_TOKEN"),
                            Config.Get <string>("WASABI_BOT_TWITTER_USER_ACCESS_SECRET"));

                        var tweet = Tweet.PublishTweet(tweetContent);

                        if (tweet != null && tweet.IsTweetPublished)
                        {
                            Logger.Info($"Tweet url {tweet.Url}");
                        }
                        else
                        {
                            Logger.Error($"Tweet was not published!!!");
                        }

                        CanTweet = false;
                        Worker.QueueOneTime("Do not tweet the same twice",
                                            () => CanTweet = true,
                                            TimeSpan.FromSeconds(60));
                    }
                    catch (Exception e)
                    {
                        Logger.Error("Error tweeting coinjoin status.", e);
                    }
                }
                previousState = state;
            }
            catch (Exception e)
            {
                Bot.Logger.Error($"Error during executing scheduled task", e);
            }
        }
Ejemplo n.º 2
0
 private static bool IsNewStateImportant(CcjRunningRoundState state)
 {
     return(state.RegisteredPeerCount == state.RequiredPeerCount);
 }