|
| 1 | +[](https://pypi.python.org/pypi/abci) |
| 2 | +[](https://https://travis-ci.org/davebryson/py-abci) |
| 3 | +[](https://codecov.io/gh/davebryson/py-abci) |
| 4 | + |
| 5 | +# Py-ABCI |
| 6 | +Build Tendermint blockchain applications in Python. It's fun. This library provides the core functionality needed to create Tendermint ABCI applications. |
| 7 | + |
| 8 | +## Supported Tendermint Version |
| 9 | +* Tendermint *0.34.11* |
| 10 | +* ABCI *0.17.0* |
| 11 | + |
| 12 | +## Installation |
| 13 | +Requires Python >= 3.9 |
| 14 | + |
| 15 | +`pip install abci` |
| 16 | + |
| 17 | +You'll need a binary version of the Tendermint engine. |
| 18 | +Available here: https://github.com/tendermint/tendermint/releases |
| 19 | + |
| 20 | +**Make sure the Tendermint version you download matches the current support version of this library** |
| 21 | + |
| 22 | +## Quick Start - demo |
| 23 | + |
| 24 | +A very simple demo application is included and available from the command line as `counter`. You can find the code here: https://github.com/davebryson/py-abci/blob/master/src/example/counter.py |
| 25 | + |
| 26 | +To try it out: |
| 27 | +1. Make sure you have the Tendermint binary setup locally and in your path. To test it's working |
| 28 | +open a terminal window and type: |
| 29 | +```text |
| 30 | +>> tendermint version |
| 31 | +``` |
| 32 | +It should output your version of Tendermint that should match the currently supported version |
| 33 | +of this library. |
| 34 | + |
| 35 | +2. Next, initialize Tendermint by running: |
| 36 | +```text |
| 37 | +>> tendermint init |
| 38 | +``` |
| 39 | + |
| 40 | +3. Start the Tendermint node: |
| 41 | +```text |
| 42 | +>> tendermint node |
| 43 | +``` |
| 44 | +The node will start, but will be waiting for you application to start. |
| 45 | + |
| 46 | +4. Open another terminal, and start the `counter` application. The `counter` will be available |
| 47 | +from within the Python environment where you installed `abci` |
| 48 | +```text |
| 49 | +>> counter |
| 50 | +``` |
| 51 | +You'll see the application start, and in the Tendermint terminal, you'll see the output of |
| 52 | +blocks being produced |
| 53 | + |
| 54 | +5. Now, open a 3rd terminal window to send some transaction to the blockchain. To do this we'll |
| 55 | +use the `curl` application to send transaction to the local blockchain over http. For example: |
| 56 | +```text |
| 57 | +>> curl http://localhost:26657/broadcast_tx_commit?tx=0x01 |
| 58 | +>> curl http://localhost:26657/broadcast_tx_commit?tx=0x02 |
| 59 | +``` |
| 60 | +The counter application expects you to send `transactions` as numbers encoded as hex in order: 1,2,3... |
| 61 | +It will reject and out-of-order numbers. You can always see the latest accepted value by sending the |
| 62 | +request: |
| 63 | +```text |
| 64 | +>> curl http://localhost:26657/abci_query |
| 65 | +``` |
| 66 | + |
| 67 | +To shut down the application enter `CTRL-C` |
| 68 | + |
| 69 | +## Get Started |
| 70 | +To start building your own application: |
| 71 | +1. Extend the `abci.application.BaseApplication` class |
| 72 | +2. Implement the Tendermint ABCI callbacks - see https://docs.tendermint.com/v0.34/spec/abci for details on how they work |
| 73 | +3. Start it: |
| 74 | +```python |
| 75 | +from abci.server import ABCIServer |
| 76 | + |
| 77 | +app = ABCIServer(app=MyApplication()) |
| 78 | +app.run() |
| 79 | +``` |
| 80 | +See the ``counter.py`` application in the ``example`` directory https://github.com/davebryson/py-abci/blob/master/src/example/counter.py for a full example. |
| 81 | + |
| 82 | + |
| 83 | +## Developing on the code base |
| 84 | +If you're working directly on the code base. Install a local editable version: |
| 85 | + |
| 86 | +`pip install --editable '.[test]'` |
| 87 | + |
| 88 | +## Updating the Protobuf code |
| 89 | + |
| 90 | +**You should only re-generate the protobuf code if you're updating the associated protobuf files, |
| 91 | +and/or contributing to this code base. You do not need to rebuild protos to create apps.** |
| 92 | + |
| 93 | +A note on protobuf: The primary code directory is `abci`, but you'll notice additional |
| 94 | +directories: `gogoproto`, `tendermint`, and `protos`. |
| 95 | + |
| 96 | +The `gogoproto` and `tendermint` directories are the protobuf generated code used by ``abci``. It adds proper Python modules and preserves all the import statements used by Tendermint for the various protobuf files spread |
| 97 | +across their codebase. The ``protos`` directory is the source .proto files. |
| 98 | + |
| 99 | +To (re)build the protobuf files: |
| 100 | + |
| 101 | +1. Install `protoc` so it's available in your PATH as a command |
| 102 | +2. Run `make update-proto` |
| 103 | + |
| 104 | + |
0 commit comments