Skip to content

Instantly share code, notes, and snippets.

@superllama
Last active August 5, 2021 14:14
Show Gist options
  • Save superllama/fc826d475a2adee091e02adc3e48956c to your computer and use it in GitHub Desktop.
Save superllama/fc826d475a2adee091e02adc3e48956c to your computer and use it in GitHub Desktop.
A work-in-progress PowerShell script that helps me generate CSV files for tracking Minds.com Off-Chain transactions in CoinTracker, because I'm crazy
param([Parameter(Mandatory=$true)][string]$csv)
$out = new-object Object[](0)
Write-Host 'Go to minds in firefox, filter Network tab by ''ledger'' and visit the transactions page, scroll until all are loaded.'
$i = 1;
while ($true) {
Write-Host "Right-click item #$i and choose Copy->Copy Response, then press any key to process it. Press Enter instead when finished."
$key = $host.UI.RawUI.ReadKey()
if ($key.Character -eq "`0" -or $key.Character -eq "`t") {continue;}
if ($key.VirtualKeyCode -eq 13) {break;}
$x = (get-clipboard)
$page = ($x | convertfrom-json).transactions | % {
$o = [pscustomobject]@{
'Date' = [DateTimeOffset]::FromUnixTimeSeconds($_.timestamp).UtcDateTime.ToString('MM/dd/yyyy hh:mm:ss');
'Received Quantity' = ''; 'Received Currency' = ''; 'Sent Quantity' = ''; 'Sent Currency' = ''; 'Fee Amount' = ''; 'Fee Currency' = ''; 'Tag' = ''
}
$__ = $_
$act = ''
switch ($_.contract) {
'offchain:reward' {
$o.Tag = 'payment'
$act = 'recv'
}
'offchain:joined' {
$o.Tag = 'payment'
$act = 'recv'
}
'offchain:boost' {
$o.Tag = ''
$act = 'send'
}
}
switch ($act) {
'recv' {
if ($__.amount -match "(\d*)(\d{$([Math]::Min($__.amount.Length,18))})`$") {
$o.'Received Currency' = 'MINDS'
$amt = "0$($matches[1]).$(('0'*18+$matches[2])[-18..-1]-join'')"
$o.'Received Quantity' = [double]$amt
} else {
$__ | out-host
}
}
'send' {
if ($__.amount -match "-(\d*)(\d{$([Math]::Min($__.amount.Length,18))})`$") {
$o.'Sent Currency' = 'MINDS'
$amt = "0$($matches[1]).$(('0'*18+$matches[2])[-18..-1]-join'')"
$o.'Sent Quantity' = [double]$amt
} else {
$__ | out-host
}
}
}
$o
}
$page | out-host
$out += $page
$i++
}
(($out | convertto-csv -NoTypeInformation) -replace '"','') -join "`n" | out-file $csv -NoNewline -Encoding utf8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment