這篇文章將為大家詳細(xì)講解有關(guān)hyperledger Composer如何實(shí)現(xiàn)轉(zhuǎn)賬功能,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

成都創(chuàng)新互聯(lián)專注于企業(yè)全網(wǎng)整合營(yíng)銷推廣、網(wǎng)站重做改版、潮州網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5響應(yīng)式網(wǎng)站、商城建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)公司、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為潮州等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
/* * @param {org.example.mynetwork.SetupDemo} setupDemo
* @transaction
*/
async function initializationFun(setupDemo) {
const NS = "org.example.mynetwork";
const factory = getFactory();
//創(chuàng)建三個(gè)參與者
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);
//創(chuàng)建資產(chǎn)
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 transaction
transaction 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.mynetwork
participant 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"
}關(guān)于“hyperledger Composer如何實(shí)現(xiàn)轉(zhuǎn)賬功能”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
分享標(biāo)題:hyperledgerComposer如何實(shí)現(xiàn)轉(zhuǎn)賬功能
地址分享:http://chinadenli.net/article36/goedsg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、App設(shè)計(jì)、Google、網(wǎng)站改版、靜態(tài)網(wǎng)站、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
營(yíng)銷型網(wǎng)站建設(shè)知識(shí)