GithubHelp home page GithubHelp logo

txsc's Introduction

txsc

Join the chat at https://gitter.im/Kefkius/txsc

txsc (tx script compiler) is a Bitcoin transaction script compiler.

Usage

Run setup.py install. The script txsc (which refers to txsc.compiler.py) will be installed. You can also run compiler.py locally, but you won't be able to use any languages added by plugins.

Unless specified, txsc will assume that the source language is txscript and the target language is BTC (see below for explanations of what these languages are).

You can either invoke txsc with a string or with a filename. If a filename is specified, the file extension will be used to determine the source language if one is present.

Compile raw BTC to ASM:

txsc "5255935788" -s btc -t asm
2 5 ADD 7 EQUALVERIFY

Compile txscript to BTC and ASM:

$ txsc "2 + 5 == 7;"
5255935787
$ txsc "2 + 5 == 7;" -t asm
2 5 ADD 7 EQUAL

With -v, optimizations will be shown:

$ txsc "verify 2 + 5 == 7;" -t asm -v
Linear Intermediate Representation:
  ['OP_2', 'OP_5', 'OP_ADD', 'OP_7', 'OP_EQUAL', 'OP_VERIFY']

Optimized Linear Representation:
  ['OP_2', 'OP_5', 'OP_ADD', 'OP_7', 'OP_EQUALVERIFY']

asm:
  2 5 ADD 7 EQUALVERIFY

Configuration Files

If a file called txsc.conf exists in the directory that txsc is being run in, it will be loaded by the compiler. A configuration file may also exist at $HOME/.config/txsc/txsc.conf. If the command-line option --config is supplied, it will be used instead of these paths. The configuration file is in JSON format. Options in the configuration file are overriden by command-line options.

Here is a sample of what a configuration file may look like:

{
    "log_level": "error",
    "target_lang": "asm"
}

The above configuration file specifies that only errors should be logged, and that asm is the target language to compile source to.

Languages

ASM

ASM represents a script as assembly instructions. Data pushes are hex-encoded, and prefixed with their size.

BTC

BTC refers to the raw, hex-encoded script format that Bitcoin scripts are sometimes represented as.

TxScript

txsc includes a language used to construct transaction scripts. It's based on Python. It works by parsing code and generating a structural intermediate representation, then transforming that into the linear intermediate representation that other languages can use.

See the TxScript documentation for detailed information regarding TxScript.

Examples

See the examples folder for scripts that txsc can be called with directly.

Credits

txsc is based loosely on Superscript compiler, an educational Bitcoin script compiler.

txsc's People

Contributors

kefkius avatar gitter-badger avatar

Stargazers

Cheng JIANG avatar FoxtrotZulu avatar Will Clark avatar xhliu avatar James Chen avatar  avatar kkuno avatar Lightning Koala avatar William Casarin avatar  avatar Jason Dreyzehner avatar  avatar Jonathan Chappelow avatar

Watchers

William Casarin avatar James Cloos avatar Jason Dreyzehner avatar  avatar  avatar

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.