Paying Taxes on Cryptocurrency

If you currently invest in cryptocurrency or are thinking of doing so, one aspect to consider is the tax ramifications. Whenever you sell crypto, if you make a profit, the IRS will want its cut. If…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Planaria Systems Programming Interface

Opening up a whole new dimension to programming Bitcoin powered state machines

And today, Planaria is opening up a whole new layer of its programming interface. On top of “application programming” you’ll be able to do “systems programming”.

You will be able to run all kinds of things on Bitcoin. Some examples:

All this is now possible because Planaria is opening up its “systems programming interface” to let developers do more low level things while taking full advantage of the exact same transparent computing model of Planaria, where each Bitcoin transaction is a command. This means all commands and their resulting state transitions are 100% transparent to the world, WITHOUT having to store the entire state machine on chain.

Instead of storing the entire state machine on chain, you can basically “reproduce” a deterministic state machine from Bitcoin transactions, with minimal data stored on Bitcoin itself.

If you’re not technical but interested in brief explanations on how all this will happen, scroll to the bottom of the post.

Otherwise, let’s go!

Today Planaria is taking the first step to opening up its “Systems Programming Interface”.

Planaria node developers now have access to much more powerful features, including:

Today we’re taking this to the next level.

If the file serve API gave you limited access to a single folder named assets, the new Planaria File System interface lets you access the ENTIRE file system in which Planaria (for writing) and Planarium (for reading) operate.

Until now, every Planaria microservice had two powerful built-in API endpoints:

But now with the file system support, you may want to add additional endpoints to serve your files, or even other data added to your Planaria state machine through other means.

And starting today, you can add your OWN custom GET HTTP endpoints through planarium.js

Here’s what it looks like:

In this example we’re defining a GET /c/:id endpoint which will automatically map to the following URL:

Here’s an actual example of what this may look like:

All Planaria endpoint URLs are prefixed by its machine address. Each machine is uniquely identified by its Bitcoin address (instead of its host HTTP URL). This is how Planaria ensures application portability.

Because the machines are identified by the Bitcoin address and NOT the host’s HTTP URL, all Planaria state machines are independent from whichever host they’re being served from, and independent from the server-client based HTTP scheme. It’s Bitcoin native.

The same machine, when run by another host, would look something like this, for example:

They would have EXACTLY the same state as the other endpoint because they’re constructed from the same code.

With all these new things you can do with Planaria, you’ll immediately realize you need some way of initializing various modules you’ll be using throughout the rest of the machine’s lifecycle. For example, you may want to:

To facilitate this, Planaria has added a new event handler named oncreate. The oncreate event will be called EXACTLY once when the machine is initialized.

And of course, since there are two containers, we have oncreate initializer for both:

Here’s an example planarium.js setting (under query.api.oncreate)

Here’s an example planaria.js setting (under oncreate)

C:// generates filenames by SHA256-hashing the content uploaded through Bitcoin and storing the file content under the content hash as filename. This means there’s exactly one universal filename per unique content, which introduces interesting properties that lets us use the files as building blocks for deterministic applications.

But first before we go in, you can find the entire code AND the public node running at:

For this machine we make use of the newly introduced event handler called oncreate.

For Planaria, this gets executed exactly once when the machine first starts its life. It is run only once the first time the machine is run, and after that onrestart is called instead whenever the node restarts.

Since we only want to mkdir once in the beginning, this belongs inside oncreate of planaria.js.

We also want to access the files and the LMDB instance from planarium.js since we want to provide an API endpoint. So we initialize them inside planarium.js as well:

You may have noticed the m.fs.path variable used in the code above. This environment variable contains the root path of the Planaria file system, shared by both Planaria and Planarium containers.

Internally, Planaria creates a folder structure that looks like this:

Note that this example is an example of a heavy use case, and in many cases you would be running just a single machine and there will be only one folder under /fs.

But essentially, each Planaria machine has its own sandboxed filesystem. This is important because a Planaria node can run multiple machines simultaneously, and files from each machine shouldn’t spill over to another file system.

That said, you don’t have to know this deep to make use of the API. All you need to remember is that the m.fs.path that gets passed in from every callback onmempool, onblock, oncreate, onrestart references the root folder of the machine’s file system. You simply need to use that variable.

For example if you want to create a folder named /c you simply need to do:

Another important thing: The file system is shared across Planaria and Planarium containers. So you can WRITE state from Planaria, and make use of the state from Planarium.

Here’s a more concrete example usage of this m.fs.path variable:

For a file server to work properly, we need to set the content type header for every file served. Otherwise browsers may not understand how to render and just download the files to the file system instead of displaying them in the browser.

But extracting this metadata at file load time may be inefficient. So here we will try to store content types at crawl time, cache it once, and then use it for every file load.

One way to do this would be to query the built-in MongoDB instance which already stores this metadata. But we’ll try something different here because we don’t want to spam the core database every time a file is requested.

Once we’ve created these entries, we can then access them from planarium.js and serve all this. We just need to add a new custom API endpoint, which I will explain in the next section.

You can define your own custom external facing HTTP Routes under query.api.routes inside planarium.js.

Remember that ONLY Bitcoin can write to Planaria. There is no “POST” or “PUT” or “DELETE” requests to Planaria. All writes to Planaria are done through Bitcoin, so if you want to write, you make a Bitcoin transaction.

Notice how we’re accessing the same LMDB instance we wrote to earlier (from planaria.js).

The two containers (planaria and planarium) share the same file system so you can write from planaria.js and read from planarium.js. Here we access key/value pair we stored earlier inside planaria.js, after which we set the value as the content type header before serving the file.

Feel free to learn more about how it works at:

Also you can use the API from the public node too:

If you think about it, everything runs on a file. And all applications are just files, which make use of other files.

Once you see it this way, you’ll realize that Planaria can be used to build all kinds of full fledged Bitcoin-powered computation backends.

Below I’ve listed some interesting technologies that are all built on files just to help with imagination.

But think about it. EVERYTHING IS A FILE.

By the way, did you notice how every aspect of everything I’ve just explained is a money making opportunity?

You can run powerful deterministic transparent services powered by Bitcoin and make money. Today. People will pay the services to run programs. And Bitcoin will act as the immutable witness, in case any service provider tries to cheat, which provides “trust” for these operations.

That’s what Bitcoin is capable of. And that’s what Planaria does.

And best of all, Planaria is not some science fiction or scam whitepaper selling the future that will never come. You can go use public nodes right here:

Or even run your own and provide your own public node as service.

Planaria is here, today.

All of what’s explained in this article is possible, today.

Bitcoin can do all this, today.

Let’s go build.

Join us.

Add a comment

Related posts:

The Origin Story

Habits are hard to break and good habits should never ideally be broken. It was therefore painful to find ourselves in the middle of global Covid-19 lockdown unable to practice the good habit of…

March Development Update

The next major RenEx update is almost ready for deployment to the RenEx Testnet, entering the final stages of development. We have listened to feedback from the community and have overhauled the…

Backing the Jean pool

Backing the Jean pool… Levi Strauss is set to price itself at $6.2 billion as the jeans maker prepares for a return to the public markets, more than 30 years after the company was taken private. In…