EM-Bitcoin
The Bitcoin protocol implemented using Ruby's EventMachine. Initially extracted from bitcoin-ruby.
Using EventMachine::Bitcoin::Connection
to connect to the Bitcoin network
require 'em_bitcoin'
gem 'em-bitcoin'
Remember that you always need to start the EventMachine event loop. You can't just do this:
EventMachine::Bitcoin::Connection.connect_random_from_dns
You'll need to do this, which will actually connect to the Bitcoin network and you'll see a stream of transactions.
EventMachine.run do
EventMachine::Bitcoin::Connection.connect_random_from_dns
end
You can override the EventMachine::Connection methods to provide your application-specific logic. Such as:
class TxCounter < EventMachine::Bitcoin::Connection
def post_init
super
@tx_count = 0
end
def receive_data(data)
super
@tx_count += 1
end
def unbind
puts "Total transactions were: #{@tx_count}!"
end
end
EM.run { TxCounter.connect_random_from_dns }
TODO
- Rework the integration points to both EM and the Bitcoin protocol parser
- Warn about some of the DNS seeds being flaky
- Put license in gemspec
- Write some tests
- Write some examples
License
Available here: COPYING