How to keep diary in blockchain
constructor(index,timestamp,data,previousHash=' 39;)< br />{
this.index=index;< br />this.timestamp=timestamp;< br />this.data=data;< br />this.previousHash=previousHash;< br />$this.hash=this.calculateHash();< br />}
calculateHash(){
return SHA256(this,index+this.previousHash+this.timestamp+JSON.stringify(this.data)).tostring();< br />}
}
class blockchain{
constructor(){
this.chain=[this.createGenesisBlock()];<
}
/ / create a generated information block
creategenesis block() {
return new block (0, & quot; 01/01/2019",& quot; Genesis block", 0);
/ / the date is the user's data. In fact, it is the hash value obtained by adding several values together. Here, the information is encrypted and the picture is encrypted. Then the data is still stored in the database, but all the data are hash values. To get this data, you must know the hash value of the previous data block. Then, if the hacker needs to crack all the nodes, the hash value is decrypted, Then all the blocks from the first node to the last node can be decrypted to get the real data. So the security of data stored in the blockchain depends on whether the data is encrypted. If the plaintext is not encrypted, then it is not a blockchain
}
/ / get the last block
getlatesblock() {
return this.chain [this.chain. Length-1]
}
/ / create block
addblock (newblock) {
newblock. Previoushash = this. Getlatesblock(). Hash< br />newBlock.hash=newBlock.calculateHash();< br />this.chain.push(newBlock);< br />}
}
on the other hand, all nodes (computers in short) participating in the network will store one account book, which is updated in real time. Even if one node fails, the blockchain will not be affected.
generally, the blockchain platform will provide corresponding interfaces, such as RPC, json-rpc, HTTP, etc. of course, the platforms are not the same, and the degree of friendliness is different
some companies specializing in API, such as blockcypher, can provide friendly calling interfaces, and it is not very convenient to write answers on the mobile phone, Search below
as for the storage content, add a point: in addition to the conventional cloud storage, file entities on the file hash record chain also have blockchain based storage schemes, such as IPFs, storej and so on
In the traditional supply chain finance, financing difficulty, high financing cost and cumbersome financing process have always been one of the bottlenecks restricting small and medium-sized enterprises to become bigger and stronger. Banks rely on the ability of core enterprises to control goods and regulate sales. For the sake of risk control, banks are only willing to provide factoring services to upstream suppliers (limited to first tier suppliers) with direct accounts payable obligations of core enterprises, or provide prepayment or inventory financing to their downstream distributors (first tier suppliers). As a result, the demand of secondary and tertiary suppliers / distributors with huge financing demand can not be met, the business volume of supply chain finance is limited, and the small and medium-sized enterprises can not get timely financing, which will easily lead to proct quality problems and damage the whole supply chain system
to solve these problems, we can make use of the characteristics of decentralized, tamper proof and distributed ledger of blockchain technology to build a blockchain supply chain financial platform
The core enterprise issues a / R certificate to the distributor. After the distributor signs the receipt, it indicates that it has signed the purchase and sales contract and the core enterprise delivers the goods Because of the shortage of funds, distributors need to borrow money from finance3. After the financial institutions have approved, the amount of loans will be sent to the core enterprises
The distributor will repay the loan and interest after selling the goods