Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Bitcoin in perl

by grondilu (Friar)
on Sep 06, 2012 at 04:48 UTC ( #992000=CUFP: print w/replies, xml ) Need Help??

Hello monks,

First things first, if you do not know what bitcoin is: it is a decentralized monetary system created in 2009. Check out wikipedia to know more.

If you do know what bitcoin is but you do not like the idea for some political/economic/whatever reason, please just ignore this message and spare yourself some time by not trolling uselessly.

If you are still here, you may be interested in a bitcoin perl library I've been working on for some time now, though my work has been kind of halted in recent weeks.

So far, it is only on GitHub. There is also a perl6 version but it can not read the bitcoin database. I may put everything on CPAN one day, if it ever becomes a substantial project. But right now it's probably too messy and needs a lot of tidying up.

My ultimate goal with this was initially to rewrite the whole bitcoin code in Perl. Unfortunately, my lack of competence in network programming, in addition to a small excess of laziness, prevented me from reaching this goal.

Still, I do believe this library is kind of neat. You can use it to create new bitcoin addresses (so yeah, you can use it to receive actual bitcoins), sign or verify messages, scrutinize the block chain, and so on.

Here is a quick snapshot of the kind of stuff you can do:

use Bitcoin; my $key = new Bitcoin::Key; say $key->address; use Bitcoin::Block; say my $block = new Bitcoin::Block Bitcoin::Constants::GENESIS;

And other stuff, such as making raw transactions, but this has not been tested much yet.

Tell me what you think guys, and if you might be interested in contributing, let me know.

Replies are listed 'Best First'.
Re: Bitcoin in perl
by Mr. Muskrat (Canon) on Sep 06, 2012 at 13:52 UTC

      I knew only the first one you're mentionning.

      Finance::Bitcoin iirc is an API to the main server bitcoind daemon.

      The second one seems only about scripting.

      The third one seems to be much closer to what I attemtped. I didn't know about it and I should check it out.

      Yes, I should have looked for existing stuff before posting. Sorry.

        Competing libraries can be a good thing. The secret to success is to make your own do something that the others doesn't, to do the same things better or with a superior interface. :)

        "Finance::Bitcoin iirc is an API to the main server bitcoind daemon"

        I'm its author, and yes, that's exactly what it is.

        perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: Bitcoin in perl
by cavac (Deacon) on Sep 11, 2012 at 17:47 UTC

    That's a very interesting project. I played with the idea of parsing all past bitcoin transactions into a PostgreSQL database to fool around with the dataset and test some theories.

    I didn't have the time and energy to really find out how to parse the blocks and such. Could i parse all the transaction data with your modules?

    Warning: completly reimplementing a complete bitcoin client in pure Perl isn't something i would recommend. While 99% of the port would make sense to me (hey, i wrote my own webserver in Perl...), i really recommend that you use existing cryptographic libraries whereever possible. Cryptography is very, very, very hard to get right and extremly easy to mess up. You may ask "kroeckx" from the Debian team who did a little patch for the Debian team, which has had a few unintended side effects.

    You can find quite a few examples of why cryptography either works perfectly or not at all on the net. For example, the yearly Chaos Communications Congress has quite a few examples including this one which also explains a few things about bitcoin.

    "I know what i'm doing! Look, what could possibly go wrong? All i have to pull this lever like so, and then press this button here like ArghhhhhaaAaAAAaaagraaaAAaa!!!"

      Yes, normally you should be able to parse the transaction data. It has only been tested with a few blocks but normally everything can be red. It even recognises transaction scripts and tries to decompile them. For instance, it will see if the embedded data is pure ASCII text. That's how for instance the times headline can be explicitely seen when you read the genesis block.

      So, assuming your transaction is in the binary string $tx, the following code should work, but you'll have to convert it into Bitcoin::DataStream first (I haven't made that automatic)

      use Bitcoin::Transaction; use YAML; my $stream = new Bitcoin::DataStream $tx; say +Dump Bitcoin::Transaction->new($stream);

      I did use cryptographic libraries for digests, but I've found no perl library for ECDSA, and I've found using C libraries with XS or something much too complicated for me.

Re: Bitcoin in perl
by Anonymous Monk on Sep 28, 2012 at 17:02 UTC
    If you're familiar with XS/C, a Perl interface to this C library would be cool:

      Unfortunately I'm not familiar enough with XS. And to me it seems quite tough to learn.

      I know about the library you're talking about though. It's discussed here on the bitcoin forum, but I guess you know that already. This guy has done quite an impressive work. You made me remember that there is already a Perl6 module that allows linking with C libraries. I'll see if I can make this work.

      XS isn't too bad. I could do it, if I though enough people actually wanted it.
Re: Bitcoin in perl
by Anonymous Monk on Oct 25, 2012 at 05:38 UTC
    If this is going to eventually wind up on CPAN, please make it compatible with earlier perl versions. 5.14 is relatively new. I have many machines that are restricted to 5.10 and I even know quite a few people that are stuck on 5.8.

    Also, BerkeleyDB can be a pain to install on many systems without manual intervention: . Unfortunately there doesn't appear to be an alternative interface. And even when Bitcoin makes the switch to leveldb, it will still use BDB for the wallet.

Re: Bitcoin in perl
by Favioflamingo (Novice) on Jun 29, 2014 at 14:13 UTC

    Hello all! I am not sure if a perl module exists that makes calls to cbitcoin yet. I have started work on this in case anyone else is working on this:

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://992000]
Front-paged by tye
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2018-07-20 03:36 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (424 votes). Check out past polls.