Code Monkey home page Code Monkey logo

blockchain's Introduction

blockchain

learning blockchain

Installation

go build

Usage

> ./simple_blockchain
> Usage:
>   createblockchain -data BLOCK_DATA - add a block to the blockchain
>   printchain - print all the blocks of the blockchain
>   send -from FROM -to TO -amount AMOUNT - send AMOUNT of coins from FROM to TO
>   getbalance -address ADDRESS - get the balance of ADDRESS

Example

$ ./simple_blockchain createwallet
Your new wallet address: 1MfCxbN471GdK2FKfEShN1J1q6nT9kexdn

$ ./simple_blockchain createblockchain --address 1MfCxbN471GdK2FKfEShN1J1q6nT9kexdn
Mining a new block...
0000007e1610d899ae1e5b1600d904f392bebc35a47691b979f6907dfe28ef1c
2018/06/06 23:05:19 New block added. used 4.703125037s
Done!

$ ./simple_blockchain getbalance --address 1MfCxbN471GdK2FKfEShN1J1q6nT9kexdn
Balance of 1MfCxbN471GdK2FKfEShN1J1q6nT9kexdn: 10

$ ./simple_blockchain createwallet
Your new wallet address: 1CNSohgdWLyGY8ZTFp1ZvHuP6Yav8djmD

$ ./simple_blockchain send --from 1MfCxbN471GdK2FKfEShN1J1q6nT9kexdn --to 1CNSohgdWLyGY8ZTFp1ZvHuP6Yav8djmD --amount 1
Mining a new block...
000000ef2acce3828404b454c71e6faf80b248d1036c2d30f3127acb76fe6e75
2018/06/06 23:06:00 New block added. used 2.743028811s
Success!

$ ./simple_blockchain getbalance --address 1MfCxbN471GdK2FKfEShN1J1q6nT9kexdn
Balance of 1MfCxbN471GdK2FKfEShN1J1q6nT9kexdn: 9

$ ./simple_blockchain getbalance --address 1CNSohgdWLyGY8ZTFp1ZvHuP6Yav8djmD
Balance of 1CNSohgdWLyGY8ZTFp1ZvHuP6Yav8djmD: 1

$ ./simple_blockchain listaddresses
1MfCxbN471GdK2FKfEShN1J1q6nT9kexdn
1CNSohgdWLyGY8ZTFp1ZvHuP6Yav8djmD

some minor issues

part 3

  1. NewBlockChain() doesn't have to take in address as parameter
  2. it is worth notifying that when iterate through txs, the order is from back to front
  3. FindUnspentTransactions() logic can be optimized for the sake of time complexity\

blockchain's People

Contributors

moyuanhuang avatar

Stargazers

 avatar

Watchers

 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.