Bitcoin Forum
November 13, 2019, 05:11:23 AM *
News: Latest Bitcoin Core release: 0.18.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 [2]  All
  Print  
Author Topic: Checking Address Balance with Bitcoin Core  (Read 371 times)
Crypto-Collector
Newbie
*
Offline Offline

Activity: 18
Merit: 11


View Profile
August 28, 2019, 08:41:48 PM
Last edit: August 28, 2019, 08:53:42 PM by Crypto-Collector
 #21

So if I have errors thrown in my script where will I find the error logs? It should be somewhere different because bitcoind is running it and not my web server right?

I added the php executable to my config file and still getting an error

Code:
runCommand error: system(/usr/bin/php /home/bitcoin/script.php d5cab12159ebf0f9df963b972e6c9323477ee822c68e44dc346c20ffa) returned 65280

My table is still empty in my database so the script didnt run (or work). What behavior will it do if the script throws an error?
The Bitcoin Forum is turning 10 years old! Join the community in sharing and exploring the notable posts made over the years.
1573621883
Hero Member
*
Offline Offline

Posts: 1573621883

View Profile Personal Message (Offline)

Ignore
1573621883
Reply with quote  #2

1573621883
Report to moderator
bob123
Legendary
*
Offline Offline

Activity: 1064
Merit: 1571



View Profile WWW
August 29, 2019, 09:44:19 AM
 #22

What bothers me is the return code 65280.

Unfortunately i am not sure what causes this, but it might be a faulty script ? Are you able to call it from the command line properly using /usr/bin/php /home/bitcoin/script.php ?

You might try it with a simple shell script to see whether your php script is the reason or some configuration. Something like this should be enough:
Code:
#!/bin/bash
echo $(date +"%D - %H:%M:%S") >> /tmp/is_it_working

Place it anywhere and change walletnotify to:
Code:
walletnotify=/bin/bash /path/to/test.sh %s

See whether it can be called properly. If so, it should create a file in /tmp and the current time/date should be inside of the file.

If this dummy script is working, your script seems to be faulty. In this case post it somewhere so we can take a look at it. If you don't want to paste it publicly, feel free to PM it to me. I'll try to take a look at it.
If this dummy script isn't working either, some configuration is faulty, but currently not sure what exactly. Permissions maybe ?

Crypto-Collector
Newbie
*
Offline Offline

Activity: 18
Merit: 11


View Profile
August 29, 2019, 11:47:00 PM
Last edit: August 30, 2019, 12:13:10 AM by Crypto-Collector
 #23

Ok, so I reset my bitcoin.conf to run your test script

Code:
rpcuser=user
rpcpassword=password
# Run a regression test network
regtest=1
blocknotify=/bin/bash /home/bitcoin/test.sh %s
walletnotify=/bin/bash /home/bitcoin/test.sh %s

Except that it writes to the same directory the script is in. I did this to test if permissions is the issue. The script ran fine and generated a file with 6 entries of the date after starting daemon, a list transactions call, generating a new address and then sending some coin to it. So permissions arent the issue and the shell script worked. There was also nothing in the regtest debug.log so it's either PHP isnt running or theres an error in my PHP script. Where could I find error logs for my PHP script since bitcoind called it instead of my server? I figured out syntax errors by testing scripts from command line but there were no transactions added to my database. I'm trying to figure out if I have an error in my SQL statements or logic doesnt work or what. I have custom errors that would normally be thrown to my server error logs but as I've said I don't know how to check PHP or MySQL error logs when it was called from bitcoind.
bob123
Legendary
*
Offline Offline

Activity: 1064
Merit: 1571



View Profile WWW
September 01, 2019, 12:39:48 PM
 #24

Alright, so we at least found the issue.
Since core and the config is working fine, we can focus on your php/sql issue.


The way to debug this, would be to run your php script from the command line and give it a (non-existing, randomly chosen or real) transaction ID.
Then see what it does or doesn't do.

I don't think there is an error log being written when these scripts are called from bitcoind.
But you can always create your own log. Either use the logger command or redirect the output from your commands into your own logfile (using >>) (sorry i don't know the php equivalent of these commands).

I think the best way would be to get them running using the command line.
Since you already found some syntax errors in your php script, is it running through completely now ? If so, it could be safe to assume that there is an issue with SQL.
If they are then running through fine via the command line, the next step would be to test them via bitcoind / walletnotify.

Crypto-Collector
Newbie
*
Offline Offline

Activity: 18
Merit: 11


View Profile
September 02, 2019, 10:21:15 PM
 #25

My SQL statement I forgot to include VALUES on INSERT. Fixed that. Now I'm getting amount: 0 for all transactions but it is saving them to my DB. When I use the CLI I get the same problem. When I use sendtoaddress it gives me a txid then when I use gettransaction on the transaction it says amount: 0 every time. This is what I get:

Code:
./bitcoin-cli -regtest gettransaction f8d306e9649aad81e1bac5f1e61cb752f886a0d5340b4ad9ac305fb5027182cc
{
  "amount": 0.00000000,
  "fee": -0.00006640,
  "confirmations": 0,
  "trusted": true,
  "txid": "f8d306e9649aad81e1bac5f1e61cb752f886a0d5340b4ad9ac305fb5027182cc",
  "walletconflicts": [
  ],
  "time": 1567455718,
  "timereceived": 1567455718,
  "bip125-replaceable": "no",
  "details": [
    {
      "address": "2N72hQwNLCXYmDnyBFDXwcUAvppm1bLLzX8",
      "category": "send",
      "amount": -2.40000000,
      "label": "",
      "vout": 0,
      "fee": -0.00006640,
      "abandoned": false
    },
    {
      "address": "2N72hQwNLCXYmDnyBFDXwcUAvppm1bLLzX8",
      "category": "receive",
      "amount": 2.40000000,
      "label": "",
      "vout": 0
    }
  ],
  "hex": "02000000000101519e1d7e4a983b8135148dbb32198e23b7500a407048805bd9ffd97d38fd163300000000171600148e193f47083de7efbe286f289e7034c084a7f70bfeffffff02001c4e0e0000000017a91497333f2c2bdf79ec3637fbef6f331fabb2f451aa8710bcb71b0100000017a914b9d9b20cb6cbf043cae1b361bc391d102dc6d49c870247304402207f71c6bdde891742d274d227f51d9f0e8a0477c2776c057278f035d9606eb0bf022014cb9951b6144462fe7423bf99f137c38846a3c647cf5426b27412ced26a47b201210340ce4e488b13b4c9dedabe231722211a2e4f02237ea347e81b804a714fac2d4500000000"

I'm seeing both a receiving and sending address and its using the same address for both. I thought [details][address] was only there for the receiving address? I'm assuming my regtest config isnt set up right or something and since it says its both sending and receiving it evens out to 0. Why would it have this behavior? The transaction is just to an address I generated using getnewaddress which should automatically have a zero balance so it shouldnt even be able to send to itself?
reardenlife
Jr. Member
*
Offline Offline

Activity: 35
Merit: 10


View Profile
September 04, 2019, 02:31:32 AM
Last edit: September 04, 2019, 02:49:56 AM by reardenlife
 #26

For example, say I have like 4000 orders and the cronjob needs to check all 4000 addresses during the cronjob to get it done efficiently

Had the exact same problem.  Decided not to check the balances on the addresses, but the other way around - to scan the blockchain real-time and see if anything has arrived.  I wrote a simple bash script which is able to scan with a speed of 30 transactions per second.

https://bitcointalk.org/index.php?topic=5181207.msg52352018#msg52352018

I am running bitcoind in pruned mode.  Everything seems to work nice so far.
Pages: « 1 [2]  All
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!