Skip to content
forked from cdecker/pycoin

Minimalistic python implementation of the Bitcoin networking stack

License

Notifications You must be signed in to change notification settings

fubendong/pycoin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pycoin

Minimalistic python implementation of the Bitcoin networking stack. This library was developed to facilitate measurements in the Bitcoin network for some of my papers. It does include everything that is needed to connect and participate in the network, it does however not contain any crypto implementations other than the checksum mechanism. If you find this work useful please contribute back your modifications or give me a shout. Should you have a nice idea for a project, we're always looking for fun stuff to implement.

Build Status Bitdeli Badge

Installation

To install just checkout the git repository and use the included setup.py script to build and bundle it:

git clone git@github.com:cdecker/pycoin.git
python setup.py install

Getting started

The following example creates a connection pool. It rewires the message handler on each connection to call the on_inv_received handler on the InvTracker instead, adding the connection as additional argument. When receiving an inv message it loops through the hashes and prints their type and hash to stdout.

from bitcoin import PooledBitcoinProtocolFactory
from functools import partial
from twisted.internet import reactor

class InvTracker(PooledBitcoinProtocolFactory):

    def buildProtocol(self, addr):
        connection = PooledBitcoinProtocolFactory.buildProtocol(self, addr)
        connection.handlers['inv'].append(partial(self.on_inv_received, connection))
        return connection

    def on_inv_received(self, connection, inv):
        for item in inv.hashes:
            print connection.key, item[0], item[1].encode("hex")

def start():
    factory = InvTracker(1000)
    desiredPort = 8333
    reactor.listenTCP(desiredPort, factory) #@UndefinedVariable

    print "Listening to port %d" % factory.port
    reactor.run() #@UndefinedVariable

if __name__=="__main__":
    start()

License

This code is distributed under the BSD 3-clause license.

About

Minimalistic python implementation of the Bitcoin networking stack

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published