...by Daniel Szego
quote
"On a long enough timeline we will all become Satoshi Nakamoto.."
Daniel Szego
Showing posts with label Hedera. Show all posts
Showing posts with label Hedera. Show all posts

Thursday, July 5, 2018

Hashgraph SDK Tips and Tricks - implementing your first application


If you already started to implement your first application with the Hedera Hashgraph SDK as it was summarized in the previous blog, you should continue with the following:

1. Extend your State class with additional elements storing state variables, like lists, arrays, hashmaps.

2. Rewrite the copy functions of your State class to cover the newly introduced state variables. 

3. Implement custom query functions in the State class to query the newly introduced state variables. 

4. Rewrite the init function of the Main class, to use any kind of custom initialization. Like, you can query the setup up parameters of the config file with platform.getParameters(), or you can create new consoles or windows with the platform.createConsole(true) and platform.createWindow(true) functions.

5. Rewrite the run() function of the Main class to run any kind of the required custom logic for your node. 

Hashgraph SDK Tips and Tricks - starting with your first application


If you start with your first application with Hedera Hashgraph, the easiest way is to download the SDK from the homepage and copy and start modifying one of the existing applications. For this:

1. Download the project from : https://www.swirlds.com/download/

2. Copy one of the applications under  sdk/source

3. Rename the folder and rename the name references in the pom.xml file.

4. Open Eclipse

5. Import the files as a "Maven" project

6. Rename the Main and State java files, objects and all the references to the name of your projects

7. Press "Run As" as "Maven Install" to get the binaries. 

8. Configure your application in the config.txt file. 

9. Start and test your application with swirlds.


Hashgraph SDK Tips and Tricks - logging error


If you use the Hashgraph SDK demo applications for prototype development, you can recognize that debugging the applications is not so simple. What you can do is to start a separate console window, just for the errors and you can log every important ´piece of information or errors to this special console, like:

/** a console window for errors */
public Console errorconsole;
...
  public void init(Platform platform, long id) {
  ...
    this.errorconsole = platform.createConsole(true);
  ...
  }

  protected void LogException(Exception e) {
    errorconsole.out.println(e.toString()+" "+e.getMessage()+" ");
  }

  protected void LogMessage(String message) {
    errorconsole.out.println(message);
  }

Unfortunately, it does not work if you want to log from your state object.