Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write an enterprise Hyperledger Fabric open source framework

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Convector (a.k.a Convector Smart Contracts) is a JavaScript development framework built for the enterprise blockchain framework. It enhances the development experience while helping developers to create a stronger and more secure intelligent contract system. It allows developers to reuse the same code base in the form of libraries through chain code and back-end to front-end. It is based on the model / controller pattern, supports Hyperledger Fabric, and runs locally along Fabric's well-designed pattern.

This blog article introduces the history of the project and focuses on the challenges and solutions of development along the way.

When we started working on Tellus, it all started. Tellus was a codeless trading designer to run on the Hyperledger Fabric blockchain. We had a bunch of Golang smart contracts then.

Our first impressions of the developer experience (DX) are not that good. There are two methods: init and invoke, and there is no other way to add a new method except to place an if condition on the invoke method and use one of the parameters to indicate the method to be called. All parameters are location-passed strings, complex parameters need to be parsed manually, and cannot be tested locally.

At the beginning of the project, Fabric 1.1 added support for Javascript chain code. We decided to give it a try, hoping to improve the developer experience. Unfortunately, it follows the same pattern in Golang chained code, and you still need to do some dirty work in your daily logic. We were looking for a better solution and found a post about the library of TheLedger, which produced Fabric link code in Typescript, which really improved the content of the original Javascript.

A pattern emerged during the migration of our smart contract from Golang to Javascript. Most of the time the functions are executed in the following order:

1. Parse the parameters. two。 Make some assertions. 3. Make changes. 4. Save your changes.

This leads to a basic question about project planning: whether smart contracts should be migrated quickly, or whether more time should be spent identifying patterns and making them flexible enough to accommodate multiple business cases. It all started with the. / src/utils/ of the project.

/ * * @ module @ worldsibu/convector-examples-token * / import * as yup from 'yup';import {ConvectorModel, ReadOnly, Required, Validate} from' @ worldsibu/convector-core-model';export class Token extends ConvectorModel {@ ReadOnly () public readonly type = 'io.worldsibu.examples.token'; @ ReadOnly () @ Required () @ Validate (yup.object ()) public balances: {[key: string]: number} @ ReadOnly () @ Required () @ Validate (yup.number (). MoreThan (0)) public totalSupply: number; @ ReadOnly () @ Required () @ Validate (yup.string ()) public name: string; @ ReadOnly () @ Required () @ Validate (yup.string ()) public symbol: string;} Convective Model

Fabric has no restrictions on the shape of the data stored in the blockchain. You basically have a key-value mapping, two of which are strings, which means you can serialize and store any complex object. We take apart the models to reuse them in the code. We have just passed all the necessary parameters.

@ Invokable () public async transfer (@ Param (yup.string ()) tokenId: string, @ Param (yup.string ()) to: string, @ Param (yup.number (). MoreThan (0)) amount: number) {const token = await Token.getOne (tokenId); if (token.balances [this.sender] < amount) {throw new Error ('The sender does not have enough funds');} token.balances [to] = token.balances [to] | 0 Token.balances [to] + = amount; token.balances [this.sender]-= amount; await token.save ();} Convector controller

Using Fabric, you can get a list of type parameters for the function. We don't want to parse the model all the time in all functions, so we add some decorators to verify that all parameter type invariants are successfully satisfied. These parameters may be primitive, complex, or even model.

Now, the function looks more like a controller. They deal with business logic when the model describes the data.

Now is the time to integrate all the chain code into our Nodejs REST API. In the process, we realized that we were creating a wrapper library on the server to invoke my chain code using fabric-client lib. This is a very common situation, so we are looking for a better way to automate.

I want to use the same controller and model files and chain code on the server. Doing so means decoupling the relationship between the model and the storage layer (Fabric) as well as the controller and execution operations.

This is how we realized that Hyperledger Fabric is just one of several blockchains that Convector can support.

Adapters and storage come into play.

The adapter is the underlying layer of the controller. The controller defines methods, parameters, and business logic, while the adapter handles how to route the call to the correct location. For example, in our API, it uses adapters to invoke structures, client libraries and send transactions.

Storage provides the ability to interact with the model. Whether you want to save, delete, or query something, you can interact with the model itself and with the specified service in the background. On the chain code, this is the Fabric STUB object. In Nodejs API, it may be sending a query transaction or reading from CouchDB.

Professional tip: Convector can be used with something other than the blockchain. For example, configure an adapter or model to invoke API or other databases.

The weekend has become a month for creating tools and perfecting models. Here are some tools you can use today:

Worldsibu/convector-common-fabric-helper: wrap the Nodejs library for fabric-client using some shortcut methods, such as sending a transaction or installing a link code. The @ worldsibu/convector-tool-chaincode-manager:CLI and Nodejs libraries are used to package and install the convection chain code on the blockchain. This is critical because using Convector to build smaller snippets of code, this tool will bundle your code. Worldsibu/hurley: establish the development environment of Fabric block chain network. Read more here. Worldsibu/convector-cli: a quick start for a new convector project. This is the easiest and quickest way to start using a new project. Read more here. # Install the CLInpm i-g @ worldsibu/convector-cli# Create a new chaincodes projectconv new mychain-c tokencd mychainnpm i# Install a dev environmentnpm run env:restart # Install the chaincodenpm run cc:start-token 1Convector CLI

In addition, Convector already comes with a Fabric adapter, an Fabric store, an CouchDB store and an analog adapter (for unit testing), which you can use to seamlessly create code and NodeJS backends for your chain code, while creating tests that can be done are included in the CI/CD pipeline. This is very important in any real life.

Additional adapters and storage layers can be easily created, and we are happy to see the community building around these tools. As we build this, we continue to work on the migration of internal products, which helps to test the framework in real-life scenarios before launch.

I'm glad we didn't take this simple approach to migration. We are very satisfied with the results and the process of releasing open source tools is amazing. It is also useful to see hundreds of people use it every day.

Hyperledger Fabric is an excellent blockchain framework. It provides an infrastructure that covers most use cases in a secure and reliable manner. That's why we think it should also provide a strong interface for smart contracts, and we want to give back to the community through the internal tools we create when we use it.

Convector joined the Hyperledger Labs program because we believed the project would be useful to anyone in the blockchain ecosystem. We are really committed to building a community around Convector, which has more than 27000 downloads and welcomes the input of the Hyperledger community. If you want to participate in an open source project, please refer to GitHub

About the author Diego Barahona is the chief technical officer and architect of WorldSibu, which is committed to creating blockchain tools and platforms for non-blockchain experts and making the technology easier to solve business challenges.

=

Share some interactive online programming hands-on tutorials related to Bitcoin, Ethernet Square, EOS, Fabric, etc.:

Java Bitcoin Development course, for beginners, covers the core concepts of Bitcoin, such as blockchain storage, decentralized consensus mechanisms, keys and scripts, transactions and UTXO, etc., as well as how to integrate Bitcoin support functions into Java code, such as creating addresses, managing wallets, constructing naked transactions, etc., is a rare bitcoin development course for Java engineers. Php Bitcoin Development course, for beginners, covers the core concepts of Bitcoin, such as blockchain storage, decentralized consensus mechanisms, keys and scripts, transactions and UTXO, etc., as well as how to integrate Bitcoin support functions into Php code, such as creating addresses, managing wallets, constructing naked transactions, etc., is a rare bitcoin development course for Php engineers. C # Bitcoin Development course, for beginners, covers the core concepts of Bitcoin, such as blockchain storage, decentralized consensus mechanisms, keys and scripts, transactions and UTXO, etc., as well as how to integrate Bitcoin support functions into C # code, such as creating addresses, managing wallets, constructing naked transactions, etc., is a rare Bitcoin development course for C # engineers. The java ethernet development tutorial is mainly for java and android programmers to conduct a detailed web3j explanation of blockchain ethernet development. Python ethernet, mainly for python engineers to use web3.py for block chain ethernet development of the detailed explanation. Php Ethernet Square, mainly introduces the use of php for intelligent contract development interaction, account creation, transaction, transfer, token development, filter and transaction and so on. Introduction to Ethernet Square tutorial, mainly introduces the intelligent contract and dapp application development, suitable for entry. Yi Tai Fang development advanced tutorial, mainly introduces the use of node.js, mongodb, block chain, ipfs to achieve decentralized e-commerce DApp practice, suitable for advanced. ERC721 focuses on Taifang pass practice, and the course focuses on the practical development of a digital art creation and sharing DApp. It deeply explains the concept, standard and development scheme of ethernet non-homogenization pass. The content includes the independent implementation of ERC-721 standard, explains the secondary development of OpenZeppelin contract code base, the actual combat project adopts Truffle,IPFS, and realizes the pass and decentralized stock exchange. C # Ethernet Square, mainly explains how to use C # to develop .net-based Ethernet Square applications, including account management, status and transactions, intelligent contract development and interaction, filters and transactions, etc. EOS introduction course, this course helps you quickly get started with the development of EOS block chain decentralized applications, covering core knowledge points such as EOS tool chain, accounts and wallets, issuing tokens, smart contract development and deployment, using code and intelligent contract interaction, and finally using all knowledge points to complete the development of a note DApp. Play with EOS wallet development. This course focuses on the complete development process of mobile EOS wallet, and deeply studies the application development of EOS blockchain. The course covers the core concepts of EOS blockchain, such as accounts, computing resources, intelligent contracts, actions and transactions. It also explains how to use eosjs and eosjs-ecc development packages to access EOS blockchain, and how to integrate EOS blockchain support in React front-end applications. The content of the course is profound and simple, which is very suitable for front-end engineers to study the application development of EOS block chain. This course is for beginners. This course includes core concepts such as Hyperledger Fabric's xxxxbook and MSP service, permission policy, channel configuration and startup, chain code communication interface, as well as Fabric network design, nodejs chain code and application development. It is the best choice for Nodejs engineers to learn Fabric block chain development. The course is for beginners. The content includes core concepts such as Hyperledger Fabric × × × books and MSP service, permission policy, channel configuration and startup, chain code communication interface, as well as Fabric network design, java chain code and application development. It is the best choice for java engineers to learn Fabric block chain development. Tendermint block chain development detailed understanding, this course is suitable for engineers who want to use tendermint for block chain development, the course content includes the core concepts of tendermint application development model, such as ABCI interface, Merkel tree, multi-version state library, etc., as well as rich practical code such as token issuance, it is the best choice for go language engineers to get started with block chain development.

Huizhi.com original translation, reprint please indicate the source. Here is how to write an enterprise Hyperledger Fabric open source framework

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report