Skip to content

BasicUsage

UrsZeidler edited this page Feb 10, 2017 · 15 revisions

Basic usage

A brief overview how to develop smart contracts with eclipse, uml and mix together.

(Here is work in progress.)

prerequisites

You need eclipse and the papyrus software the best starting points are the modeling.

See install for more details.

workspace and project

In eclipse the files are stored in the workspace and organized as projects. When you use js as frontend code it is good to convert the project to a java script project. If you want to use the project setup described in junit testing with java for junit testing follow this instruction, you can always add the java script nature later on.

preferences

The preferences are used for meaningful defaults. There are used to populate a launch configuration when it gets created. The properties have a global and a project scope. See the preferences section in the wiki.

create a model

You could now simply use the prepared archetype which provides a maven project setup for eclipse and uml2solidity.

Create a simple uml model, add the registered profile and the solidity types. Use the short cut by load a template.

1. create a papyrus project 2. name the project
3. select the uml model as diagram language 4. name the model and create a class diagramm
4a. create a model from the template (load from template)

Or :

4b. apply the solidity profile to the model 5ab. finish the wizard

You don't need to use a papyrus project to create an uml model. Skip the first and second step.

create a model from template

To create a properly configured model use the template.

create a model from the template

adding stereotypes

Adding model elements is defined in http://wiki.eclipse.org/Papyrus_User_Guide

In short: select an element like a class from the palette and place it on the diagram. You add elements like methods and properties to the element by using the inline editor or the tool palette.

The properties view allows you to control what stereotypes are applied to an element. The Profile section let you select a stereotype applicable for the element.

changing stereotype properties

The stereotype properties are available at the profile tab of the properties view, there all applied stereotypes are listed together with their properties.

working with the model

The property view is your best friend also the also the model explorer comes handy, both are displayed in the papyus perspective.

adding elements

The papyrus editor is straight forward you add new elements by selecting it in the tool palette section or the inline editor.

adding contracts

To add a contract you need to add a class and apply the Contract Stereotype. See the contract profile for more details.

adding fields

Add Fields and assign a type. A field is modeled as an attribute, it has a name, a type and a cardinality, often one. The type should be a type selected from the type package or a type you have defined and which is reachable like a inner struct.

Change the name and change the type.

adding events

Events are modeled as an operations, it has the Event stereotype applied. Parameters are modeled as parameters. A parameter need a type and a name.

To modify the parameters double click the parameters and a editor let you change the parameter properties, like the type and the name.

adding functions

A function is modeled as an operation, parameters can have the kind 'in' or 'return' for the input and return parameters.

Contract functions are modeled by operations with the stereotype Function applied. Don't forget to set the return const to true if the function don't change the blockchain.

work with modifiers

Modifiers are modeled as constrains, when the modifier has input parameters you need to apply the modifier stereotype, to link the modifier to a function you can add a modifier datatype to the function stereotype, this is a bit crude, and linking the modifier to the function and set the parameters.

It is also possible to link the operation to the constrain, when the modifier has no parameters.

There is a constrain 'payable' in the Types model, so you don't need to create it for your self.

work with mappings

Mappings can be express in two ways, as 'mapping' and as 'key mapping'. The main difference is the meaning of the property type, with mapping, the property type defines the key value, and with the 'key mapping' the property type describes the value type.

generate the code

To generate the code, generate a launch configuration, see launch configuration for more details and generate the code. Change the model and generate again.

customize the code

The code contains marker for the code generator to be left alone. Here you place you own code. When, why ever, the code between the protected gets overridden, the generator will store this in a file suffixed with .lost.

// Start of user code Library.operations
 here you can insert your code
// End of user code

customize solidity code

customize js code

js page code
js test code

java test code