This article uses the bitcoin testnet as the development test environment and combines Node.js to implement the identity registration function of the PPkPub open source project ODIN as a specific application case to illustrate how to use multi-signature transactions to embed custom data and broadcast it after signing. After being confirmed by the miner node and stored in the blockchain, it can finally be read and parsed to obtain the registration result, thus realizing a complete process from writing to reading from the blockchain.
As the first open source project released by the PPkPub open group, ODIN is the abbreviation of Open Data Index Name . In a broad sense, ODIN refers to an open system for identifying and exchanging data content indexes in a network environment. It complies with the URI (Uniform Resource Identifier) specification and provides an extensible framework for autonomous, open, secure and reliable data content management and intellectual property management based on the digital cryptocurrency blockchain (BlockChain). It includes 4 components: identifiers, resolution systems, metadata and policies. In a narrow sense, ODIN refers to a permanent open identifier that identifies any data content object. ODIN can be figuratively understood as the "autonomous domain name in the data age". It is a completely open and decentralized naming and identification system based on the Bitcoin blockchain and is scalable and compatible with more blockchains. Compared with traditional DNS domain names, it has more innovative features and can be well applied to emerging fields such as big data, smart devices and the Internet of Things. With reference to the technical principles of digital cryptocurrencies such as XCP (Contract Coin) and Mastercoin, ODIN is implemented by encoding specific message data according to the Bitcoin protocol specifications, broadcasting it to the Bitcoin network as a Bitcoin transaction and storing it in the blockchain. Each ODIN message includes the following characteristics: (b) A Bitcoin destination address (corresponding to the target individual pointed to by the ODIN message. When the message generator and the target individual pointed to by the message are the same, this address is empty) (c) Several 1-of-N multi-signature output Bitcoin address public keys (generated by encoding in the ODIN data packet. When actually generating a transaction, 32 bytes are extracted from the ODIN setting data in sequence, and 1 byte corresponding to the length of the string is added to the front of the 32 bytes. A total of 33 bytes correspond to a Bitcoin public key. If the number is less than 33 bytes, binary 0s are automatically appended to the end until it reaches exactly 33 bytes, corresponding to a compressed public key) (d) There is a certain amount of Bitcoin balance in the Bitcoin source address (it is recommended to have more than 0.001 BTC to generate several valid transaction entries sent from the source address to the destination address to be embedded in the ODIN data packet. Note: Due to the characteristics of Bitcoin 1-of-N multi-signature transactions, these Bitcoin amounts will not be actually spent and will be recycled in the next ODIN message) (e) A fixed fee for the message cost in Bitcoin (default is 0.0001 BTC), which will be paid to the Bitcoin network miner who includes this transaction data block. (f) a Bitcoin change address (the same as the Bitcoin source address in the first item above, used to recover the excess amount of the Bitcoin input transaction after generating several transaction entries that meet the requirements of embedding the ODIN data packet to the sender's account in accordance with the Bitcoin transaction protocol) The above feature (c) is the key to the implementation of the technology. The ODIN data block will be embedded in the multi-signature output data block of the Bitcoin transaction, which is a 1-of-N output. The first public key of each data block is fixed to the sender, so the output currency value can be redeemed and recycled. The address space storing the second to Nth public keys is used to store the encoded ODIN message data. For detailed description of Bitcoin multi-signature transactions, please refer to the Bitcoin protocol specification. The format of each ODIN information data block is defined in byte order as follows: Bytes 1-32: Prefix feature identifier, 32-byte ASCII string "P2P is future! ppkpub.org->ppk:0" (excluding double quotes on both sides) Byte 33: Message type, 1 byte. The 34th byte to the end of the message is different message data distinguished by message type. For details, see the definition in the specific ODIN message type. Note: For easy identification, each ODIN message is prefixed with a 32-byte ASCII string "P2P is future! ppkpub.org->ppk:0" (without the quotation marks on both sides). This string is very long, so it is impossible to confuse ODIN-specific transactions with other Bitcoin transactions. The following is the specific message definition for "newly registered ODIN identifier" in the ODIN protocol: Bitcoin source address: corresponds to the ODIN identifier registrant Bitcoin destination address: corresponds to the ODIN identifier owner The format of the message data block is defined in byte order as follows: Note: Configuration permission value description: ASCII character 0, 1 or 2 —————————————————————————————————— Assume that there is the following example of ODIN identification registration information: Then, according to the above message definition, it can be assembled into a Bitcoin transaction record to be broadcast to the Bitcoin network for effectiveness. The original data of the corresponding transaction is as follows (the original binary data is output in hexadecimal ASCII code format by byte for easy analysis): 01000000 // Version number, UINT32 03 // Number of Tx inputs, variable length INT. 0×03 = 3 inputs. /*** Next is the first group of Input Tx ***/ /*** The second group of Input Tx. Same as above, omitting the decomposition***/ /*** The third group of Input Tx. Same as above, omitting the decomposition***/ /*** The first group of output ***/ /*** The second group of output ***/ /*** The third group of output ***/ 00000000 // Lock time, UINT32, fixed 4 bytes Combined with the ODIN protocol definition content described above, the corresponding ODIN identification registration message can be restored and parsed through the blue area in the above transaction data. 3. Run the sample program The sample program consists of two parts: 2. OdinRegisterTestnet.js: Download the sample code above and save it to a test environment where Node.js is installed (the saved files are named OdinRegisterTestnet.js and OdinMonitorTestnet.js). Before running the above sample program, please make sure that the Docker runtime environment of the Bitcoin test network (bitcoin-testnet) has been installed. If it has not been installed, you can refer to the instructions in the "Bitcoin Blockchain Development Guide from Beginners to Advanced 2" to install it (http://www.8btc.com/ppkpub_blockchain_develope_lesson_2). Open a new text terminal window in the Node.js development and testing environment, and enter the following command in the command line to start the monitoring sample program: Then open a new text terminal window and enter the following command in the command line to run the registration sample program: After running the registration sample program, enter "make generate BLOCKS=6" in the command line of the Docker runtime environment of the Bitcoin test network (bitcoin-testnet) to simulate the generation of new block records. The newly generated transaction records will be effectively confirmed and stored in the blockchain. At this time, the monitoring program's running interface will prompt that the new ODIN identifier registration record has been parsed (as shown in the figure below). |
<<: Let’s talk about comics: Who is the man behind the blockchain?
>>: Ethereum co-founder Taylor Gerring: Hard forks can make the network more resilient
It is very important for a woman to marry well. I...
In physiognomy, we can also analyze a person'...
It is said that a man cannot be poor. If a man ha...
Unlike most blockchain projects that only have on...
Many people may think that most beautiful women h...
Everyone has physiological needs, but some people...
If the moving line and the original changing line...
What is your persistence in life? Everyone is per...
There are moles of different sizes distributed in...
From the perspective of physiognomy, no matter wh...
In ancient times, the Palace of Marriage was also...
From the surge to $60,000 at the beginning of the...
Wu said blockchain learned that Sichuan Power Tra...
Sometimes, we can see the development of our fort...
The mouth is the most important part of a person....