Code Monkey home page Code Monkey logo

moon's Introduction

moon, a testnet3 tBTC faucet

moon-faucet

  1. Installation
  2. Configuration
  3. Bitcoinlib
  4. Service Provider
  5. RPC Server Connection
  6. Database Setup
  7. Environment
  8. Redis
  9. Running the Server

Installation

Start by cloning this repository into your project directory.

ubuntu:~/projects$ git clone https://github.com/craigderington/moon.git
ubuntu:~/projects$ cd moon
ubuntu:~/projects/moon$ virtualenv venv --python=python3.9
ubuntu:~/projects/moon$ source venv/bin/activate
(venv)ubuntu:~/projects/moon$ pip install -r requirements.txt
... python project dependencies installed ...

bitcoinlib

This faucet app utilizes Bitcoinlib as the RPC client. Several configuration changes are required to configure the module.

Configuration

Browse into the Python virtual environment site-packages at /project-path/venv/lib/python3.9/sites-packags/bitcoinlib

Modify data/config.ini

[locations]
default_databasefile=mysql://username:password@localhost:3306/bitcoinlib

Alternatively, you can use SQLite. The bitcoinlib database is only used by the packages wallet features and is not dependent on the fronted faucet application.

Modify data/providers.json

{
  "bitcoinlib_test": {
    "provider": "bitcoinlibtest",
    "network": "bitcoinlib_test",
    "client_class": "BitcoinLibTestClient",
    "provider_coin_id": "",
    "url": "http://rpc-server-user:[email protected]:18332",
    "api_key": "",
    "priority": 10,
    "denominator": 100000000,
    "network_overrides": null
  }  
}

Service Provider

Our connection to the Bitcoin Testnet3 RPC Server is dependent on a successful RPC Server setup on the host machine running Bitcoin Core 0.22+ testnet; with a properly configured wallet. Please see Bitcoin Core documentation for setup instructions.

I recommend testing your RPC Server connection before running the web server for the first time. In your console, run curl to make sure you can connect to the service.

(venv)ubuntu:~/projects/moon$ curl --data-binary '{"jsonrpc": "1.0", "id": "crltext", "method":"getblockchaininfo", "params": []}' -H "Content-Type: text/plain" http://rpc-server-username:[email protected]:18332
... {json-server-response} ...

Since Bitcoin Core RPC Server only allows connections from the localhost, I recommend running the testnet server on a separate instance and configuring a SSH tunnel from the moon faucet web server to the BTC Testnet3 Server.

This can be accomplished by creating a tunnel to the testnet machine.

(venv)ubuntu:~/projects/moon$ ssh -L -fn localhost:18333:localhost:18332 ubuntu@host

When setting up this project using a SSH tunnel, make sure your RPC SERVER uses the correct port, in this case 18333 (local) to 18332 (remote)

Database Setup

The bitcoinlib database must be created before using MySQL as the data provider. The schema will be created at run time, however, we need to create the database and create a user with permission to read/write to the database.

(venv)ubuntu:~/projects/moon$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.
Server version: 5.7.38-0ubuntu0.18.04.1 (Ubuntu)

mysql> create database bitcoinlib;
mysql> create user "bitcoinlib"@"localhost" identified by "password";
mysql> grant all on bitcoinlib.* to "bitcoinlib"@"localhost" with grant option;
mysql> flush privileges;

Environment

Create 2 files, .env and .flaskenv to store the apps environment variables. These vars must be configured prior to running the web server for the first time.

# .flaskenv
FLASK_APP="manage.py"
FLASK_ENV="development"
# .env
FLASK_CONFIG=development
MAIL_USERNAME=""
MAIL_PASSWORD=""
MAIL_DEFAULT_SENDER="<sender@address>"
BITCOINLIB_DATABASE_PASSWORD=""
BITCOINLIB_RPC_SERVER_USERNAME=""
BITCOINLIB_RPC_SERVER_PASSWORD=""

Redis

Make sure redis-server is running on the host and is accessible at...

redis://localhost:6379/0

Moon uses a redis in-memory cache to store and retrieve remote client IP addresses and user-agents to help fight against bots spamming the faucet request form and to limit client requests to once per hour.

I'd rather not have to implement an unfriendly captcha solver. Even the best captcha can be beaten with the appropriate tools and software.

A bot detection redirect service may be required in the future.

Running the Server

(venv)ubuntu:~/projects/moon$ flask run

For background tasks and messaging functionality, in a separate console, fire up the Celery worker to execute app tasks.

(venv)ubuntu:~/projects/moon$ venv/bin/celery worker -A celery_worker.celery -l info -n worker%h -c 2

TODO

  • API's
  • Bot detection
  • redis-cache
  • python bloom filter (objects=10**8)
  • Faucet wallet funding with tBTC
  • Bitcoin RPC server command library (available commands)

moon's People

Contributors

craigderington avatar

Stargazers

 avatar

Watchers

 avatar  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.