Skip to content

My cryptocurrency using a distributed decentralized public ledger in a blockchain (i.e. bitcoin).

License

Notifications You must be signed in to change notification settings

JeffDeCola/jeffCoin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jeffCoin

Tag Latest Go Reference Go Report Card codeclimate Maintainability codeclimate Issue Count MIT License jeffdecola.com

*** THE REPO IS UNDER CONSTRUCTION - CHECK BACK SOON ***

A cryptocurrency (transaction based data) built on distributed decentralized multi-node P2P open Network using a sha256 Proof of Work (PoW) blockchain with a REST JSON API and a TCP Server to communicate between the Nodes over IP.

Or more simply, a distributed decentralized public ledger.

To dive right in, head down to RUN.

Table of Contents

Documentation and Reference

PREREQUISITES

go get -v -u github.com/btcsuite/btcutil/base58
go get -v -u golang.org/x/crypto/ripemd160
go get -u -v github.com/gorilla/mux
go get -u -v github.com/sirupsen/logrus
go get -u -v github.com/pkg/errors
go get -u -v github.com/satori/go.uuid
go get -u -v golang.org/x/crypto/bcrypt

SOFTWARE STACK

  • GUI golang net/http package
  • Routing & REST API framework golang gorilla/mux package
  • Inter Node Communication golang TCP package
  • Backend golang
  • Database N/A

BUILDING BLOCKS

This project was built from some of my other projects,

OVERVIEW

jeffCoin (JEFF) is my interpretation of a transaction based (ledger) using a blockchain. This is a work in progress I feel can be used as a foundation for building bigger and better things.

The following illustration shows the jeffCoin Network of Nodes,

IMAGE - the-jeffcoin-network - IMAGE

Coins (a.k.a jeffCoins) are minted as follows,

  • A grand total of 1,000,000 jeffCoins
  • The blockchain will not store jeffCoins but addies which are 1/1000 of a jeffCoin (.001 JEFF)
  • The founders wallet will start with 100,000 jeffCoins (100,000,000 addies) (10% of all jeffCoins)
  • Rewards 1 jeffCoin (1000 addies) every 10 minutes (144 jeffCoins/day or 52,560 jeffCoins/year)
  • Will take 17.12 years to mint all the jeffCoins (900,000/52,560 = 17.12)

jeffCoin uses the following technology,

  • Written in golang
  • Implements a blockchain using a sha256 hash
  • A distributed decentralized multi-node P2P architecture maintaining a Network of Nodes
  • A Webserver with both a GUI and a REST API
  • A TCP Server for inter-node communication
  • ECDSA Private & Public Key generation
  • Private Key AES-256 encryption for storage
  • Creates a jeffCoin Address from the ECDSA Public Key (Just like bitcoin) currently not being used
  • ECDSA Digital Signature Verification
  • Mining uses Proof of Work (PoW)
  • Transaction as stored using an unspent transaction output model
  • Password hashing and storage using bcrypt

What jeffCoin does not have,

  • No database, so if the entire Network dies, the chain dies
  • Rigorous testing of all corner cases

SOFTWARE ARCHITECTURE

This readme got too big so I moved my software explanation to architecture.md.

I divided the software into 5 sections,

YOUR PASSWORD & KEYS

Your secrets are kept in /credentials in .json files. These file are .gitignored. But if they did make there way onto git you are still protected as follows,

  • Password File
    • Stores your password hash
    • Password hashing using bcrypt
  • Wallet File
    • Stores your Private and Public ECDSA Key
    • The Private Key is Encrypted using AES-256 with your password as your key

This illustration may help,

IMAGE - password-and-key-flow - IMAGE

RUN

If this is you first time running and you want to create your own private Network, you need to create your first Node (Genesis Node). You only do this once. You can also set the log level (info, debug, trace) to cut down on the amount of logging.

GENESIS NODE

go run jeffCoin.go \
       -genesis \
       -loglevel debug \
       -nodehttpport 2000 \
       -nodeip 127.0.0.1 \
       -nodename Founders \
       -nodetcpport 3000 \
       -nodepassword fpw

This will created the first Node (the Founders Node) in the Network. It will also create a wallet and password file and save the credentials in /wallet and /password respectively. Not to worry, the password is password hashed with bcrypt and your Wallet Private Key is encrypted using AES-256. I also .gitignore them.

Note that the node has an IP address and port for both HTTP and TCP. For this example I use the localhost or 127.0.0.1. But obviously, you can pick anything you want for your rig.

But having one node is boring so lets create more.

ADDING NEW NODES

To hook up to the Network you need the IP of any working Network Node. If you have the above running Node on 127.0.0.1:3000, adding a second Node "Jeff" in your network could look like,

go run jeffCoin.go \
       -loglevel debug \
       -networkip 127.0.0.1 \
       -networktcpport 3000 \
       -nodehttpport 2001 \
       -nodeip 127.0.0.1 \
       -nodename Jeff \
       -nodetcpport 3001 \
       -nodepassword jpw

Why stop, might as well add a third Node,

go run jeffCoin.go \
       -loglevel debug \
       -networkip 127.0.0.1 \
       -networktcpport 3000 \
       -nodehttpport 2002 \
       -nodeip 127.0.0.1 \
       -nodename Matt \
       -nodetcpport 3002 \
       -nodepassword mpw

LOGGING

You will notice logging is set to -debug. You can be more explicit and set to -trace or less wordy and set to -info.

WEBSERVER & REST API

The GUI for the three nodes you just created are,

127.0.0.1:2000 / 127.0.0.1:2001 / 127.0.0.1:2002

The API page will list the various API commands. For example, to show a particular block,

127.0.0.1:2000/showblock/0

PLAY AROUND

Each Node has it's own wallet, so now you can send jeffCoins/Value. To do this, use the Webserver and API. You will notice only the Founders have jeffCoins to send. So Jeff or Matt will not be able to send coins until the Founder gives them some.

Send some coins from the Founders to Jeff or Matt and note they are pending. That's because they are not validated. Like bitcoin, you will need to wait 10 minutes for a miner to solve the nonce and then for the Network to validate the transactions and reach consensus.

SWITCHES (REFERENCE)

-h prints the following,

  • -gce Is this Node on Google Compute Engine (See below)
  • -genesis Create your first Node
  • -loglevel string LogLevel (info, debug or trace) (default "info")
  • -networkip string Network IP (default "127.0.0.1")
  • -networktcpport string Network TCP Port (default "3000")
  • -nodehttpport string Node Web Port (default "2001")
  • -nodeip string Node IP (default "127.0.0.1")
  • -nodename string Node Name (default "Jeff")
  • -nodepassword string Set/Reset your Password
  • -nodetcpport string Node TCP Port (default "3001")
  • -testblockchain Loads the blockchain with test data (See below)
  • -v prints current version
  • -wallet Only the wallet and webserver GUI/API (See below)

RUN (WALLET ONLY)

If you just want to have a wallet, use the -wallet switch. You will not be part of the Network since there is no blockchain or miner. But you can always restart and become part of the Node.

You will need to hook up to a Node, so the following could work,

go run jeffCoin.go \
       -loglevel debug \
       -networkip 127.0.0.1 \
       -networktcpport 3000 \
       -nodehttpport 2005 \
       -nodeip 127.0.0.1 \
       -nodename Jills-Wallet \
       -nodetcpport 3005 \
       -nodepassword jpw \
       -wallet

The Node and Wallet name are the same.

RUN (OPTIONAL)

Here are some optional things you can do.

CONNECT USING TCP

You can also bypass the Webserver REST API and just open a connection to the TCP server itself,

netcat -q -1 127.0.0.1 3000

And request commands such as,

--- Waiting for command: SBC, BANN, SNL, BVB, BC, BTR, SAB, TR, EOF
SNL
[...nodeList...]
thank you

Note you will need to handshake it with a thank you at the end.

There is a complete list of commands in the architecture readme TCP REQUESTS & HANDLERS.

TEST MOCK TRANSACTIONS

If you add the -test switch you will run some mock transactions from mock wallets. Those wallets are located in /wallets and just used for testing.

You must use the MockFounders nodename,

go run jeffCoin.go \
       -genesis \
       -loglevel debug \
       -nodehttpport 2000 \
       -nodeip 127.0.0.1 \
       -nodename MockFounders \
       -nodetcpport 3000 \
       -nodepassword mfpw \
       -testblockchain

These transactions are the same I used in my bitcoin-ledger example.

So your blockchain and pendingBlock should look similar to blockchain-output.txt.

And the balances in the blockchain should be,

The balance for MockFounders PubKey (Address) is 99657000
The balance for MockJeffs PubKey (Address) is 42500
The balance for MockMatts PubKey (Address) is 265000
The balance for MockJills PubKey (Address) is 35000
The balance for MockCoinVaults PubKey (Address) is 500

Remember, the pendingBlock is pending, so it's not part of this calculation. Transaction do not have value until they are part of the blockchain.

RUN ON GOOGLE COMPUTE ENGINE (GCE)

Make sure your create a firewall rule and have your instance use it as a network tag,

gcloud compute firewall-rules create jeffs-firewall-settings-rule \
    --action allow \
    --rules tcp:1234,tcp:3334 \
    --priority 1000 \
    --source-ranges 0.0.0.0/0 \
    --target-tags "jeffs-firewall-settings" \
    --description "Jeffs firewall rules"

The IP 0.0.0.0 gets forwarded to your external IP, hence I added a -gce switch to deal with this,

go run jeffCoin.go \
       -gce \
       -genesis \
       -loglevel debug \
       -nodehttpport 1234 \
       -nodeip 35.203.189.193 \
       -nodename Founders \
       -nodetcpport 3334 \
       -nodepassword fpw

Add another node (not at gce) is as simple as connecting to it,

go run jeffCoin.go \
       -loglevel debug \
       -networkip 35.203.189.193 \
       -networktcpport 3334 \
       -nodehttpport 2003 \
       -nodeip 127.0.0.1 \
       -nodename Jill \
       -nodetcpport 3003 \
       -nodepassword jpw

I have a gce build example here.