In 2018, Komodo Platform added cryptoconditions to thier codebase, and lots of testing has taken place leading to a new suite of dApps. I've been busy working on the Dragonhound dApp (for asset tracking) in the KMD Labs, a community Skunkworks project.
Dragonhound offers a cartographic interface using LeafletJS to display the GPS location data history of a Particle.io Asset Tracker, which is stored in a tactical pouch attached to a OneTigris K-9 Harness, and worn by a wandering hound with a lust for freedom who I've bailed out of lock up more than once.
Tying all this together is a Komodo assetchain (currently in testnet) which uses an Oracle Crypto-conditions smart contract to store GPS data emitted from the Particle.io device, and retrieve it for display with python RPC functions via the Django framework.
As this is new tech, simple to understand documentation is in short supply. Below I'll walk through the steps for creating an oracle from Ubuntu 18.04 command line, and then storing and receiving data on it.
oraclescreate takes 3 parameters - name, description and format. The example above uses "S", which will allow us to store a string up to 65536 characters long.
It returns a hex, which is broadcast to the network using
The Oracle Transaction ID
To confirm your oracle has been created, use
oraclesinfo to view its details, using the oracletxid as a parameter.
To register as a publisher on the oracle, use
oraclesregister. It's parameters are the oracletxid and a data fee, which is expressed in satoshis and should be more than the network transaction fee.
Make sure to broadcast the raw hex to the network using
sendrawtransaction. Once the transaction has been processed (you can check this with
getrawmempool), if you run
oraclesinfo again, you'll see your registration details.
To use the oracle, it needs to be funded. This is done using
oraclesubscribe, with the parameters oracletxid, publisher and amount.
Sending data is a little more tricky. Our string needs to be converted to hex, and include a portion to indicate it's length. So to begin, we need to get the byte length (in hex) of the data we want to write to the oracle.
The oracle data being sent is prefixed with a four char hex string indicating the length of the data being sent. Depending on the byte length, padding may be required to fill this prefix. The added padding is as follows :
So in the example pictured, bigend would be
0045. Now we have to convert the prefix from big endian to little endian :
Now we combine the prefix
4500 to the hex string of the data you want to write to the oracle.
Now we have our string data in a format the oracle will accept!
Data is sent to the oracle using
oraclesdata, which takes oracletxid and the hexstring which we created in the last step. This returns a raw transaction hex which we broadcast using
Once the raw transaction has been validated by the network, we'll be able to query the oracle to retrieve it.
Data stored on the oracle is using
oraclesamples. Its parameters are the oracletxid, its batontxid, and num. The batontxid is a reference point for what our starting point is for the records we want returned, and num is how many records back from the reference batontxid. You can get the latest batontxid using
This batontxid is the tip of all the data stored in the oracle. If the num parameter is
1, it will return the most recent data sent to the oracle.
As the data I'm working with is sensitive location intel, the GPS data is encrypted before being stored - this is optional, most oracles would be data intended to be publicly accessible to subscribers.
This is more easily done in python, and will be explained in a future post. If you're interested now, an example is available on the Dragonhound github repository.
Note: The repo linked above uses CherryPy and has been abandoned in favour of using Django.
Got questions? Drop into the Komodo Discord and ask away!