blockchain IRIS - ( Embedded Python )
Example of creating a financial blockchain Using Embedded Python on IRIS Data Platform
What is a blockchain
Blockchain is a chain of blocks, where each block contains information from the previous block, this concept can be applied in many ways.
What is a blocks?
Block will be composed of: a datetime, index, content, hash and the hash of the previous block.
In this project the blocks are constructed by:
- index:
- block identification index in the chain
- timestamp:
- transactions:
- Financial transactions that are part of this block, represents the content of the block, you can change the structure by changing the dc.Blockchain.Blockchain classmethod newTransaction
- hash:
- the entire contents of the encrypted block
- nonce:
- value that the system finds by the mining process, changing the hash value when the block is generated.
- previousHash:
- hash of the previous block
Prerequisites
Make sure you have git and Docker desktop installed.
Installation
Clone/git pull the repo into any local directory
$ git clone https://github.com/Davi-Massaru/blockchain_Iris_python.git
Open the terminal in this directory and run:
$ docker-compose build && docker-compose up -d
Run the endpoint curl http://localhost:52773/api/blockchain/ping
to verify the connection to the server
Get Started
After installing the application, you can access the end-points to better understand how it works
- http://localhost:52773/api/blockchain/chain [ GET ]
Returns the current state of blockchain
Response sample:
- http://localhost:52773/api/blockchain/transactions/new [ POST ]
Add a new transaction to be computed in a block, and return which block the transaction will be added
Request Content:
{
"sender": "user 1",
"amount": 1.42,
"recipient": "user 2"
}
Response sample:
- http://localhost:52773/api/blockchain/mine [ GET ]
Start mining a new block that will be added to the chain, returns added block information
Response sample:
- http://localhost:52773/api/blockchain/block/{index} [ GET ]
Returns block information, in the given index
Response sample:
Exploring the blockchain
You can better understand and track global content and transactions through the portal.
Access http://localhost:52773/csp/sys/exp/UtilExpGlobalView.csp?$ID2=GBlockchain&$NAMESPACE=USER&$NAMESPACE=USER to see all blockchain content.
Access http://localhost:52773/csp/sys/exp/UtilExpGlobalView.csp?$ID2=GTransactions&$NAMESPACE=USER&$NAMESPACE=USER to see all transactions made and in which blocks were mined
References: