-
Notifications
You must be signed in to change notification settings - Fork 1
Publishing
Aakil Fernandes edited this page Jul 1, 2015
·
12 revisions
Publishing is the act of broadcasting a vendor's data to the Bitcoin blockchain. Once a vendor's data has been published, anyone can retrieve his/her data by supplying the xpubkey
.
At a high level, the vendor data is compressed into a msgpack byte array, signed, and split into 37-byte chunks called "manifest chunks". Each manifest chunk is given a 3-byte header for a total of 40-bytes.
The following is pseudocode to help understand the publishing process.
//pack the vendor data using the msgpack encoding scheme
vendorDataMsg = msgpack.encode(vendorData)
//sign the vendor data with the vendor's address
signature = sign(vendorDataMsg,vendor.address)
//compute the number of transactions a broadcast will take
transactionsRequired = ((1+vendorData)/37).roundUp()
//the publishing algorithm can only handle up to 255 transactions
if(transactionsRequired>255) throw 'Too many transactions required'
//add everything together into a single byte array
manifest = [transactionsRequired] + signature + vendorDataMsg
//split the bytes into chunks of 37
manifestChunks = manifest.splitIntoChunksOfByteSize(37)
//determine the random byte (byte #2 of the 3 byte header)
randomByte = random(0,255)
//create an OP_RETURN transaction for each chunk and broadcast it to the network
manifestChunks.each(function(vendorDataMsgChunk,index){
sendrawtransaction('OP_RETURN',header(randomByte,index)+vendorDataMsgChunk,vendor.address)
})
All fields are to be decoded using UTF8. Only the product image url is optional.
- Name (n)
- Currency (c)
- Pgp Key Data (k)
- Info (i)
- Array of Products (p)
- Name (n)
- Price (p) (string)
- Image URL (i) (optional)
Each manifest chunk contains a 3 byte header.
- A constant
0x6D
to indicate a manifest chunk.0x6D
is the hex code form
. - A random hex between
0x00
and0xff
. This is to help protect against manifest chunks from different manifests from being comingled. - The index of the manifest chunk in the manifest. For example the first chunk would have a header of
0x00
while the second one would have a header of0x01
.