5: Match with Crux – Saturn Assignment
NOTICE: Crux has been renamed to XTDB. This tutorial is now available at https://nextjournal.com/xtdb-tutorial instead. Please consider the following tutorial deprecated.
This is the
match installment of the Crux tutorial.
You need to get Crux running before you can use it.
Arrival on Saturn
As you pass through the innermost ring of Saturn, A warning light appears on your communications panel. You open the message. It’s from Space Customs and reads:
They are asking to see your flight manifest.
Choose your path:
You have your manifest : You have permission to land, continue to the space port.
You do not have your manifest : You do not have permission to land. You can either return to Neptune or continue at your own risk.
As you prepare to land you open your Crux manual to the page on
You are happy with what you have read, and in anticipation of the assignment you define the standalone node.
As you land on the surface of Saturn the job ticket for this assignment is unlocked.
The next shuttle to the CMT office leaves in 5 Earth minutes. While you wait you use your easy ingest function you created on Pluto to put the example data into your system.
You also decide to make some Clojure functions so you can easily show Ubuku the stock and fund levels after the trades.
Just as you are finishing off your shuttle arrives.
After a short journey through the icy lower clouds of Saturn you are met by a friendly faced Ubuku.
Choose your path:
"Yes, I'll give it a go." : Continue to complete the assignment.
"I'm not even sure how to begin" : Take some time to read through the Crux manual again. If you're still unsure then you can follow along anyway and see if things become clear.
You explain to Ubuku that all they need to do to solve their problem is to use the
match operation instead of
put when they are processing their trades.
You show Ubuku the
match operation for a valid transaction. You move 10 units of Methane (
:units/CH4) each at the cost of 100 credits to Blue Energy:
You explain that because the old doc is as expected for both the buyer and the seller that the transaction goes through.
You show Ubuku the result of the trade using the function you created earlier:
They are happy that this works as he sees the 1000 credits move from Blue energy to Tombaugh Resources Ltd. and 10 units of Methane the other way.
Ubuku asks if you can show them what would happen if there was not enough funds in the account of a buyer. You show him a trade where the old doc is not as expected for Encompass trade, to buy 10,000 units of Gold from Gold Harmony.
You explain to Ubuku that this time, because you have both
match operations in the same transaction, the trade does not go through. The accounts remain the same, even though the failing
match was the second operation.
Ubuku thanks you. This is just what they are looking for. You head back to the space station to see if there is another assignment waiting for you.
Back at the spaceship there is a light waiting for you on your communications panel.
You update your manifest with your most recent badge.
As you do so, you check to see if you still have the note that the porter gave you for Kaarlang back on Earth.
Feeling a bit apprehensive, you enter countdown for lift off to Jupiter. See you soon.