-
Notifications
You must be signed in to change notification settings - Fork 14
BasicUsage
A brief overview how to develop smart contracts with eclipse, uml and mix together.
(Here is work in progress.)
You need eclipse and the papyrus software the best starting points are the modeling.
- http://www.eclipse.org/downloads/packages/eclipse-modeling-tools/neon
- smart-contract tools, you find a private build here: (http://opensource.urszeidler.de/SolidityEditor-1.0.0-SNAPSHOT.zip) Note this is a zipped update site. see more
- The JavaScript Development Tools SDK (1.6.201.v201512010225) this is the version I found is working well
- mix and the solidity compiler
See install for more details.
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.
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.
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.
To create a properly configured model use the template.
create a model from the template |
---|
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.
The stereotype properties are available at the profile tab of the properties view, there all applied stereotypes are listed together with their properties.
The property view is your best friend also the also the model explorer comes handy, both are displayed in the papyus perspective.
The papyrus editor is straight forward you add new elements by selecting it in the tool palette section or the inline editor.
To add a contract you need to add a class and apply the Contract Stereotype. See the contract profile for more details.
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.
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.
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.
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.
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.
To generate the code, generate a launch configuration, see launch configuration for more details and generate the code. Change the model and generate again.
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