Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/citp/testchain-generator
Generate synthetic blockchains
https://github.com/citp/testchain-generator
bitcoin bitcoin-cash blockchain blocksci
Last synced: about 1 month ago
JSON representation
Generate synthetic blockchains
- Host: GitHub
- URL: https://github.com/citp/testchain-generator
- Owner: citp
- License: gpl-3.0
- Created: 2018-11-19T18:47:16.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-13T10:04:44.000Z (about 3 years ago)
- Last Synced: 2024-07-30T17:24:45.944Z (5 months ago)
- Topics: bitcoin, bitcoin-cash, blockchain, blocksci
- Language: Python
- Homepage:
- Size: 45.9 KB
- Stars: 8
- Watchers: 7
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Testchain Generator
[![Build Status](https://travis-ci.org/citp/testchain-generator.svg?branch=master)](https://travis-ci.org/citp/testchain-generator)
This tools deterministically generates a synthetic blockchain using Bitcoin's regtest mode.
It was written to provide a lean blockchain to run functional and regression against and is used to test [BlockSci](https://github.com/citp/BlockSci).## Requirements
- Requires Python >=3.6
- Install Bitcoin Core (`bitcoind`)
- Mac: `brew install bitcoin`
- Linux: [Install instructions](https://bitcoin.org/en/full-node#linux-instructions) (only install the daemon)
- Install [secp256k1](https://github.com/bitcoin-core/secp256k1)
- Install Python3 requirements
- `pip3 install -r requirements.txt`## Running
The `generate_chain.py` script takes three arguments:
- `--output-dir=` specifies where the output should be stored (default: `../files/`)
- `--chain=` specifies whether a Bitcoin or a Bitcoin Cash chain should be generated (options: `btc` or `bch`, default: `btc`)
- `--exec=` expects a path to the node daemon (default: `bitcoind`)If you are using this as a submodule for BlockSci and want to update the Bitcoin (BTC) chain, you would run
```
python3 generate_chain.py
```
It will automatically update the `BlockSci/test/files/btc/` directory with the new block and json files.To update the Bitcoin Cash output, you'll need to select `bch` and provide a path to the Bitcoin ABC daemon executable.
```
python3 generate_chain.py --chain=bch --exec=
```If you're using this as a standalone tool, you'll probably want to change the output directory for the generated files, e.g.
```
python3 generate_chain.py --output-dir=.output
```## Extending the blockchain
New motifs can be created by adding a new class in `blockgen/motifs/` that inherits from `Generator`.
Then, add this new class to `generate_chain.py`.
The `Generator` class provides a number of utility functions, such as:- `next_address()`: returns a new `Address`
- `current_address()`: returns the current address (the one returned by the last `next_address()` call)
- `fund_address(addr, value)`: sends `value` BTC to the address `addr`
- `create_transaction([sources], [recipients])`: creates a new transaction using a list of addresses as inputs (`[sources]`) and another list of addresses as outputs (`[recipients]`)
- `generate_block()`: creates a new block that includes all transactions created since it was last called