Code Start

As we covered in the previous posts, I plan to build a blockchain like software because I want something that runs on Raspberry Pi and I also want a bit more control. I have selected C++ and Cloud9 as my tools. Now to use them.

I first created a new user for myself and potentially others who I might use my Cloud9 account. AWS has tutorials for all of this, that is how I learned. So with a new user and IDE in the cloud, I was ready to start.

I first wanted some standards. I wanted a comment standard to follow. So I read various coding standards for C++ and selected the ones that looked the most standard and new–Google got my attention. I will try to fit close to their standard. I noticed that they restricted the Boost library functions to use to only those approved to use. Most of the ones I was looking at were not approved.

After some tries and thought, I wrote this and like it (sorry it is not in the best font–Don’t know how to change that):

/**

Copyright 2018 Michael R. Wild

Permission is hereby granted, free of charge, to any person obtaining a copy of
 this software and associated documentation files (the "Software"), to deal in
 the Software without restriction, including without limitation the rights to
 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 the Software, and to permit persons to whom the Software is furnished to do so,
 subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
 copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE

@file mcpmain.cpp
 @author Michael R. Wild
 @date 3/6/2018
 @version 0.0.1

@brief Master Control Program

@section DESCRIPTION

This is the description

@section CHANGES

20180306 Creation

*/

I decided to release the code and to use @-notation to capture relevant information. I liked the idea of having the information available to an editor. The MCP is a reference to the old TRON movie. I have to admit it took me days to decide on this and I read a lot of standards.

The main (not easy to show as I had to embed some characters) is just a group of demos. Still learning and guessing how to do all of this. I have not used the convention of std being defined before. I have not written formal C++ and was taken aback by some of the changes in standards I read. Now define the minimal and key a bit more. I also like the auto to define the obvious.

#include <iostream>
#include <ctime>
#include "mcp.cpp"

int main()
{
    
    MCPParms ourparms("some.xml"); // parms for program
	
	// Print a header of execution out
	auto result = std::time(nullptr);	
	std::cout << "Master Control Program " << std::endl;
	std::cout << "Local Time: " <<
	    std::asctime(std::localtime(&result)) << std::endl;
	    
	// Try to get the parms for the MCP
	std::cout << "Read in MCP controls " << std::endl;
	try
    {
        ourparms.load();
        std::string name = ourparms.get("mcp.programtext");
        std::string version = ourparms.get("mcp.version");
        std::cout << "Success: " << name << " " << version << std::endl;
    }
    catch (std::exception &e)
    {
        std::cout << "Error: " << e.what() << std::endl;
    }
    
    // update something
    ourparms.put("mcp.more", "This is a test");
    
    // get update
    try
    {
        std::string name = ourparms.get("mcp.more");
        std::cout << "Success: " << name << " " << std::endl;
    }
    catch (std::exception &e)
    {
        std::cout << "Error: " << e.what() << std::endl;
    }
    
    // save change
    try
    {
        ourparms.save();
        std::cout << "Saved!" << std::endl;
    }
    catch (std::exception &e)
    {
        std::cout << "Error: " << e.what() << std::endl;
    }
    
    // Leave politely
    return 0;
}

The code read in an XML file into a tree structure. I really like this as I can just load data into a tree from a file and look it up and update it and even write it back. That gives me all sorts of ideas.

Next time I will expand the information into the includes. Once that happens this Blog will be caught up and I will have to code and Blog at the same time. I am thinking of blogging on Tuesdays and Thursday and code the other nights.

 

Boost

You can find at Boost Org the fantastic library of free and handy code. I remember writing my first tree structures and data structure code back in the 1980s (during the pre-Internet times) in Pascal and wondering why we had to write this code–it should be available. I remember having to recopy in all of my code into the compiler I wrote to do a tree search. Boost covers much of this and many things that were just ideas–dreams–in the 1980s (like XML parsing).

I first learned of Boost when I was trying to compile some blockchain code. The Boost version of the Raspberry Pi OS, Raspbian was one version too old. Annoyingly, the code for the blockchain solution contained legacy code that would not compile at a higher level. I learned how to build Boost on a slow Raspberry Pi 3. I still could not get the code to run. I moved on but liked the Boost library.

The Boost library is meant to extend C++. I have written C++ for years for so many sketches for the Arduino. I have written some pretty impressive code for robots and other projects in Arduino’s version of C and C++. I was feeling confident I could code C++.

I saw that advertisements on Amazon for Cloud9, a development platform. It was cloud-based and free. This being Amazon Cloud it would likely cost something, usually about the cost of coffee in Starbucks (this is the PNW). I tried it out and create my first server. The IDE was a weak Eclipse version, but it could do all the languages I might need and some I did not need. Go was missing–Google’s language, but as Google is a competitor to Amazon it was not a surprise. It has C++ and version 9 and Python 3.6+, so I was happy.

The editor worked with some coloring for reserved words and some standard completion logic. It has the requirement that you save your work to a file for it to work well. I also noticed that the first compile failed and then worked after that. Again, the file needs to be there for the compile options to work I think.

I had trouble with remembering my C++ and made a few basic mistakes. The Arduino code I worked with over the last four years is not as formal as the includes of GNU C++, but once I finally took a quick online class from YouTube, I got my C++ to run. I do not remember “Hello, World” as this hard!

I used the Linux terminal to update my software and load Boost library 61, newest version. I followed the directions and built a library. It was in my workspace and not in the compile path. I created a link to the director in the correct place, and then it worked.

With Boost now working and an IDE and me remembering my C++, we are ready to start our project. Next post we’ll look at that.

New Project: Blockchain by me

Welcome to my first post.

My plan is to share my designs here.

I am also using editing software to avoid glaring typos. Please let me know if it missed a typo. I would like to get even with it!

So the first item to discuss is what I intend to do. Well, I have learned a lot about blockchain, and I have looked in detail at how to use IBM’s Hyperledger known as Fabric. I was surprised that the source is available, but instances are not really able to be installed and forked. Maybe someone else can find a way to do this, but I was unable to get that to work. I looked at a couple more, and they needed a unique combination of Linux and Boost library levels with all sorts of add-ons that had restricted versions. I did find Etherium was able to be installed and it can be forked. I did require newest releases, and these are not able to run on Raspberry Pi.

I want to run a blockchain example on a group of Raspberry Pis. I have purchased quite a few and intend to use them in a group and exchange information via blockchain like technology. Nothing really seems to work and even if it did the likelihood that it would be stable was small.

I also noticed that I did not like the code and structure of the design. I thought I could do better and I needed something less complex for the Raspberry Pis. Also, I am not sure I understand all the issues and need to account for them in the code and papers I read. I needed something less complex, maybe without all the crypto, and would actually run meaningfully on Pis.

So with a tip-of-the-hat to software heroes, I decided to write my own. But now the question came, on what? So I got the Raspberry Pi running and immediately found it slow and hard to use. The 30 hours to install Boost Library for C++ was still also fresh in my mind. I had spent hours and hours trying to get a descent Pi environment. So I did not really want to run my development on a Raspberry Pi.

My Apple computer is cool (I like to use cool here–the editing software is complaining and suggesting fresh) and fun, but I am not sure I want to test blockchain code and processing on my computer I run my life on. I have a few spare Windows and an Ubuntu server. I decided to try Linux. I tried to get Go to well go, and that was less positive than I expected. Python? Well, I like Python, but I think all of the libraries I will need will be in C++.  So C++.

Next, I found that Amazon has a new Cloud9 offering for well exactly what I was looking for, Linux based development.  Got my account running on Amazon. Cloud9 is free and thus costs about $2.00 a month. “Carrying charges,” I am told by the fat man at the Blue Parrot. 

I then loaded Boost newest. I was worried that the server would just fail. It finished the make in an hour or so. Great! I then hooked it into the library structure. I then wrote a fine C++ program to run an example program for one of the libraries. Success!

So in the first post, we learned that I am building a Raspberry Pi based example blockchain. I cannot find software that I believe will be stable and that I can understand. I decided to use Amazon’s Cloud9. So far I have Boost loaded and working.

A good start, I think.

cropped-mrw-cooking.jpg