Convector Smart Contracts
For now, we only support Hyperledger Fabric, so this documentation is for using Convector Smart Contracts on Hyperledger Fabric.
Model/Controller pattern. Convector is designed to help you write reusable pieces of code that describe the nature of what a developer can do in a blockchain. A blockchain, in the developer’s eyes, is no more than a data layer protected by a logic layer defining the rules of what the outside world can do in with the inner data. Thus, a really comfortable way of writing chaincode logic (smart contracts) is by having Models describing the shape of the data and Controllers describing the actions and rules that apply to the models.
Using Convector CLI
Since Convector CLI was released, we recommend using it to provision your Chaincode projects. It makes it easier, faster, and less prone to errors.
To start a new chaincode project follow these steps.
You can go to ./packages/mychaincode-cc/src to see your source code (models and controllers). You will want to to modify them later.
There are some tasks available in the project (inside your root
npm run env:restart. This will use Hurley to create a new development blockchain network on your computer. Make sure to have Docker running.
npm run env:clean. This will use Hurley to destroy all the containers running a local blockchain network. Beware that this cannot be undone.
npm run cc:start -- <chaincode-name>. This will package your code into a folder located in
./chaincode-<chaincode-name>, then it will install it in every peer of your current Hurley network, and lastly it will instantiate it automatically.
npm run cc:start -- mychaincode
npm run cc:start:debug -- <chaincode-name>. Just like
cc:startit will package, install, and instantiate the smart contract, but it will start a debug process that you can connect to.
npm run cc:start:debug -- mychaincode
- Here's an example on how to debug a chaincode on your development environment straight from the blockchain network.
npm run cc:upgrade -- <chaincode-name> <version>. It will upgrade your chaincode on every peer in the development network with a new version.
npm run cc:upgrade -- mychaincode 1.2
npm run cc:package -- <chaincode-name> <organization>. In case you are just packaging your code to deploy it to a remote network (or any network not managed by Hurley) you can package the code and upload it to your infrastructure orchestration tool.
npm run cc:package -- mychaincode org1
Convector was designed to help you write reusable pieces of code that describe the nature of what a developer can do in a blockchain.
You usually focus the most on the Specification, a.k.a models and controllers, to make sure they do what the network expects them to do.
A blockchain, in the developer’s eyes, is no more than a data layer protected by a logic layer defining the rules of what the outside world can do in with the inner data. Thus, a really comfortable way of writing chaincode logic (smart contracts) is by having Models describing the shape of the data and Controllers describing the actions and rules that apply to the models.
Convector has been built taking in consideration the best out of the modern architectural design landscape. Its modular approach aims to accompany you through the whole development cycle.
- Models are real world objects or concepts (like a token, a cryptocurrency, a contract, a car, a container, a user...) with specific characteristics (like a name, an owner, a deadline...) that you structure for your project.
- Controllers are real world actions acting over objects (models). E.g.: build a car, transferring ownership, reporting an accident. It's the business logic of your system.
You can then include that project at any layer of your application, from the blockchain to the front end. You only need to specify the corresponding adapter and storage containing the functions implementations and storage target of that layer. For example, to test, you may include a mock storage to see if your blockchain logic works before deploying it.
This architecture provides the most robust way to quickly build a fullstack smart contract system.
Even if this is our preferred architecture, you can surely use Convector just in the smart contracts and call them from another programming language such as Golang, Java, Python, etc.