Skip to content

Fix remote execution#6

Open
msmarcal wants to merge 1 commit intocoinspark:masterfrom
msmarcal:hotfix/remote-request-fix
Open

Fix remote execution#6
msmarcal wants to merge 1 commit intocoinspark:masterfrom
msmarcal:hotfix/remote-request-fix

Conversation

@msmarcal
Copy link

@msmarcal msmarcal commented Mar 3, 2016

Hi,

I've tested this great script but, when I run it on a Mac OS X box sending request to a externeral bitcoin full node I got following error:

PHP Warning:  file_get_contents(<PATH>/.bitcoin/bitcoin.conf): failed to open stream: No such file or directory in <PATH>/OP_RETURN.php on line 492

It seems OP_RETURN.php is checking for posix_getpwuid even when you set OP_RETURN_BITCOIN_USE_CMD and OP_RETURN_BITCOIN_IP constants

This pull request should fix this.

Thank you for your excellent work!!!

@gidgreen
Copy link
Contributor

gidgreen commented Mar 4, 2016

I'm afraid I don't think that suggestion is right, because that's all in an outer branch where OP_RETURN_BITCOIN_USE_CMD is false. The idea of that code block is to read the user/password/port automatically from the bitcoin.conf file, if they were not specified in the constants at the top.

If you set the OP_RETURN_BITCOIN_PORT, OP_RETURN_BITCOIN_USER and OP_RETURN_BITCOIN_PASSWORD constants at the the top, you won't need this.

But still you're right that there's an issue there, in that it's not calculating the location of bitcoin.conf directly on Mac OS X, and that's what I think needs solving.

@msmarcal
Copy link
Author

msmarcal commented Mar 4, 2016

Hi gidgreen,

Sorry.. I meant I set OP_RETURN_BITCOIN_USE_CMD to false and, still then it is searching for a local bitcoin install configuration.

I think it is happening in linux boxes also. I'll test it.

My planning is submitting transactions to an external node.

br,

@msmarcal
Copy link
Author

msmarcal commented Mar 4, 2016

Hi!

I've tested on a Linux box.

I'm afraid OP_RETURN is only working when you have a local bitcoin node installed.
It only worked when I patched it.

Please see below my testing details:

Testing box:

Linux ---HIDDEN---.telecorp.com.br 3.10.0-229.14.1.el7.x86_64 #1 SMP Tue Sep 15 15:05:51 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

My constans:

      define('OP_RETURN_BITCOIN_IP', '---HIDDEN---'); // IP address of your bitcoin node
        define('OP_RETURN_BITCOIN_USE_CMD', false); // use command-line instead of JSON-RPC?

        if (OP_RETURN_BITCOIN_USE_CMD) {
                define('OP_RETURN_BITCOIN_PATH', '/usr/bin/bitcoin-cli'); // path to bitcoin-cli executable on this server

        } else {
                define('OP_RETURN_BITCOIN_PORT', ''); // leave empty to use default port for mainnet/testnet
                define('OP_RETURN_BITCOIN_USER', 'bitcoinrpc'); // leave empty to read from ~/.bitcoin/bitcoin.conf (Unix only)
                define('OP_RETURN_BITCOIN_PASSWORD', '---HIDDEN---'); // leave empty to read from ~/.bitcoin/bitcoin.conf (Unix only)
        }

Simple testing execution

$ php store-OP_RETURN.php TESTING
PHP Warning:  file_get_contents(/home/msmarcal/.bitcoin/bitcoin.conf): failed to open stream: No such file or directory in /home/msmarcal/php-OP_RETURN/OP_RETURN.php on line 492
PHP Stack trace:
PHP   1. {main}() /home/msmarcal/php-OP_RETURN/store-OP_RETURN.php:0
PHP   2. OP_RETURN_store() /home/msmarcal/php-OP_RETURN/store-OP_RETURN.php:46
PHP   3. OP_RETURN_bitcoin_check() /home/msmarcal/php-OP_RETURN/OP_RETURN.php:115
PHP   4. OP_RETURN_bitcoin_cmd() /home/msmarcal/php-OP_RETURN/OP_RETURN.php:453
PHP   5. file_get_contents() /home/msmarcal/php-OP_RETURN/OP_RETURN.php:492
Error: Please check Bitcoin Core is running and OP_RETURN_BITCOIN_* constants are set correctly

@gidgreen
Copy link
Contributor

gidgreen commented Mar 4, 2016

If you set OP_RETURN_BITCOIN_PORT as well, that should solve the problem?

@msmarcal
Copy link
Author

msmarcal commented Mar 4, 2016

Setting OP_RETURN_BITCOIN_PORT to 18333:

define('OP_RETURN_BITCOIN_IP', '----HIDDEN---'); // IP address of your bitcoin node
        define('OP_RETURN_BITCOIN_USE_CMD', false); // use command-line instead of JSON-RPC?

        if (OP_RETURN_BITCOIN_USE_CMD) {
                define('OP_RETURN_BITCOIN_PATH', '/usr/bin/bitcoin-cli'); // path to bitcoin-cli executable on this server

        } else {
                define('OP_RETURN_BITCOIN_PORT', '18333'); // leave empty to use default port for mainnet/testnet
                define('OP_RETURN_BITCOIN_USER', 'bitcoinrpc'); // leave empty to read from ~/.bitcoin/bitcoin.conf (Unix only)
                define('OP_RETURN_BITCOIN_PASSWORD', '----HIDDEN----); // leave empty to read from ~/.bitcoin/bitcoin.conf (Unix only)
        }

I get:

$ php store-OP_RETURN.php TESTING
Error: Please check Bitcoin Core is running and OP_RETURN_BITCOIN_* constants are set correctly

@gidgreen
Copy link
Contributor

gidgreen commented Mar 4, 2016

Unless you're using testnet, the RPC port should be 8332. For testnet, 18332.

@msmarcal
Copy link
Author

msmarcal commented Mar 4, 2016

I am using testnet. Testing with 18332:

$ php store-OP_RETURN.php TESTING
TxIDs:
03a70e6d73634bd44bb9c3ed453a5bbb63c3f7ac02d2d325290cae3a926c0047

Ref: 000101-042755

Wait a few seconds then check on: http://coinsecrets.org/

It's working when you have ALL constants set.

Note you check default port to 18332 when it isn't set:

LINE 507:

if (!strlen($port))
   $port=$testnet ? 18332 : 8332;

@gidgreen
Copy link
Contributor

gidgreen commented Mar 4, 2016

OK, so you need 18332 which is the RPC port number, not the P2P port number.

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.

2 participants