A simple app developed to fix some concepts about Rust and Blockchains
- Initial Version ✅
- Block Mining ✅
- Persistence (rocksdb) ✅
- Transaction Implementation ✅
- TXPool ✅
- RPC ✅
- State ✅
- Signatures
- EVM
- P2P
cargo run
The implementation of the Peer-To-Peer Protocol, allowing the nodes to communicate between after estabilishing the connection.
A new TCP port will be opened to deal with the protocol, in this case 55666
This implementation has three kind messages:
- Connect -> Initial message, meaning a new node wants to connect with the current node.
Message structure: [connection] -> A simple string
What current node must do:
- Stores the new peer address (peer_ip:55666) into the known peers array.
Returns: [connected] -> A simple string
- ForwardBlock -> Sent by the node's miner when a new block is created (only the node itself can execute this message)
Message structure: [forward_block|BLOCK] -> A simple string containing the block to be forwarded to it's peers
What current node must do:
- The current node will forward the block to all it's connected peers trough the ReceiveBlock message
- ReceiveBlock -> Received when other peer finished the block creation firstly.
Message structure: [receive_block|BLOCK] -> Same as ForwardBlock
What current node must do:
- The current node needs to commit it to it's ledger
Only connected nodes can share information (i.e, forwarding blocks)
When a node receive a new TX or produce a new block, it will save locally and forward this information to it's peers. The peers must validate the information and save it in their ledger.
Each request (or method) is structured like this:
method|args
So, you need to send in this format to execute the RPC methods.
The RPC listen on the 6565 port and have only one method so far:
- send_tx -> Send a simple tx from one account to another one
Example: send_tx|from:user1,to:user2,amount:100
echo 'send_tx|from:user1,to:user2,amount:100' | ncat localhost 6565
- get_block_by_number -> Returns all information about a block by it's number
Example: get_block_by_number|23
echo 'get_block_by_number|23' | ncat localhost 6565
- get_balance_of -> Returns the current balance of an User
Example: get_balance_of|betty
echo 'get_balance_of|betty' | ncat localhost 6565
- get_transaction -> Returns the information of an executed transaction
Example: get_transaction|tx_hash
echo 'get_transaction|463d49fe26b4b71937901b21918c39399e6b9acbe3dae4a7bb73a833880fcb39' | ncat localhost 6565
- get_user_transactions -> Returns all txs which the user was involved (sent and received)
Example: get_user_transactions|user
echo 'get_user_transactions|betty' | ncat localhost 6565