built with concourse

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

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,

jeffCoin uses the following technology,

What jeffCoin does not have,

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,

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,

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.