Skip to content

Instantly share code, notes, and snippets.

@lontivero
Created July 28, 2023 13:34
Show Gist options
  • Save lontivero/5d04491c7e6768c47118126821cc1954 to your computer and use it in GitHub Desktop.
Save lontivero/5d04491c7e6768c47118126821cc1954 to your computer and use it in GitHub Desktop.

This script lists the rounds in output registration phase that seems to be ready for signing.

The math for accurate detection is not here, instead we use a difference less than 3% (because this is a PoC).

    $ dotnet fsi ready.fsx
    87cc3a2a909f5efc0ebce1c6ef4e26d0992c5cc62dc7865fff66936c6e006f7e can be signed because diff is 75.45730076 - 75.45593750 = 0.00136326
    87cc3a2a909f5efc0ebce1c6ef4e26d0992c5cc62dc7865fff66936c6e006f7e can be signed because diff is 75.45730076 - 75.45593750 = 0.00136326
    87cc3a2a909f5efc0ebce1c6ef4e26d0992c5cc62dc7865fff66936c6e006f7e can be signed because diff is 75.45730076 - 75.45593750 = 0.00136326
    87cc3a2a909f5efc0ebce1c6ef4e26d0992c5cc62dc7865fff66936c6e006f7e can be signed because diff is 75.45730076 - 75.45593750 = 0.00136326

Note: The script uses the WasabiWallet.dll so, make sure to compile it and specify the right path to it.

#r "WalletWasabi.dll"
#r "Newtonsoft.Json"
#r "NBitcoin"
open System
open System.Net.Http
open System.Threading
open WalletWasabi
open WalletWasabi.WabiSabi.Client
open WalletWasabi.WebClients.Wasabi
open WalletWasabi.WabiSabi.Models
open WalletWasabi.Tor.Http
open WalletWasabi.WabiSabi.Backend.Rounds
open NBitcoin
let httpClient = new HttpClient()
httpClient.BaseAddress <- Uri "https://api.wasabiwallet.io/"
let clearNetHttpClient = ClearnetHttpClient(httpClient)
let wabisabiClient = WabiSabiHttpApiClient clearNetHttpClient
let rec queryRounds () = async {
let! status =
wabisabiClient.GetStatusAsync(RoundStateRequest.Empty, CancellationToken.None)
|> Async.AwaitTask
status.RoundStates
|> Array.filter (fun x -> x.Phase = Phase.OutputRegistration)
|> Array.map (
fun r ->
let inputsSum = r.CoinjoinState.Inputs |> Seq.sumBy (fun x -> x.Amount)
let outputsSum = r.CoinjoinState.Outputs |> Seq.sumBy (fun x -> x.Value)
r, inputsSum, outputsSum )
|> Array.filter (fun (_, is, os) -> is - os < Money.Satoshis(decimal is.Satoshi * 0.03m))
|> Array.iter (
fun (r, is, os) ->
Console.WriteLine $"{r.Id} can be signed because diff is {is} - {os} = {is - os}")
do! Async.Sleep (TimeSpan.FromSeconds 1)
do! queryRounds()
}
queryRounds ()
|> Async.RunSynchronously
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment