Page 32 - MSDN Magazine, June 2018
P. 32

The Workbench documentation provides more information about the specific scenarios and a step-by-step walk-through of the UI. There are also detailed instructions on how the demo smart contracts and associated configuration files were created, and how to set up the right user accounts in Azure AD to enable this scenario.
Uploading a Custom Contract
Youcanalsocreatecustomcontractsinanyoftheprogramming languages supported by the blockchain platform of reference, and deploy them in Azure Blockchain Workbench. All Azure Blockchain Workbench requires is three files that define business logic, interac- tions and visualizations of the implemented workflows. These are:
Smart Contract: To begin, you must create a smart contract that contains the business logic for the scenario. In the following example, the smart contract is targeting the Ethereum blockchain, so the contracts are written in the Solidity programming language.
Configuration: In the configuration file, users map properties, actions and blockchain protocol information for the smart con-
provides an example of the constructor and properties of the Asset Transfer smart contract.
Be sure that your class name and constructor name match. You can find the sample source code in Solidity language for this smart contract, along with the JSON configuration files, on my GitHub repository at bit.ly/2HJPcET.
ConfigurationFileCreation
The configuration file defines the main properties and parameters for the smart contract. This includes listing out all properties and types, as well as defining a constructor indicating what parameters the user needs to input to instantiate the smart contract. Figure 5 shows an example of the Asset Transfer properties and constructor from the configuration file.
In addition, the user must enumerate and provide detail for all possible actions, including specifying input parameters for each action. Figure 6 shows an example of the MakeOffer action speci- fication from the Asset Transfer configuration file, which requires
tract. You also define what parameters are required from the participants for the instantiation and actions on the smart contract.
UI Configuration: In the config- uration UI files, you define the UI for role-based access control at each state of the smart contract, such as restrict- ing which personas can take specific actions. In this file, the user maps states and personas, and specifies state defini- tions, percentage complete at each state of the contract, and eligible actions at each state.
Smart Contract Creation
The contract definition contains a few components that must be specified to work with Azure Blockchain Workbench. Before defining the contract details specific to the scenario such as states, participants and the functions that describe the logic behind each action, you have to implement a LexingtonBase contract. The actual contract with the business logic for the business scenario will inherit from the LexingtonBase contract (which is equivalent to a class in C#), as shown in Figure 3.
Each contract should have a state that represents the current state of the con- tract, addresses for participants involved in the smart contract, data that’s stored in the contract, functions defining the business logic for different actions and a constructor for when the smart contract is instantiated. Figure 4
Figure 5 Asset Transfer Properties and Constructor
the user to input an inspector, appraiser and an offer price.
Last, include the blockchain config- uration information, as follows:
"Chains": { "Ethereum": {
"Type": "Ethereum",
"Version": "1.0",
"Location": "AssetTransfer.sol", "TypeName": "AssetTransfer", "ActionOverrides": {}, "PropertyOverrides": {}
}
UI Configuration File Creation
Users define the UI details for each action in the UI configuration file. This includes details on the users, such as the initiator or participant role and persona mapping, state mappings, as well as a constructor indicating text to be dis- played when a user wants to instantiate the smart contract. Figure 7 shows an example of the Asset Transfer prop- erties and constructor from the UI configuration file.
In addition, the user should enu- merate all possible states and include details for each state specifying actions that can be taken at each step per per- sona, as well as a percentage-complete value to give users a visualization of progress through the smart contract. For example, the Asset Transfer con- tract UI configuration file shows that once the state shows an offer has been placed, only owners and buyers can take specified actions, as shown in the code in Figure 8.
"Properties": { "State": {
"Type": "state" },
"Owner": { "Type": "user"
}, "Description": {
"Type": "string" },
"AskingPrice": { "Type": "money"
}, "Buyer": {
"Type": "user" },
"OfferPrice": { "Type": "money"
}, "Inspector": {
"Type": "user" },
"Appraiser": { "Type": "user"
} },
"Constructor": { "description": {
"Type": "string" },
"price": { "Type": "money"
} },
Figure 6 MakeOffer Action Specification
}
"MakeOffer": { "Parameters": {
"inspector": { "Type": "user"
}, "appraiser": {
"Type": "user" },
"offerPrice": { "Type": "money"
} }
},
26 msdn magazine
Blockchain


































































































   30   31   32   33   34