Pages:
Author

Topic: libbitcoin - page 8. (Read 92492 times)

legendary
Activity: 1232
Merit: 1076
February 16, 2012, 11:17:43 PM
So I'm running debian 6.0.4 (squeeze) and trying to get this installed for a small project.

I'm just going to install it on an ubuntu system instead, but figured I would post my error log anyway.

http://pastie.org/private/3jnuenhclxaf4f90wpbyfw


https://bitcoinconsultancy.com/wiki/Build_libbitcoin

Your g++ is outdated.

@znort, try google-protobuf or something. And dont use the boost headers in ubuntu... they are missing async_connect function. Use 1.48 from boostr website as per instructions above.

@Dusty, sure. Use the network component to connect to a bitcoin node, then fashion a get_data packet. Send it to the node and subscribe to either transactions or blocks. Then once you received the block and/or tx, create an exporter object to serialise them and print the bytes to the screen. Hopefully I can get this next tutorial out soon, and it will clarify some points for you. Just been very busy this week with exchange stuff :/ Constantly stressed for time
hero member
Activity: 742
Merit: 500
February 16, 2012, 10:37:00 PM
So I'm running debian 6.0.4 (squeeze) and trying to get this installed for a small project.

I'm just going to install it on an ubuntu system instead, but figured I would post my error log anyway.

http://pastie.org/private/3jnuenhclxaf4f90wpbyfw
hero member
Activity: 731
Merit: 503
Libertas a calumnia
February 15, 2012, 09:09:05 AM
Is there a (even not so) simple way to use this library to dump the raw bytes of a transaction or even a full block?

I.e: something like example #3 of the post above, but in reverse: give the program the hash of a tx so he can get it from the network or the db, and dump it to stdout.

Thanks for any help
legendary
Activity: 1232
Merit: 1076
February 06, 2012, 09:55:42 AM
[libbitcoin] First steps
This tutorial will create a simple program in Python using libbitcoin’s Python bindings to read the version information of a remote bitcoin node. We will need to connect to the bitcoin node and send it a version packet. The other bitcoin node should respond back with their own version packet which we can examine.
legendary
Activity: 1232
Merit: 1076
February 05, 2012, 03:47:45 PM
libbitcoin is licensed as Lesser AGPL:
- When used in the p2p network, you only need to provide changes on demand (LGPL).
- When used on a webserver, you must proactively provide sourcecode for any changes you have made to libbitcoin.
- Applications can link against libbitcoin, and they do not need to release their changes publically.
Thanks to Aaron Williamson of the SFLC and Richard Stallman of the FSF for helping draft up this license.
legendary
Activity: 1232
Merit: 1076
February 04, 2012, 11:07:49 AM
Python bindings + tutorials are going to be released later this week:

Code:
import bitcoin
import time

class Application:

    def __init__(self):
        self.stopped = False
        self.net = bitcoin.network()
        self.channel = None

    def start(self):
        self.net.connect("localhost", 8333, self.handle_connect)

    def stop(self):
        self.stopped = True

    def is_stopped(self):
        return self.stopped

    def create_version_message(self):
        vers = bitcoin.version()
        vers.version = 60000
        vers.services = 1
        vers.address_me.servies = 1
        vers.address_me.ip = \
            [0, 0, 0, 0, 0, 0, 0, 0,
             0, 0, 255, 255, 127, 0, 0, 1]
        vers.address_me.port = 8333
        vers.address_you.services = 1
        vers.address_you.ip = \
            [0, 0, 0, 0, 0, 0, 0, 0,
             0, 0, 255, 255, 127, 0, 0, 1]
        vers.address_you.port = 8333
        vers.user_agent = "/libbitcoin:0.4/example:1/";
        vers.start_height = 0
        vers.nonce = 42
        return vers

    # First we send our version message then the node will reply back
    def handle_connect(self, ec, channel):
        # check the error_code
        if ec:
            print 'Could not connect:', ec
            self.stop()
            return
        self.channel = channel
        version_message = self.create_version_message()
        self.channel.send_version(version_message, self.handle_send)
        self.channel.subscribe_version(self.read_version_reply)

    def handle_send(self, ec):
        if ec:
            print 'Problem sending:', ec
            self.stop()

    def read_version_reply(self, ec, vers):
        if ec:
            print 'Problem in reply:', ec
            self.stop()
            return
        # Display the version message back
        print vers.address_me.ip
        self.stop()

if __name__ == "__main__":
    app = Application()
    app.start()
    while not app.is_stopped():
        time.sleep(0.1)

Some more stuff (crappy/hackish testing files):
Code:
import bitcoin


d = bitcoin.data_chunk("001212")
print d
h = bitcoin.hash_digest("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f")
print h
if h == "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f":
    print 'Yes'
print len(h)

tx = bitcoin.transaction()
print bitcoin.hash_transaction(tx)

netaddr = bitcoin.network_address()
print netaddr.ip

s = bitcoin.script()
o = bitcoin.operation()
o.code = bitcoin.opcode.special
s.push_operation(o)
o.code = bitcoin.opcode.nop
o.data = bitcoin.data_chunk("deadbeef")
s.push_operation(o)
o = bitcoin.operation()
o.code = bitcoin.opcode.hash160
s.push_operation(o)
print s
print s.operations()
print s.type()

Code:
import bitcoin

raw_tx_repr = "010000000187493c4c15c76df9f69ddd7aeb7ffbcddad4b7a979210f19602282d5b9862581000000008a47304402202d9e9f75be9c8a4c4304931b032e1de83fd2c6af2c1154a3d2b885efd5c3bfda02201184139215fb74499eae9c71ae86354c41b4d20b95a6b1fffcb8f1c5f051288101410497d11f5c33adb7c3fed0adc637358279de04f72851b7b93fb4a8655613729047c7e2908966551b5fb7f6899f6c3dd358b57eb20a61b2c9909aa106eac6310f9fffffffff0140420f00000000001976a91407e761706c63b36e5a328fab1d94e9397f40704d88b000000000"
raw_tx = bitcoin.data_chunk(raw_tx_repr)
print raw_tx
print len(raw_tx)

ex = bitcoin.satoshi_exporter()
tx = ex.load_transaction(raw_tx)
print "txhash", bitcoin.hash_transaction(tx)
print tx
print ex.save_transaction(tx)
print len(ex.save_transaction(tx))
assert str(ex.save_transaction(tx)) == raw_tx_repr

Code:
import bitcoin

ec = bitcoin.elliptic_curve_key()
print ec.new_key_pair()
privdat = ec.private_key()
print privdat

ec1 = bitcoin.elliptic_curve_key()
ec1.set_private_key(privdat)
assert str(ec1.private_key()) == str(privdat)

h = bitcoin.hash_digest("f003f0c1193019db2497a675fd05d9f2edddf9b67c59e677c48d3dbd4ed5f00b")
print h
sig = ec1.sign(h)
print ec.verify(h, sig)
sr. member
Activity: 440
Merit: 251
February 02, 2012, 09:23:31 PM
License will now be Lesser AGPL.
You mean the Lesser GPL (LGPL) license, right? http://www.gnu.org/licenses/lgpl.html  To my (very limited) knowledge, a Lesser AGPL license doesn't exist.

Here it is:  http://mo.morsi.org/blog/node/270
legendary
Activity: 1500
Merit: 1022
I advocate the Zeitgeist Movement & Venus Project.
February 02, 2012, 03:55:12 AM
Well done! Looking forward to a richer bitcoin ecosystem.
full member
Activity: 154
Merit: 102
Bitcoin!
February 01, 2012, 11:28:06 PM
Good deal.
legendary
Activity: 1232
Merit: 1076
February 01, 2012, 10:24:34 PM
Red Emerald:
As the codebase matures I'll start adding a ton of comments. The thing I hate more than uncommented code is out of date comments.

License will now be Lesser AGPL.
You mean the Lesser GPL (LGPL) license, right? http://www.gnu.org/licenses/lgpl.html  To my (very limited) knowledge, a Lesser AGPL license doesn't exist.

I'm collaborating with the SFLC/FSF to sort that out. They resolved a bunch of licensing issues for me already.

First tutorial (of many) is written. Just a high level overview. Next one should have some code, and then we'll go back and break everything down as we go along.
[libbitcoin] Overview
libbitcoin is a bitcoin library targeted towards high end use. The library places a heavy focus around asychronicity. The enables a big scope for future scalability as each component has its own thread pool. By increasing the number of threads for that component the library is able to scale outwards across CPU cores. This will be vital in the future as the demands of the bitcoin network grow.

I tried to explain the design principles behind libbitcoin and why things are done how they are.
hero member
Activity: 742
Merit: 500
February 01, 2012, 09:01:42 PM
Keep up the great work.

Reading through this is much easier than trying to read through the Satoshi client although there aren't too many comments (yet (hopefully)).
full member
Activity: 154
Merit: 102
Bitcoin!
February 01, 2012, 06:23:04 PM
License will now be Lesser AGPL.
You mean the Lesser GPL (LGPL) license, right? http://www.gnu.org/licenses/lgpl.html  To my (very limited) knowledge, a Lesser AGPL license doesn't exist.
legendary
Activity: 1232
Merit: 1076
February 01, 2012, 05:49:41 PM
OK, I'm getting ready to finalise a 1.0 release by the end of this month (Feb).

License will now be Lesser AGPL. You can link and use libbitcoin in your closed source project, but the changes you make to libbitcoin must be public. I will give explicit permission through email to people 'myusername'@riseup.net (signed with my GPG key) if you want to be sure.

Will be heavily documenting and writing tutorials soon.

On the development front:
- I have written a blockchain fuzzer which I will use to stress test the blockchain algorithm.
- Node discovery needs to be completed (should be easy- the tricky part is designing a good API).
- A high level synchronous interface for easy programming and integration of bitcoin in your project. This might not make it to 1.0 release. fellowtraveler, this is what you're asking for.

Right now the project is still rough around the edges, but it is rapidly approaching production capability in a rough way. We will have to smooth out some things while using it and the API may change a lot early on. I will also be making a test client as a proof of concept in order to perfect the API better.

libbitcoin requires advanced C++ knowledge (for now). It is heavily built around asynchronous interfaces and the library is thread safe. An understanding of thread contexts is required but I'll document this in the tutorials.
sr. member
Activity: 440
Merit: 251
January 10, 2012, 10:13:04 AM
1. I'm sure there are mining groups now who would accept certain more exotic transaction types.

2. Even if multi-sign isn't accepted yet, I still need to get started on my code, so I still need to see a code sample using your library (preferably.) It will be months before this stuff is fully ready,  IMO.

3. Once low-trust servers are popping up to take advantage of such code, I can almost guarantee you there will be a sea change in the Bitcoin community as various miners, exchanges, et al jump on board.

Need sample code!


------------------------

 
legendary
Activity: 1232
Merit: 1076
January 09, 2012, 07:00:25 AM

Can you please post a code sample of how to perform multi-sign transactions on the blockchain using your library.

This is a necessary piece for me.


Multi-signature transactions are restricted by IsStandard() right now, so you won't be able to use them until 15th Feb. They will be available then.

https://en.bitcoin.it/wiki/BIP_0016

Quote
On February 1, 2012, the block-chain will be examined to determine the number of blocks supporting pay-to-script-hash for the previous 7 days. If 550 or more contain "/P2SH/" in their coinbase, then all blocks with timestamps after 15 Feb 2012, 00:00:00 GMT shall have their pay-to-script-hash transactions fully validated. Approximately 1,000 blocks are created in a week; 550 should, therefore, be approximately 55% of the network supporting the new feature.

If a majority of hashing power does not support the new validation rules, then rollout will be postponed (or rejected if it becomes clear that a majority will never be achieved).
sr. member
Activity: 440
Merit: 251
January 09, 2012, 05:50:10 AM

Can you please post a code sample of how to perform multi-sign transactions on the blockchain using your library.

This is a necessary piece for me.
legendary
Activity: 1232
Merit: 1076
January 08, 2012, 04:30:46 PM
Today we enter a new era with all core components done. But this is not the end. This is the beginning!

Everything is still far from finished:

https://bitcoinconsultancy.com/wiki/index.php?title=Libbitcoin

Services:

- blockchain
-- bdb_blockchain (berkeley db)
-- postgresql_blockchain
- network
- transaction memory pool

Other:

- scripting system
- full validation of blocks and unconfirmed transactions
- all the usual utilities like base58, encryption, hashing

Todo (minor things):

- wallet
- node discovery

Headers:

include/bitcoin/error.hpp
include/bitcoin/address.hpp
include/bitcoin/network/channel.hpp
include/bitcoin/network/discovery.hpp
include/bitcoin/network/handshake.hpp
include/bitcoin/network/shared_const_buffer.hpp
include/bitcoin/network/network.hpp
include/bitcoin/block.hpp
include/bitcoin/data_helpers.hpp
include/bitcoin/exporter.hpp
include/bitcoin/validate.hpp
include/bitcoin/constants.hpp
include/bitcoin/transaction_pool.hpp
include/bitcoin/types.hpp
include/bitcoin/messages.hpp
include/bitcoin/blockchain/postgresql_blockchain.hpp
include/bitcoin/blockchain/organizer.hpp
include/bitcoin/blockchain/bdb_blockchain.hpp
include/bitcoin/blockchain/blockchain.hpp
include/bitcoin/utility/threads.hpp
include/bitcoin/utility/elliptic_curve_key.hpp
include/bitcoin/utility/assert.hpp
include/bitcoin/utility/ripemd.hpp
include/bitcoin/utility/logger.hpp
include/bitcoin/utility/sha256.hpp
include/bitcoin/utility/base58.hpp
include/bitcoin/utility/big_number.hpp
include/bitcoin/utility/serializer.hpp
include/bitcoin/utility/clock.hpp
include/bitcoin/script.hpp
include/bitcoin/transaction.hpp

The benchmark I use for how the API is progressing is the classical poller application which has become much more intuitive and simple yet flexible and powerful since the early days:

Code:
#include
using namespace libbitcoin;

using std::placeholders::_1;
using std::placeholders::_2;

class pollapp
  : public threaded_service,
    public std::enable_shared_from_this
{
public:
    pollapp();

    void start(std::string hostname, unsigned int port);

private:
    void handle_connect(const std::error_code& ec, channel_ptr node);
    void initial_ask_blocks(const std::error_code& ec,
        const message::block_locator& loc);

    void recv_inv(const std::error_code& ec,
        const message::inventory& packet);
    void recv_blk(const std::error_code& ec,
        const message::block& blk);

    void handle_store(const std::error_code& ec, block_info info,
        const hash_digest& block_hash);
    void ask_blocks(const std::error_code& ec,
        const message::block_locator& loc, const hash_digest& hash_stop);

    network_ptr network_;
    handshake_ptr handshake_;
    blockchain_ptr chain_;
    channel_ptr node_;
};

typedef std::shared_ptr pollapp_ptr;

pollapp::pollapp()
{
    network_ = std::make_shared();
    handshake_ = std::make_shared();
    chain_ = std::make_shared("database/");
}

void pollapp::start(std::string hostname, unsigned int port)
{
    handshake_->connect(network_, "localhost", 8333,
        std::bind(&pollapp::handle_connect, shared_from_this(), _1, _2));
}

void pollapp::handle_connect(const std::error_code& ec, channel_ptr node)
{
    if (ec)
    {
        log_fatal() << ec.message();
        return;
    }
    node_ = node;
    chain_->fetch_block_locator(
        std::bind(&pollapp::initial_ask_blocks, shared_from_this(), _1, _2));
}

void handle_send_packet(const std::error_code& ec)
{
    if (ec)
        log_error() << ec.message();
}

void pollapp::initial_ask_blocks(const std::error_code& ec,
    const message::block_locator& loc)
{
    if (ec)
    {
        log_fatal() << ec.message();
        return;
    }
    node_->subscribe_inventory(
        std::bind(&pollapp::recv_inv, shared_from_this(), _1, _2));
    node_->subscribe_block(
        std::bind(&pollapp::recv_blk, shared_from_this(), _1, _2));
    ask_blocks(ec, loc, null_hash);
}

void pollapp::recv_inv(const std::error_code& ec,
    const message::inventory& packet)
{
    if (ec)
    {
        log_fatal() << ec.message();
        return;
    }
    message::get_data getdata;
    for (const message::inventory_vector& ivv: packet.inventories)
    {
        if (ivv.type != message::inventory_type::block)
            continue;
        getdata.inventories.push_back(ivv);
    }
    node_->send(getdata, handle_send_packet);
    // Re-subscribe
    node_->subscribe_inventory(
        std::bind(&pollapp::recv_inv, shared_from_this(), _1, _2));
}

void pollapp::recv_blk(const std::error_code& ec,
    const message::block& blk)
{
    if (ec)
    {
        log_fatal() << ec.message();
        return;
    }
    chain_->store(blk,
        std::bind(&pollapp::handle_store, shared_from_this(),
            _1, _2, hash_block_header(blk)));
    // Re-subscribe
    node_->subscribe_block(
        std::bind(&pollapp::recv_blk, shared_from_this(), _1, _2));
}

void pollapp::handle_store(const std::error_code& ec, block_info info,
    const hash_digest& block_hash)
{
    if (ec)
    {
        log_fatal() << ec.message();
        return;
    }
    switch (info.status)
    {
        case block_status::orphan:
            chain_->fetch_block_locator(
                std::bind(&pollapp::ask_blocks, shared_from_this(),
                    _1, _2, block_hash));
            break;

        case block_status::rejected:
            log_error() << "Rejected block " << pretty_hex(block_hash);
            break;

        case block_status::confirmed:
            log_debug() << "block #" << info.depth;
            break;
    }
}

void pollapp::ask_blocks(const std::error_code& ec,
    const message::block_locator& loc, const hash_digest& hash_stop)
{
    if (ec)
    {
        log_fatal() << ec.message();
        return;
    }
    message::get_blocks packet;
    packet.locator_start_hashes = loc;
    packet.hash_stop = hash_stop;
    node_->send(packet, std::bind(&handle_send_packet, _1));
}

int main(int argc, const char** argv)
{
    bdb_blockchain::setup("database/");

    pollapp_ptr app = std::make_shared();
    app->start("localhost", 8333);
    // Wait for CTRL-D
    while (true)
    {
        char n;
        std::cin >> n;
        if (std::cin.eof())
            break;
    }
    return 0;
}

legendary
Activity: 905
Merit: 1012
December 31, 2011, 06:39:37 PM
I, too, would use and contribute to this project if it were released under a more permissive license (BSD preferably, LGPL if you must). As it stands I cannot even look at this code due to the possibility of legal risk to my company.
full member
Activity: 168
Merit: 100
December 31, 2011, 06:28:19 PM
Quote
As much as I like *free* software, I think we need to support proprietary businesses if Bitcoin is to go mainstream.
I agree with this 100%

I'm also thrilled that libbitcoin is here.  In my opinion, its a milestone.

Has anyone tried compiling on MSVC?
sr. member
Activity: 252
Merit: 250
Live Stars - Adult Streaming Platform
December 31, 2011, 03:23:49 AM
#99
I will not contribute any code to this project unless the license is changed to LGPL.
Pages:
Jump to: