Managing Data Storage with Blockchain and BigchainDB
Core points
- Ascribe uses the Bitcoin blockchain to record the unique identification of digital artworks and combines NoSQL database (RethinkDB) with the blockchain layer to create BigchainDB. This combination enhances control, asset tracking and security levels, and is particularly attractive to NoSQL database users.
- BigchainDB claims to be completely decentralized due to its blockchain layer. It also adds transaction support, a feature that is often missing in NoSQL databases. This support ensures that database changes have occurred when writing to the underlying NoSQL database through the blockchain layer.
- BigChainDB can fill in missing gaps in current NoSQL and distributed databases, which may provide effective business or use cases. For blockchain enthusiasts, it accomplishes the challenge of fully decentralized application stacks, which may change how applications are developed, deployed, and maintained.
Although the future of Bitcoin is unclear, the underlying technology on which it depends - blockchain - has completely changed many industries and projects, and more applications are about to emerge.
Ascribe is a compelling startup that uses the Bitcoin blockchain to record a limited number of unique identifiers for digital artworks. Therefore, due to this limited number of “copies”, they are traceable, accountable and (hopefully) higher value.
Ascribe encountered technical problems when using this method, which mainly stemmed from the Bitcoin blockchain itself. It is slow to write everything to it, costly (currently 80 cents per time) and limited daily entries and total write capacity. It is also contrary to typical scalable database techniques, adding nodes does not improve performance, and there is no real query language. This makes business expansion based on Bitcoin blockchain a challenge.
However, the blockchain concept is a powerful concept, and its use and legitimacy have increased over the past few years, and even large banks have announced that they are developing technologies inspired by the concept.
Ascribe decided to combine the advantages of the two, adopting a proven NoSQL database (RethinkDB) and adding a blockchain layer to it to enhance control, asset tracking and additional security levels.
The combination of this technology is particularly attractive to NoSQL database users, as few NoSQL database support has traditionally helped ensure that the database changes have occurred "transactions". BigchainDB adds transaction support by writing to the underlying NoSQL database through the blockchain layer.
BigChainDB also claims to be completely decentralized due to the blockchain layer. While many distributed NoSQL databases claim to be decentralized, there are often pseudo-master/slave settings.
Installing BigChainDB and its dependencies
There are several ways to install BigChainDB. First I tried Docker image, but encountered some connection issues and found that the Python package is the most reliable.
- Install RethinkDB, and for other Mac users, there is also a Homebrew package available.
- Install Python 3.4.
- Install BigChainDB with Pip – sudo pip install bigchaindb
- Start RethinkDB with rethinkdb
- Start BigChainDB with bigchaindb start, it will also configure some content for you.
- Open BigChainDB (actually RethinkDB UI) at http://SERVER_IP:58080/.
Simple Example - Message Allocation and Tracking
One of the main use cases of BigchainDB (and why Ascribe created it) is to track assets, so let's create a simple example in Python. First run the following command in your terminal.
pip install bigchaindb bigchaindb configure bigchaindb show-config
Create a new file, app.py and add the following:
from bigchaindb import Bigchain b = Bigchain() print(b)
This will import the bigchaindb library, create a new object and connect to it using the settings file you just created.
Then run the Python application:
python app.py
You should see something like <bigchaindb.core.bigchain at 0x...>
, which tells us everything is fine.
Add the following:
from bigchaindb import Bigchain import time b = Bigchain() spuser_priv, spuser_pub = b.generate_keys() print("User Created") digital_asset_payload = {'msg': 'This is my special message just for you'} tx = b.create_transaction(b.me, spuser_pub, None, 'CREATE', payload=digital_asset_payload) print("Transaction Written") tx_signed = b.sign_transaction(tx, b.me_private) b.write_transaction(tx_signed) print ("Transaction Written to BC, now waiting") time.sleep(10) tx_retrieved = b.get_transaction(tx_signed['id']) print(tx_retrieved)
This will create a user and associated key to access the database – remember the additional security level. Then create a payload for writing to the database, allocate the required key, and write it.
How many seconds does a new transaction take to pass from the blockchain layer to the database. The code waits for ten seconds, and then retrieves and prints the record. You should see something like the following:
{ "signature": '304502205...', "id": "0f442bcf4a42...", "transaction": { "timestamp": "1457104938.430521", "data": { "hash": "b32779e57...", "payload": { "msg": "This is my special message just for you" } }, "operation": "CREATE", "current_owner": "hFJKYk2...", "new_owner": "26pdiQTTx...", "input": None } } }
You now have a special message that you want one person to be able to access:
... print("Now to transfer") spuser2_priv, spuser2_pub = b.generate_keys() print("Second User Created") tx_transfer = b.create_transaction(spuser_pub, spuser2_pub, tx_retrieved['id'], 'TRANSFER') print("Transfer Created") tx_transfer_signed = b.sign_transaction(tx_transfer, spuser_priv) b.write_transaction(tx_transfer_signed) print ("Transaction Written to BC, now waiting") time.sleep(15) tx_transfer_retrieved = b.get_transaction(tx_transfer_signed['id']) print("Transferred") print(tx_transfer_retrieved)
This will create a second user, then get the transaction ID of the special message and transfer it to the second user. BigChainDB's blockchain layer will prevent users and your code from performing the same operations twice. If you try to run the above code again, a double spending exception is thrown.
This example shows a small part of how BigChainDB is added to RethinkDB, and a complete list is available here.
HTTP endpoint
Currently, the only client library available for BigChainDB is Python, and there may be more libraries, but at the same time, a limited HTTP endpoint can be used to query existing transactions:
https://www.php.cn/link/6eea81fa0417b0068e614074225a9daf
Or write a new transaction using the following method:
https://www.php.cn/link/f8b64946ebc86a5e23e1605a2943210c
Add the following payload, where the operation can be changed to suit different types of transactions that can be written:
{ "id": "", "signature": "", "transaction": { "current_owner": "", "data": { "hash": "", "payload": null }, "input": null, "new_owner": "", "operation": "", "timestamp": "" } }
Components of the Decentralized Future
Ignore the origin of its blockchain for the time being, BigChainDB provides a large number of features missing in current NoSQL and distributed databases. This fact alone may be the reason to try it and may provide a valid business/use case.
For blockchain enthusiasts among you, it also completes the puzzle of a complete decentralized application stack. In theory, there is now Ethereum for applications, IPFS for file systems, and BigChainDB for data storage. These components set the stage for very different ways of developing, deploying and maintaining applications, creating a fascinating future, and I hope to hear your comments on this in the comments below.
(The FAQ part is omitted here because this part is just a simple summary and retelling of the content of the article and does not fall into the category of pseudo-originality.)
The above is the detailed content of Managing Data Storage with Blockchain and BigchainDB. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

Fastapi ...

Using python in Linux terminal...

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...
