Bitcoin Forum
May 24, 2024, 10:14:35 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: [1]
1  Bitcoin / Bitcoin Technical Support / Re: sendtoaddress sending 0 amount every time PHP on: September 05, 2019, 07:35:08 AM
So I used createwallet and created a sender wallet and a receiver wallet to test with where I will mine to the sender wallet and try sending it to the receiver address. From here I'm not sure how to switch between wallets. I have 3 wallet.dat files now, two of which are in folders regtest/wallets/sender and regtest/wallets/receiver so I'm assuming bitcoind automatically grabs the wallet.dat in regtest/wallets/wallet.dat. How do I switch between receiver and senders wallet.dat's to test this? I tried looking at this link of outdaated calls to see if there is an RPC call for it, theres not in the outdated API:

https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list

The link to the updated list does not list API calls. It has the header that says it but its blank then moves on to hash byte order:

https://bitcoin.org/en/developer-reference#bitcoin-core-apis
2  Bitcoin / Bitcoin Technical Support / Re: sendtoaddress sending 0 amount every time PHP on: September 04, 2019, 05:26:45 AM
In electrum you can send transactions to other addresses in your wallet and it transfers it all to the new address, how come its not doing this behavior in regtest CLI? The coins are not stored in that address, when I use generatetoaddress I use a different address than the one I'm sending it to.

I'll try using createwallet
3  Bitcoin / Bitcoin Technical Support / Re: sendtoaddress sending 0 amount every time PHP on: September 03, 2019, 10:03:32 PM
Still the same issue when I send to address generated with legacy flag (produces address that begins with an m instead of one that begins with a 2). I think it has to do with this. How do I make it not send from the same address?

Code:
"details": [
    {
      "address": "mgt64uGFQHg6Q6hw6NBK2ZQib3zqek7CHQ",
      "category": "send",
      "amount": -15.00000000,
      "label": "-addresstype",
      "vout": 1,
      "fee": -0.00006720,
      "abandoned": false
    },
    {
      "address": "mgt64uGFQHg6Q6hw6NBK2ZQib3zqek7CHQ",
      "category": "receive",
      "amount": 15.00000000,
      "label": "-addresstype",
      "vout": 1
    }
  ],
4  Bitcoin / Bitcoin Technical Support / Re: sendtoaddress sending 0 amount every time PHP on: September 03, 2019, 04:22:17 AM
I use getnewaddress to generate my addresses, how do I set the type of address?
5  Bitcoin / Bitcoin Technical Support / Re: sendtoaddress sending 0 amount every time PHP on: September 03, 2019, 03:40:27 AM
this may be another bug in bitcoin core similar to decoderawtransaction which fails to decode transactions containing witnesses properly unless you explicitly pass a Boolean (true) to tell it the transaction is a SegWit one. https://bitcointalk.org/index.php?topic=5014781.0

try using a legacy transaction and see if the amount you get is zero again. this means use a regular address like a P2PKH (address starting with 1 on mainnet) and spend coins from that address. if you don't see the same problem then it must be the bug i mentioned.

How do I do that in regtest mode? I'm using the current version.
6  Bitcoin / Bitcoin Technical Support / Re: sendtoaddress sending 0 amount every time PHP on: September 02, 2019, 10:48:30 PM
I'm using regtest where I have my own private blockchain not testnet. I have a balance of like 700 BTC in addresses I generated because I mined several hundred blocks.
7  Bitcoin / Bitcoin Technical Support / Re: Checking Address Balance with Bitcoin Core on: September 02, 2019, 10:21:15 PM
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?
8  Bitcoin / Bitcoin Technical Support / Re: sendtoaddress sending 0 amount every time PHP on: September 02, 2019, 08:26:05 PM
I dont think its the library, just tried sending a transaction using the cli with same result.

Code:
./bitcoin-cli -regtest sendtoaddress [address] 2.1

Returns a transaction ID, then when I run

Code:
./bitcoin-cli -regtest gettransaction [txid]

The amount still says 0..

This is my most recent return for gettransaction:

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"

It's looking like its maybe sending and receiving to the same address which I dont know how its possible because I literally just generated the address with getnewaddress.
9  Bitcoin / Bitcoin Technical Support / sendtoaddress sending 0 amount every time PHP on: September 02, 2019, 07:52:37 PM
So using the easybitcoin.php library I'm making a test wallet controller for regtest. I have it working to generate blocks and new addresses but transactions arent working properly. I have a form that sends which address and which amount and the script is as follows for processing the transaction:

Code:
	$amount= (float) number_format($_POST['amount'], 8);
$bitcoin->settxfee(0.0004);
$txid = $bitcoin->sendtoaddress($_POST['sendTo'], $amount);

Doing that when I get txinfo I get a txid and all that but the amount is 0 every time. Same if I used the code like this:

Code:
	$amount= $_POST['amount'];
$bitcoin->settxfee(0.0004);
$txid = $bitcoin->sendtoaddress($_POST['sendTo'], (float) $amount);

This is very frustrating as it makes it difficult to test my app. I also hard coded 3.32 for example so it was a float to begin with and still the transaction is sent with a 0 amount. What is going on?


Code:
	$bitcoin->settxfee(0.0004);
$txid = $bitcoin->sendtoaddress($_POST['sendTo'], 3.32);

All of them I get a $txid and using $txinfo = gettransaction($txid) I can get the txid using $txinfo['txid'] but $txinfo['amount'] always returns as 0.
10  Bitcoin / Bitcoin Technical Support / Re: Checking Address Balance with Bitcoin Core on: August 29, 2019, 11:47:00 PM
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.
11  Bitcoin / Bitcoin Technical Support / Re: Checking Address Balance with Bitcoin Core on: August 28, 2019, 08:41:48 PM
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?
12  Bitcoin / Bitcoin Technical Support / Re: Checking Address Balance with Bitcoin Core on: August 27, 2019, 11:53:12 PM
Ok, so I wrote PHP scripts for blocknotify and wallet notify along with the needed tables. So when I generate new blocks and send bitcoin to a generated address I can see in the regtest error log that the scripts arent working:

Code:
AddToWallet 3449dc56136cd9d5cc74a639f2a08ab7141ee0fdcabf41672fcb3e41975eb5cf  new
runCommand error: system(/home/bitcoin/blocknotify.php 40ecf86e83735ca8d1b8d95cdcd54bdd94f885efcd291374bb666d369ccdcf01) returned 65280

I see that for every new block generated and also the same for the script for walletnotify. My table is empty so I dont think the script is even running. I set walletnotify and blocknotify in bitcoin.conf and just start the daemon using ./bitcoind -regtest -daemon

Is there a way that I'm supposed to type it differently because I'm using PHP? I'm assuming its because .php files are not executables. I could write an executable but right now I'm basically just making a proof of concept in PHP because its faster to do so. Also, how would I check for error logs for my PHP scripts if theres syntax errors and such? I'm assuming they wont be in the same place as PHP error logs for site code because its being run from bitcoind rather than my server software. I'm using Debian Linux.

This is my bitcoin.conf

Code:
rpcuser=user
rpcpassword=password
regtest=1
blocknotify=/home/bitcoin/blocknotify.php %s
walletnotify=/home/bitcoin/walletnotify.php %s

I've tried adding php -f before the location of the file but still same error.
13  Bitcoin / Bitcoin Technical Support / Re: Checking Address Balance with Bitcoin Core on: August 27, 2019, 10:03:25 AM
With walletnotify I'd just get a new transaction and I can use the tx info to determine which address it goes towards and update in mysql the number of transactions for that order, however I want to handle cases where users need to send multiple transactions to the address for example if the first transaction wasnt enough to pay the whole tab. II was thinking use blocknotify then search my database for all orders with less than required confirmations and have orders associated with the address for the order. With multiple transactions, using one confirmations field in the database doesnt work so whats a strategy I could use to keep track of all the different transactions for each address/order? I'd have to keep track of all the transactions confirmations in a separate table and associate them with the order ID in the table keeping track of orders wouldnt I?

I'm kind of having trouble coming up with how to handle block notify since it sends block hash instead of tx hash.
14  Bitcoin / Bitcoin Technical Support / Re: Checking Address Balance with Bitcoin Core on: August 27, 2019, 09:23:32 AM
So I just thought about it, what would I do in the case that my node went down and wasnt running for all the new transactions or blocks? Would it just skip over those notifications or handle them when the node restarts?

When I use listtransactions does it list all transactions in the block or just transactions in that block for my addresses associated with my xpub?

15  Bitcoin / Bitcoin Technical Support / Re: Checking Address Balance with Bitcoin Core on: August 09, 2019, 04:50:06 AM
Well, you'd call the script with the transaction id as a parameter:

Code:
walletnotify=/path/to/your/script %s

And inside of your script (shell, php, whatever..), you could call
Code:
bitcoin-cli gettransaction $TX

to get all necessary data from the transaction.

Afterwards process the data as you need and/or fill your database.


You wouldn'd directly check whether address X received a transaction, but you'd call that script upon receiving any transaction.
Then using gettransaction, you'd get all necessary information (receiving address, amount, etc.. ) for further processing.

So when walletnotify runs the script where do I get the transaction ID from to use $TX in gettransaction? What happens if theres multiple transactions at once? Will it just run multiple instances or will $tx be returned as an array?
16  Bitcoin / Bitcoin Technical Support / Re: Checking Address Balance with Bitcoin Core on: August 08, 2019, 11:57:45 AM
So how do I check if that specific address had a transaction? After walletnotify tells the bash script to go, what methods do I use to check specific addresses vs the whole wallets balance?
17  Bitcoin / Bitcoin Technical Support / Re: Checking Address Balance with Bitcoin Core on: August 08, 2019, 11:34:41 AM
Quote
Why don't you use the master public key to derive public keys and addresses while the private keys are in cold storage ?
That way, you would directly accept payments into your cold wallet and would save on transaction fees.

Was most likely going to do this in deployment environment. Was just going to add extra functionality to send to single address if I wanted it stored in one address for whatever reason.

Quote
You could use walletnotify to get notified each time the state of your wallet changes (i.e. transaction received, transaction sent, first confirmation on a TX).
That'd be more efficient than having a cronjob checking the addresses each X seconds/minutes.

If I have thousands of transactions couldnt that cause performance issues if theres payments in many addresses in very short periods of time? I'm trying to build it to scale from the beginning.
18  Bitcoin / Bitcoin Technical Support / Checking Address Balance with Bitcoin Core on: August 08, 2019, 11:04:08 AM
I have an online store and already accept CC payments and I want to start accepting crypto. I'm using the regtest to test the application and so I can't rely on third party APIs plus I feel doing that will hurt at scaling. I'm trying to set it up where each new order will have its own address and I'll have a cronjob periodically check if the address received the payment then send money to cold storage wallet as follows:

Generate address -> receive payment -> wait for confirmations -> send coins to cold storage and show confirmed payment

Currently I save the address in a database associated with the order and generate it using getnewaddress(). I'm stuck on checking the balance of said address and how many confirmations the payment has. I saw accounts looked kind of like what I was looking for but its deprecated so I cant use that. I looked into using blockchain.info JSON API but then with scaling I have to worry about request limits and if I'm trying to request information on too many addresses at once I think it will result in an error. 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 then the addresses that received enough confirmation switch order to paid in database and send coins to cold storage wallet off of server. Plus I'm trying to test it in regtest mode so obviously I cant use a 4rd party API. I saw listunspent() after manually adding addresses and rescanning the chain but I feel if you have thousands of orders and addresses it will be very inefficient every time the job is run and slow the server down.

What is a solution to what I'm trying to accomplish?

I'm very tech savvy and am interested in the be my own bank aspect so I'm not trying to use third party processors or use blockchain.info's wallet API.
Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!