How to use the fabric-contract-api.Object function in fabric-contract-api

To help you get started, we’ve selected a few fabric-contract-api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hyperledger / fabric-chaincode-node / test / chaincodes / annotations / src / test_contract / test_contract.ts View on Github external
}

@Object()
class Person {
    @Property()
    private eyeColour: string;
}

@Object()
class Bob extends Person {
    @Property()
    private houseName: string;

}

@Object()
class Fred extends Person {
    @Property()
    private favouriteColour: string;
}

export default class TestContract extends Contract {
    constructor() {
        super()
    }

    @Transaction()
    public async createAsset(ctx: Context, id: string, name: string, value: number, extraID: string, extraValue: number) {
        const asset = new Asset(id, name, value, new SomethingThatCouldBeAProperty(extraID, extraValue));

        await ctx.stub.putState(ctx.stub.createCompositeKey(Asset.stateIdentifier, [asset.id]), Buffer.from(asset.serialize()))
    }
github hyperledger / fabric-chaincode-node / test / chaincodes / annotations / src / test_contract / test_contract.ts View on Github external
if (!json.hasOwnProperty('id') || !json.hasOwnProperty('name') || !json.hasOwnProperty('value')) {
            throw new Error('Was not JSON formatted asset');
        }

        return new Asset(json.id, json.name, json.value, SomethingThatCouldBeAProperty.deserialize(json.extra));
    }
}

@Object()
class Person {
    @Property()
    private eyeColour: string;
}

@Object()
class Bob extends Person {
    @Property()
    private houseName: string;

}

@Object()
class Fred extends Person {
    @Property()
    private favouriteColour: string;
}

export default class TestContract extends Contract {
    constructor() {
        super()
    }
github hyperledger / fabric-chaincode-node / test / chaincodes / annotations / src / test_contract / test_contract.ts View on Github external
/*
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
*/

import { Contract, Context, Transaction, Returns, Object, Property } from 'fabric-contract-api';

@Object()
class SomethingThatCouldBeAProperty {
    @Property()
    public id: string;

    @Property()
    public value: number;

    constructor(id: string, value: number) {
        this.id = id;
        this.value = value;
    }

    serialize(): string {
        return JSON.stringify({
            id: this.id,
            value: this.value
github IBM-Blockchain / vehicle-manufacture / contract / src / lib / assets / usageEvent.ts View on Github external
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.
*/

import { Object, Property } from 'fabric-contract-api';
import { Asset } from './asset';

export enum EventType {
    CRASHED = 1,
    OVERHEATED,
    OIL_FREEZING,
    ENGINE_FAILURE,
}

@Object()
export class UsageEvent extends Asset {
    public static getClass() {
        return Asset.generateClass(UsageEvent.name);
    }

    @Property()
    private eventType: EventType;

    @Property()
    private acceleration: number;

    @Property()
    private airTemperature: number;

    @Property()
    private engineTemperature: number;
github IBM-Blockchain / vehicle-manufacture / contract / src / lib / organizations / organization.ts View on Github external
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.
*/

import { Object, Property } from 'fabric-contract-api';
import { NetworkName } from '../../constants';
import { State } from '../ledger-api/state';

@Object()
export class Organization extends State {
    public static generateClass(orgType: string): string {
        return NetworkName + '.organizations.' + orgType;
    }

    @Property()
    public readonly id: string;

    @Property()
    public readonly name: string;

    constructor(
        id: string,
        name: string,
        orgType: string,
     ) {
github IBM-Blockchain / vehicle-manufacture / contract / src / lib / assets / policy.ts View on Github external
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.
*/
import { Object, Property } from 'fabric-contract-api';
import { Asset } from './asset';

export enum PolicyType {
    THIRD_PARTY = 0,
    FIRE_AND_THEFT,
    FULLY_COMPREHENSIVE,
}

@Object()
export class Policy extends Asset {
    public static getClass() {
        return Asset.generateClass(Policy.name);
    }

    @Property()
    public readonly vin: string;

    @Property()
    public readonly startDate: number;

    @Property()
    public readonly endDate: number;

    @Property()
    public readonly insurerId: string;
github IBM-Blockchain / vehicle-manufacture / contract / src / lib / participants / company.ts View on Github external
/*
SPDX-License-Identifier: Apache-2.0
*/

import { Object, Property } from 'fabric-contract-api';
import { Participant } from './participant';

@Object()
export class Company extends Participant {
    @Property()
    private name: string;

    constructor(id: string, name: string, companyType: string) {
        super(id, companyType);
        this.name = name;
    }

    public getName(): string {
        return this.name;
    }
}
github IBM-Blockchain / vehicle-manufacture / contract / src / lib / ledger-api / state.ts View on Github external
See the License for the specific language governing permissions and
limitations under the License.
*/

'use strict';

import { Object as ContractObject, Property } from 'fabric-contract-api';
import 'reflect-metadata';
import { ReflectParams } from 'reflect-params';

export interface IState {
    new (...args: any[]): T;
    getClass(): string;
}

@ContractObject()
export class State {

    public static serialize(object: object): Buffer {
        return Buffer.from(JSON.stringify(object));
    }

    public static deserialize(data: Buffer, supportedClasses: Map>): State {
        const json = JSON.parse(data.toString());
        const objClass = supportedClasses.get(json.class);
        if (!objClass) {
            throw new Error(`Unknown class of ${json.class}`);
        }
        return this.callConstructor(objClass, json);
    }

    public static makeKey(keyParts: string[]): string {
github IBM-Blockchain / vehicle-manufacture / contract / src / lib / organizations / regulator.ts View on Github external
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.
*/

import { Object } from 'fabric-contract-api';
import { Organization } from './organization';

@Object()
export class Regulator extends Organization {
    public static getClass() {
        return Organization.generateClass(Regulator.name);
    }

    constructor(
        id: string, name: string,
    ) {
        super(id, name, Regulator.name);
    }
}
github IBM-Blockchain / vehicle-manufacture / contract / src / lib / assets / asset.ts View on Github external
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.
*/

import { Object as ContractObject, Property } from 'fabric-contract-api';
import { NetworkName } from '../../constants';
import { State } from '../ledger-api/state';

@ContractObject()
export class Asset extends State {
    public static generateClass(assetType: string): string {
        return NetworkName + '.assets.'  + assetType;
    }

    @Property('id', 'string')
    private _id: string;

    constructor(id: string, assetType: string) {
        super(Asset.generateClass(assetType), [id]);

        this._id = id;
    }

    get id(): string {
        return this._id;