nbobtc / bitcoind-php Goto Github PK
View Code? Open in Web Editor NEWLow level PHP wrapper around bitcoind
License: MIT License
Low level PHP wrapper around bitcoind
License: MIT License
Example output with debugging code shows multiple CurlDrivers can cause problems - destructing one destroys the $ch, but leaves an Unknown resource there.
destruct CurlDriver #1: 0000000041738a1d000000001283de3d
/home/bitcoin/git/bitcoind-php/src/Http/Driver/CurlDriver.php:37:
resource(91) of type (curl)
- closed curl
destruct CurlDriver #2: 0000000041738a16000000001283de3d
/home/bitcoin/git/bitcoind-php/src/Http/Driver/CurlDriver.php:37:
resource(91) of type (Unknown)
This had a pretty sinister effect on my tests - https://travis-ci.org/Bit-Wasp/bitcoin-php/builds/290376696 - HHVM notices there is a null object pointer and breaks, PHP just segfaults or runs out of memory. Some more debugging will tell me if travis's environment is interacting with something here, (or if curl can be patched to notice improper usage) but interesting that I don't seem to get the issues locally..
Submitting a test case that I see passes on 2.x
branch, but fails on the latest tagged release.
Could you tag a release please? :)
Currently the responses are returned as PHP objects. Example: $object->info
I think it would be useful to have an option in the client to return responses as array.
I prefer responses to be returned as array. Example: $object['info']
Returning as json would be useful as well, since this is what bitcoind returns.
For some reason after update to 2.x-dev version getContents() always empty.
Empty here:
$command = new \Nbobtc\Command\Command($command, $options);
$response = $client->sendCommand($command);
$contents = $response->getBody()->getContents();
Work fine with __toString():
$command = new \Nbobtc\Command\Command($command, $options);
$response = $client->sendCommand($command);
$contents = $response->getBody()->__toString();
Not sure how it broken, maybe you have some ideas?
As i see nothing changed, but old code doesn't work 😣
I can run these commands with curl in command line. But can not with php code.
Is there a way to safe some lines of code?
As example:
$command = new \Nbobtc\Command\Command;
$client = new \Nbobtc\Http\Client('http://***:***@localhost:18332');
$command = new $command('validateaddress', $request->input('address'));
$response = $client->sendCommand($command);
$contents = json_decode($response->getBody()->getContents());
if($contents->result->isvalid) {
$command = new $command('getnewaddress', 'foo');
$response = $client->sendCommand($command);
$contents = json_decode($response->getBody()->getContents());
print_r($response);
}
so is there a shorter way to get the result?
travis-ci is building PR's, but doesn't post any status on the pull request.
The php://temp
stream is not read from the beginning without issuing a seek command.
There are some unexpected consequences of this behavior.
For example, calling $response->getBody()->getContents()
twice will return null the second time.
It could be a good idea for such noobies as as me to add require_once
installation instructions. Its real pain in the ass to figure out how to start working with lib.
I've downloaded it through git clone. Then I've created php file and added two main (as I think) files
require_once Nt_Path::get()->scripts . '/btc/lib/Http/Client.php';
require_once Nt_Path::get()->scripts . '/btc/lib/Command/Command.php';
but it doesnt work, I assume it should be added somehow else... but how?
Im trying to use the library in pretty old zend framework, is there an easy require way of installing it?
How to catch an exception which for example may occur when bitcoind is offline?
Wasn't able to solve this by using:
private function getAddress(){
//...prepare connection
try{
$response = $client->sendCommand($command);
return json_decode($response->getBody()->getContents());
}
catch(Exception $e){
return json_encode([
'errors' => 'server offline',
]);
}
Given that new RPC commands were added over time which are not available in all Bitcoin Core versions, some form of categorization would be helpful.
I ran into problems with the curl driver.
I iterate through some addresses and fire the 'getreceivedbyaddress' command. The first address gave me the correct output but as soon as I get to the second address I get:
[ErrorException]
curl_close(): supplied resource is not a valid cURL handle resource
[ErrorException]
curl_setopt_array(): supplied resource is not a valid cURL handle resource
I commented the following line from the destructor and then everything works like a charm.
public function __destruct()
{
if (null !== self::$ch) {
// curl_close(self::$ch);
}
}
obvious I can also set self::$ch to null...
I do not understand why this is. curl_close always throws this exception after the first command. No matter when I call it. any clue?
Just installed with composer (as a vendor in a cakephp 3 project), received this error at the first try:
Fatal error: Declaration of Nbobtc\Http\Message\Message::withBody() must be compatible with Psr\Http\Message\MessageInterface::withBody(Psr\Http\Message\StreamInterface $body) in ****\vendor\nbobtc\bitcoind-php\src\Http\Message\Message.php on line 18
the psr http-message module was updated recently, maybe it was a major update. There is no streamableinterface any more as I see, but could not resolve the error by trying to make it compatible (renaming and stuff), just more errors occured..
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.