在 my-asset-contract.ts 中的 vs 代码中面临 IBM 区块链平台的问题

问题描述

刚开始在 VS code 上通过 IBM 区块链平台学习区块链,并面临代码问题。我按照教程做了一切,但不知道如何解决它们。

这是代码

/*
 * SPDX-License-Identifier: Apache-2.0
 */

import { Context,Contract,Info,Returns,Transaction } from 'fabric-contract-api';
import { MyAsset } from './my-asset';

@Info({title: 'MyAssetContract',description: 'My Smart Contract' })
export class MyAssetContract extends Contract {

    @Transaction(false)
    @Returns('boolean')
    public async myAssetExists(ctx: Context,myAssetId: string): Promise<boolean> {
        const data: Uint8Array = await ctx.stub.getState(myAssetId);
        return (!!data && data.length > 0);
    }

    @Transaction()
    public async createMyAsset(ctx: Context,myAssetId: string,value: string): Promise<void> {
        const exists: boolean = await this.myAssetExists(ctx,myAssetId);
        if (exists) {
            throw new Error(`The my asset ${myAssetId} already exists`);
        }
        const myAsset: MyAsset = new MyAsset();
        myAsset.value = value;
        const buffer: Buffer = Buffer.from(JSON.stringify(myAsset));
        await ctx.stub.putState(myAssetId,buffer);
    }

    @Transaction(false)
    @Returns('MyAsset')
    public async readMyAsset(ctx: Context,myAssetId: string): Promise<MyAsset> {
        const exists: boolean = await this.myAssetExists(ctx,myAssetId);
        if (!exists) {
            throw new Error(`The my asset ${myAssetId} does not exist`);
        }
        const data: Uint8Array = await ctx.stub.getState(myAssetId);
        const myAsset: MyAsset = JSON.parse(data.toString()) as MyAsset;
        return myAsset;
    }

    @Transaction()
    public async updateMyAsset(ctx: Context,newValue: string): Promise<void> {
        const exists: boolean = await this.myAssetExists(ctx,myAssetId);
        if (!exists) {
            throw new Error(`The my asset ${myAssetId} does not exist`);
        }
        const myAsset: MyAsset = new MyAsset();
        myAsset.value = newValue;
        const buffer: Buffer = Buffer.from(JSON.stringify(myAsset));
        await ctx.stub.putState(myAssetId,buffer);
    }

    @Transaction()
    public async deleteMyAsset(ctx: Context,myAssetId: string): Promise<void> {
        const exists: boolean = await this.myAssetExists(ctx,myAssetId);
        if (!exists) {
            throw new Error(`The my asset ${myAssetId} does not exist`);
        }
        await ctx.stub.deleteState(myAssetId);
    }

}

错误 1

enter image description here

错误 2

enter image description here

错误 3

enter image description here

错误 4

enter image description here

错误 5

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...