Giter VIP home page Giter VIP logo

bitrans's Introduction

Bitrans

A bitcoin transaction script language / vm implementation in python. Built based on info from the bitcoin wiki.

Getting it running

  • Install bitcoind
    • Guide for installing using Macports on Maverick guide
  • Enable the bitcoin rpc server and historical transaction indexing in ~/bitcoin.conf by adding/uncommenting the following lines and replacing bracketed things:
    • txindex=1
    • server=1
    • rpcuser=[yourUser]
    • rpcpassword=[yourPass]
    • rpcport=8332
    • rpcconnect=127.0.0.1
  • Spin up a bitcoind daemon, rebuilding the historical index. This will take some time to complete; about a day for all transactions. You will be able to work with the current state of the index, though, so transactions from early blocks should work pretty quickly.
bitcoind -conf=/path/to/your/bitcoin.conf -daemon -reindex
  • Get bitrans:
git clone https://github.com/hackscience/bitrans.git
cd bitrans
  • Install the python ecdsa lib.
  • Fire up python:
python
  • Establish a connection to the bitcoind daemon
>>> import rpc
>>> s = rpc.jsonrpc("yourUser","yourPass")
  • Grab a transaction
    • the transaction id could be found in https://blockchain.info/
    • for testing, we use txid = ‘fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4’.
    • Note that if your bitcoind hasn’t finished reindex, the current rpcserver will just return NoneType Error.Just grab a different txid or wait until reindex finishes.
>>> import transaction
>>> t = transaction.transaction('fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4',s)
  • Verify the transaction:
t.verify()

Description

this is outdated Here’s how it works:

There are three primary abstractions: opcodes, bytestreams, and machines. A stream is a sequence of bytes; it is implemented as a wrapper around python strings of human readable hex (like ‘AFAF’). A machine consists of two stacks (a primary and alternative stack). An opcode takes a stream and a machine as input and does stuff (maybe mutates) one, both, or neither.

Byte streams will be a mixture of opcodes and ‘raw’ data. The elements of the stacks are themselves bytestreams. Raw data is interpreted as variable-length little-endian signed integers. Opcodes are one-byte unsigned little-endian big-endian ints.

There doesn’t seem to be any reason to compile anything. A script is interpreted by continually reading an opcode from a stream representing the script and applying the opcode to the stream and a machine. I think scripts have headers but I haven’t quite figured it out yet. (Multiple) scripts are embedded in transactions which provide some metadata. A transaction is valid if all scripts do not fail during interpretation and the top stack item after interpretation is true.

Structure

  • ops.py: Opcode implementations.
  • opfns.py: Implementations of the functions that opcodes are built from.
  • machine.py: Stack machine implementation.
  • bytestream.py: Bytestream implementation.
  • script.py: Implements a script.
  • transaction.py: Parses and represents entire transactions.

Immediate todo

  • Implement remaining opfns and ops

Fun todo

  • Write a higher-level representation which compiles to bytestreams.
  • Animate the process of interpreting a script.
  • Throw a whole bunch of garbage at the vm and see if anything causes it to lock up or overflow or something.

Running tests

Install and run nose:

pip install nose
nosetests

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.