Skip to content

Instantly share code, notes, and snippets.

@polarker
Created December 13, 2021 11:25
Show Gist options
  • Save polarker/a21491d2d5aab1b5f2306b5f8b6f9b6e to your computer and use it in GitHub Desktop.
Save polarker/a21491d2d5aab1b5f2306b5f8b6f9b6e to your computer and use it in GitHub Desktop.
#credit to @diomark
#credit to @mwferris
# Put your details here:
$walletName = "WALLET_NAME"
$unlockWallet = 0 # swap to 1 if you want to auto unlock wallet
$walletPassword = "WALLET_PASSWORD" # only needed if unlocking wallet in script
$apiKey = "0000000000000000000000000000000000000000000000000000000000000000"
$headers = @{
'accept'='*/*'
'X-API-KEY'=$($apiKey)
}
# unlock wallet
if($unlockWallet -eq 1){
$body = @{ password=$walletPassword } | ConvertTo-Json
Invoke-RestMethod -Method Post -Uri "http://127.0.0.1:12973/wallets/$($walletName)/unlock " `
-ContentType "application/json" -Headers $headers -Body $body
}
#check wallet
$oldBalance = Invoke-RestMethod -Method Get -Uri "http://127.0.0.1:12973/wallets/$($walletName)/balances" `
-ContentType "application/json" -Headers $headers | Select-Object -ExpandProperty TotalBalanceHint
Write-Output "Current balance: $($oldBalance)"
$oldDate=Get-Date
while($true) {
Write-Host "." -NoNewLine
$newBalance=Invoke-RestMethod -Method Get -Uri "http://127.0.0.1:12973/wallets/$($walletName)/balances" `
-ContentType "application/json" -Headers $headers | Select-Object -ExpandProperty TotalBalanceHint
if($oldBalance -ne $newBalance) {
$newDate=Get-Date
$msg="`nWon a block after $($(($newDate - $oldDate).TotalMinutes).tostring("#")) minutes!"
" $($msg) Current balance: $($newBalance) " | Write-Output
$oldDate=$newDate
$oldBalance = $newBalance
}
Start-Sleep 30
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment