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 realize the transfer function of hyperledger Composer

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article will explain in detail how to achieve the transfer function of hyperledger Composer. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

/ * * @ param {org.example.mynetwork.SetupDemo} setupDemo * @ transaction * / async function initializationFun (setupDemo) {const NS = "org.example.mynetwork"; const factory = getFactory (); / / create three participants var zhangsan = factory.newResource (NS, "Person", 'zhangsan001') zhangsan.name = "Zhang San"; zhangsan.balance = 100 Var lisi = factory.newResource (NS, "Person", 'lisi') lisi.name = "Li Si"; lisi.balance = 100; var wangwu = factory.newResource (NS, "Person",' wangwu') wangwu.name = "Wang Wu"; wangwu.balance = 100; const partRegistry = await getParticipantRegistry (NS+'.Person') await partRegistry.add (zhangsan); await partRegistry.add (lisi); await partRegistry.add (wangwu) / / create assets var car = factory.newResource (NS, "Car", 'Sichuan A0001') car.personId = zhangsan.id; car.color = "red" const assetRegistry = await getAssetRegistry (NS+'.Car'); await assetRegistry.add (car)} / * * Sample transactiontransaction TransactionCar {* @ param {org.example.mynetwork.TransactionCar} transactionCar * @ transaction * / async function transactionCarFun (transactionCar) {const NS = "org.example.mynetwork" Const from = transactionCar.from; const to = transactionCar.to; const price = transactionCar.price; from.balance = from.balance + price; to.balance = to.balance-price; const partRegistry = await getParticipantRegistry (NS+'.Person') await partRegistry.update (from); await partRegistry.update (to); debugger const car = transactionCar.car; car.personId = to.id If (! car.transactionCars) {car.transactionCars = []} car.transactionCars.push (transactionCar) const assetRegistry = await getAssetRegistry (NS+ ".car"); await assetRegistry.update (car) } / * Write your model definitions here * / namespace org.example.mynetworkparticipant SampleParticipant identified by participantId {o String participantId o String firstName o String lastName} asset SampleAsset identified by assetId {o String assetId-- > SampleParticipant owner o String value} transaction SampleTransaction {--> SampleAsset asset o String newValue} event SampleEvent {- > SampleAsset asset o String oldValue o String newValue} participant Person identified by id {o String id o String name o Double balance} abstract asset Vehicle identified by licensePlate {o String licensePlate o String color} asset Car extends Vehicle {o String personId o TransactionCar [] transactionCars optional} transaction SetupDemo {} transaction TransactionCar {o Double price o String car o String from o String to} / * * Licensed under the Apache License Version 2.0 (the "License") * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "ASIS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * / * * Sample access control list. * / rule Default {description: "Allow all participants access to all resources" participant: "ANY" operation: ALL resource: "org.example.mynetwork.*" action: ALLOW} rule SystemACL {description: "SystemACL to permit all access" participant: "org.hyperledger.composer.system.Participant" operation: ALL resource: "org.hyperledger.composer.system.**" action: ALLOW} rule NetworkAdminUser {description: "Grant Business network administrators full access to user resources "participant:" org.hyperledger.composer.system.NetworkAdmin "operation: ALL resource:" * * "action: ALLOW} rule NetworkAdminSystem {description:" Grant business network administrators full access to system resources "participant:" org.hyperledger.composer.system.NetworkAdmin "operation: ALL resource:" org.hyperledger.composer.system.** "action: ALLOW} {" $class ":" org.example.mynetwork.TransactionCar " "price": 10, "car": "Chuan A0001", "from": "zhangsan001", "to": "lisi"} this is the end of the article on "how to transfer money in hyperledger Composer". Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

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