Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: Option to print BTC transactions #176

Closed
wants to merge 3 commits into from
Closed

DRAFT: Option to print BTC transactions #176

wants to merge 3 commits into from

Conversation

webwarrior-ws
Copy link
Contributor

Added --print-transactions option that for given Bitcoin
address prints all incoming transactions in reverse
chronological order.
Data printed: BTC amount, USD amount, date.

@knocte
Copy link
Member

knocte commented Oct 26, 2022

CI is broken @webwarrior-ws . Moving forward please don't create a PR yet if CI on your fork is not green yet.

<Reference Include="SharpRaven">
<HintPath>..\..\packages\SharpRaven.2.4.0\lib\net471\SharpRaven.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Configuration" />
<Reference Include="System.Net.Http" />
<!-- FIXME: we should not need to reference ResultUtils at all when we can upgrade to F#v4.5 across the board (all CI lanes) -->
<Reference Include="ResultUtils">
<HintPath>..\..\packages\DotNetLightning.Kiss.1.1.2-date20220322-1031-git-5379324\lib\netstandard2.0\ResultUtils.dll</HintPath>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webwarrior-ws you're not using DNL in this PR so why do you add this? we told you to remove unnecessary changes from the PR please, review the PR changes yourself before telling us that you finished

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed reference to ResultUtils

@@ -111,12 +137,89 @@ type public ElectrumServerReturningInternalErrorException(message: string, code:
originalRequest: string, originalResponse: string) =
inherit ElectrumServerReturningErrorException(message, code, originalRequest, originalResponse)

type StratumClient (jsonRpcClient: JsonRpcTcpClient) =
module StratumRequestSerializer =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webwarrior-ws same thing with this change, which seems to be a refactoring done in the LN branch (08fc3e5) but not needed for this PR because this PR doesn't have tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the module is used in BlockchainScriptHashHistory and BlockchainTransactionGetVerbose methods, which were not present before and so don't have "old" versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webwarrior-ws then convert the BlockchainScriptHashHistory and BlockchainTransactionGetVerbose methods into old ones, it's very very very simple and the diff for the PR would be much smaller

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converted the methods to "old style" and minimized changes in StratumClient

<package id="FSharp.Core" version="4.7.0" targetFramework="net471" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="5.0.0" targetFramework="net472" />
<package id="Microsoft.Extensions.Logging.Abstractions" version="1.0.2" targetFramework="net471" />
<package id="NBitcoin" version="6.0.17" targetFramework="net471" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webwarrior-ws this PR shouldn't need Frontend.Console adding NBitcoin as a dependency. I know you can figure out how to prevent this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved all logic to backend and removed all added dependencies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved all logic to backend and removed all added dependencies.

Thanks. Also can you rebase this PR to get CI green please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. CI is green.


if not (Seq.isEmpty incomingOutputs) then
let amount = incomingOutputs |> Seq.sumBy (fun txOut -> txOut.Value)
let dateTime = DateTime(1970, 1, 1) + TimeSpan.FromSeconds(float transaction.Time)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webwarrior-ws what's this magic number?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start of UNIX epoch

Copy link
Member

@knocte knocte Nov 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that; it's my way to say you have to create a variable called unixEpoch, this is programming 101

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

let bitcoinAmount = amount.ToDecimal(NBitcoin.MoneyUnit.BTC)
Console.WriteLine(SPrintF1 "~USD amount: %s" ((bitcoinAmount * price).ToString("F2")))
| None ->
Console.WriteLine("Could not get bitcoin price for the date")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webwarrior-ws no more explanation? if this happens to any user, he would file a bug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the program prints exception that occurred when fetching bitcoin price

@@ -480,5 +480,7 @@ let main argv =
UpdateServersFile()
| 1 when argv.[0] = "--update-servers-stats" ->
UpdateServersStats()
| 2 when argv.[0] = "--print-transactions" ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webwarrior-ws let's tweak this feature, if there's a number after the flag --print-transactions then you would only print that number of transactions (e.g. --print-transactions 3 would only print the last 3 transactions instead of continuing to print all).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

open GWallet.Backend.UtxoCoin


module BTCTransactionPrinting =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webwarrior-ws please rename to BtcTransactionPrinting and move it to UtxoCoin folder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@webwarrior-ws
Copy link
Contributor Author

CI failure on Windows seems to be completely unrelated

@webwarrior-ws
Copy link
Contributor Author

Fixed indentation in .fsproj file

@knocte knocte force-pushed the master branch 3 times, most recently from fc34810 to a887996 Compare December 23, 2022 06:04
@knocte
Copy link
Member

knocte commented Jan 3, 2023

@webwarrior-ws 2 last things to do here (while you're waiting for CI on the other task):

  • Please rebase this PR with latest master in order to achieve green CI. After that:
  • Please develop this small feature (in a 2nd commit, do not squash with 1st): when user writes a parameter for maxTransactionsCount, for example 2, check if the last 2 transactions have the same addresses as outputs (e.g. tx 1 outputs are 3: sends to address A, which belongs to wallet, and to address B and C, which don't belong to wallet; tx2 outputs are 3: sends to address A, which belongs to wallet, and to address B and D, which don't belong to the wallet), and if that is the case, put info about the TOTAL amount being sent, in tx1: A+B amount and percentage of each amount (e.g. 75% to A, 25% to B), and tx2: A+B amount and percentage of each amount (e.g. 65% to A, 35% to B).

Blockstream electrum servers don't support sending verbose
transactions (see [1]), and we use this functionality to get
confirmations of a transaction; so we prevent a crash by
blacklisting them.

[1] Blockstream/electrs#36
@knocte
Copy link
Member

knocte commented Jan 4, 2023

I gave this a go today, I found 2 issues @webwarrior-ws , see this example output (where I cut addresses with <snip/> for privacy):

% mono src/GWallet.Frontend.Console/bin/Debug/GWallet.Frontend.Console.exe --print-transactions 2 39...<snip/>
BTC amount: 0.02800286
~USD amount: 478.88
date: ... UTC

BTC amount: 0.02321512
~USD amount: 391.20
date: ... UTC

Transactions with shared outputs:
Transaction with outputs to NBitcoin.TxOut, NBitcoin.TxOut
Date: ... PM UTC
Total BTC: 0.03634679
Sent 0.00134309 BTC to bc1qp...(snip) (3.70%)
Sent 0.00700074 BTC to bc1q1...(snip) (19.26%)

Transaction with outputs to NBitcoin.TxOut, NBitcoin.TxOut
Date: 8/12/2022 8:33:59 PM UTC
Total BTC: 0.03034462
Sent 0.00132585 BTC to bc1qp...(snip) (4.37%)
Sent 0.00580375 BTC to bc1q1...(snip) (19.13%)

The two issues are:

  • The percentages are wrong, because their total is not 100%.
  • Most importantly, address 39...<snip/> is not included in the final summary titled Transactions with shared outputs, it should be included!

@webwarrior-ws just a reminder, this is a low-priority task, you should only work on this when you're waiting for CI for your high-priority task. Thanks Taras, good progress so far.

Added --print-transactions option that for given Bitcoin
address prints all incoming transactions in reverse
chronological order.
Data printed: BTC amount, USD amount, date.
When called with --print-transactions and number of
transactions is specified, if there are outputs shared between
all transactions, print amount and percentage for each such
output in each transaction.
@knocte knocte force-pushed the master branch 2 times, most recently from 1a3be72 to 265b103 Compare October 16, 2023 05:05
@knocte knocte changed the title Option to print BTC transactions DRAFT: Option to print BTC transactions Feb 2, 2024
@knocte knocte force-pushed the master branch 2 times, most recently from b841302 to ccb1641 Compare May 8, 2024 09:18
@webwarrior-ws webwarrior-ws closed this by deleting the head repository May 23, 2024
@webwarrior-ws
Copy link
Contributor Author

Superseded by #295

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants