千家信息网

hyperledger Composer如何实现转账功能

发表于:2025-02-24 作者:千家信息网编辑
千家信息网最后更新 2025年02月24日,这篇文章将为大家详细讲解有关hyperledger Composer如何实现转账功能,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。/* * @param {org.
千家信息网最后更新 2025年02月24日hyperledger Composer如何实现转账功能

这篇文章将为大家详细讲解有关hyperledger Composer如何实现转账功能,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

/* * @param {org.example.mynetwork.SetupDemo} setupDemo * @transaction */async function initializationFun(setupDemo) {    const NS = "org.example.mynetwork";    const factory = getFactory();    //创建三个参与者    var zhangsan = factory.newResource(NS, "Person", 'zhangsan001')    zhangsan.name = "张三";    zhangsan.balance = 100;    var lisi = factory.newResource(NS, "Person", 'lisi')    lisi.name = "李四";    lisi.balance = 100;    var wangwu = factory.newResource(NS, "Person", 'wangwu')    wangwu.name = "王五";    wangwu.balance = 100;    const partRegistry = await getParticipantRegistry(NS+'.Person')    await partRegistry.add(zhangsan);    await partRegistry.add(lisi);    await partRegistry.add(wangwu);       //创建资产    var car = factory.newResource(NS, "Car", '川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 "AS IS" 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:  "System ACL 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": "川A0001",  "from": "zhangsan001",  "to": "lisi"}

关于"hyperledger Composer如何实现转账功能"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

篇文章 功能 转账 更多 不错 实用 三个 内容 参与者 文章 知识 资产 张三 李四 王五 参考 帮助 有关 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 数据库考试怎么准备什么 广东视频云空间部署服务器 长沙信息管理系统软件开发 无服务器开源安全的工具 中国技术信息数据库 海淀区国家级网络安全产业园 邮件管理系统 服务器 星空搜索软件开发 服务器登录不上端口没开 自己想开一家软件开发公司 典型的图数据库管理系统软件 网络安全等保测评培训 win10 建立本地数据库 南通游戏软件开发定做价格 福州做小程序软件开发 工作职位信息数据库 文件在数据库打开怎么关闭 窗体是数据库应用系统的 在网络安全模式下回复系统 汽车软件开发测试工程师培训 数据库自动备份定时删除 打印机服务器属性纸张老是消失 无法开始服务器进程检查用户名 河南高校党建软件开发系统 数据库应用特点 游戏设计学软件开发 安徽仓储生鲜配送软件开发 湖南郴州市电脑软件开发培训中心 销售数据库建设 手底下管理多个公司服务器
0