Skip to content

Commit

Permalink
Major Refactor. See whitepaper in ./docs/
Browse files Browse the repository at this point in the history
  • Loading branch information
cranklin committed May 27, 2018
1 parent 3d2b348 commit bafb87a
Show file tree
Hide file tree
Showing 44 changed files with 4,792 additions and 3,029 deletions.
39 changes: 39 additions & 0 deletions README.md
Expand Up @@ -2,3 +2,42 @@
[![Build Status](https://travis-ci.org/cranklin/crankycoin.svg?branch=master)](https://travis-ci.org/cranklin/crankycoin)

Cranky Coin is a simple blockchain, cryptocurrency, wallet implementation

## Getting Started

```
# apt-get install pip
# pip install virtualenv
# virtualenv venv
# . venv/bin/activate
# pip install -r requirements.txt
# pip install -r requirements-dev.txt
```

**Generating a wallet**

```
# python run.py client
Cranky Coin (CRNK) wallet > publickey
```
*copy your public key*
```
Cranky Coin (CRNK) wallet > privatekey
```
*copy your private key*
```
Cranky Coin (CRNK) wallet > quit
# python ./tools/encrypt.py
```
*enter a secure passphrase*
```
Choose a passphrase:
Re-enter your passphrase:
```
*enter your private key*
```
Secret:
Encrypted private key:
```
*copy your encrypted private key*

32 changes: 20 additions & 12 deletions config/config.yaml
Expand Up @@ -2,28 +2,36 @@ user:
public_key:
encrypted_private_key:
ip: "127.0.0.1"
block_path:
chain_db: "./data/chaindata.db"
pool_db: "./data/pool.db"
peer_db: "./data/peer.db"
max_peers: 30
min_peers: 10
queue_bind_in: "ipc:///tmp/crank_in"
queue_bind_out: "ipc:///tmp/crank_out"
queue_processing_workers: 2
network:
name: "Cranky Coin"
ticker_symbol: "CRNK"
version: 1
initial_coins_per_block: 50
halving_frequency: 210000
max_transactions_per_block: 2000
minimum_hash_difficulty: 4
minimum_hash_difficulty: 1
target_time_per_block: 600
difficulty_adjustment_span: 500
significant_digits: 8
short_chain_tolerance: 3
full_node_port: 30013
nodes_url: "http://{}:{}/nodes"
transactions_url: "http://{}:{}/transactions"
block_url: "http://{}:{}/block/{}"
blocks_range_url: "http://{}:{}/blocks/{}/{}"
blocks_url: "http://{}:{}/blocks"
downtime_threshold: 20
nodes_url: "http://{}:{}/nodes/"
transactions_url: "http://{}:{}/transactions/{}"
transactions_inv_url: "http://{}:{}/transactions/block_hash/{}"
unconfirmed_transactions_url: "http://{}:{}/unconfirmed_tx/{}"
blocks_inv_url: "http://{}:{}/blocks/start/{}/end/{}"
blocks_url: "http://{}:{}/blocks/{}/{}"
transaction_history_url: "http://{}:{}/address/{}/transactions"
inbox_url: "http://{}:{}/inbox/"
balance_url: "http://{}:{}/address/{}/balance"
status_url: "http://{}:{}/status"
dns_seeds: []
seed_nodes:
- "127.0.0.1"
- "127.0.0.2"
status_url: "http://{}:{}/status/"
connect_url: "http://{}:{}/connect/"
67 changes: 67 additions & 0 deletions config/init_blockchain.sql
@@ -0,0 +1,67 @@
CREATE TABLE IF NOT EXISTS blocks(
hash CHAR(32) NOT NULL,
prevHash CHAR(32) NOT NULL,
merkleRoot CHAR(32) NOT NULL,
height INTEGER NOT NULL,
nonce INTEGER NOT NULL,
timestamp INTEGER NOT NULL,
version INTEGER NOT NULL,
branch INTEGER DEFAULT 0,
PRIMARY KEY (hash),
UNIQUE (prevHash, branch) ON CONFLICT ROLLBACK
) WITHOUT ROWID;

CREATE INDEX idx_blocks_height ON blocks(height);
CREATE INDEX idx_blocks_prevHash ON blocks(prevHash);

CREATE TABLE IF NOT EXISTS transactions(
hash CHAR(32) NOT NULL,
src CHAR(70) NOT NULL,
dest CHAR(70) NOT NULL,
amount REAL NOT NULL,
fee REAL NOT NULL,
timestamp INTEGER NOT NULL,
signature CHAR(32) NOT NULL,
type INTEGER NOT NULL,
blockHash CHAR(32) NOT NULL,
asset CHAR(32) NOT NULL,
data TEXT NOT NULL,
branch INTEGER DEFAULT 0,
prevHash CHAR(32) NOT NULL,
PRIMARY KEY (hash, branch),
UNIQUE (prevHash, branch) ON CONFLICT ROLLBACK
) WITHOUT ROWID;

CREATE INDEX idx_transactions_src ON transactions(src);
CREATE INDEX idx_transactions_dest ON transactions(dest);
CREATE INDEX idx_transactions_blockHash ON transactions(blockHash);
CREATE INDEX idx_transactions_type_asset ON transactions(type, asset);

CREATE TABLE IF NOT EXISTS branches(
id INTEGER PRIMARY KEY,
currentHash CHAR(32),
currentHeight INTEGER
);

--INSERT INTO branches (id, currentHash, currentHeight)
-- VALUES (0, 'd30051890fe899813f441bd1e93d34790cbb44702668abca4cd8a380aa90e943', 1);
--
--INSERT INTO transactions (
-- hash, src, dest, amount, fee, timestamp, signature, type, blockHash, asset, data, branch, prevHash) VALUES (
-- '96409c929a70a52f1219b3eb3b064c9351f744b8e5023240013f30be572ac70a', '0',
-- '03dd1e57d05d9cab1d8d9b727568ad951ac2d9ecd082bc36f69e021b8427812924', 50, 0, 1524038353, '', 1,
-- 'd30051890fe899813f441bd1e93d34790cbb44702668abca4cd8a380aa90e943',
-- '29bb7eb4fa78fc709e1b8b88362b7f8cb61d9379667ad4aedc8ec9f664e16680', '', 0, '0'
--);
--INSERT INTO transactions (
-- hash, src, dest, amount, fee, timestamp, signature, type, blockHash, asset, data, branch, prevHash) VALUES (
-- 'ef5a5850b5377ee4f5a4ca953ed04b35d0910e886c121b565c1c4012e26636b0', '0',
-- '03dd1e57d05d9cab1d8d9b727568ad951ac2d9ecd082bc36f69e021b8427812924', 1000000, 0, 1524038329, '', 0,
-- 'd30051890fe899813f441bd1e93d34790cbb44702668abca4cd8a380aa90e943',
-- '29bb7eb4fa78fc709e1b8b88362b7f8cb61d9379667ad4aedc8ec9f664e16680', '', 0, '0'
--);
--
--INSERT INTO blocks (hash, prevHash, merkleRoot, height, nonce, timestamp, version, branch) VALUES (
-- 'd30051890fe899813f441bd1e93d34790cbb44702668abca4cd8a380aa90e943', '',
-- '4f27a78679e35963289fae864d1d6ec9b26848160a0d09e6e8fcd56e9ee969b0', 1, 0, 1524041935, 1, 0
--);
16 changes: 16 additions & 0 deletions config/init_mempool.sql
@@ -0,0 +1,16 @@
CREATE TABLE IF NOT EXISTS unconfirmed_transactions(
hash CHAR(32) NOT NULL,
src CHAR(70) NOT NULL,
dest CHAR(70) NOT NULL,
amount REAL NOT NULL,
fee REAL NOT NULL,
timestamp INTEGER NOT NULL,
signature CHAR(32) NOT NULL,
type INTEGER NOT NULL,
asset CHAR(32) NOT NULL,
data TEXT NOT NULL,
prevHash CHAR(32) NOT NULL,
PRIMARY KEY (hash)
) WITHOUT ROWID;

CREATE INDEX idx_unconfirmed_transactions_fee ON unconfirmed_transactions(fee);
8 changes: 8 additions & 0 deletions config/init_peers.sql
@@ -0,0 +1,8 @@
CREATE TABLE IF NOT EXISTS peers(
host CHAR(100) NOT NULL,
downtime INT NOT NULL,
PRIMARY KEY (host)
);

INSERT INTO peers (host, downtime) VALUES ('127.0.0.1', 0);
INSERT INTO peers (host, downtime) VALUES ('127.0.0.2', 0);
15 changes: 8 additions & 7 deletions crankycoin/__init__.py
@@ -1,7 +1,8 @@
from block import *
from blockchain import *
from config import *
from errors import *
from node import *
from transaction import *
from wallet import *
import logging
import yaml

with open("config/config.yaml", 'r') as ymlfile:
config = yaml.load(ymlfile)

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
132 changes: 0 additions & 132 deletions crankycoin/block.py

This file was deleted.

0 comments on commit bafb87a

Please sign in to comment.