Last active
March 14, 2019 09:00
-
-
Save sami-abdul/89bcfd5eac4e40649903316268e228e6 to your computer and use it in GitHub Desktop.
first-network/firstchaincode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Chaincode, StubHelper} from "@theledger/fabric-chaincode-utils"; | |
export default class Firstchaincode extends Chaincode { | |
async initLedger(stubHelper: StubHelper, args: string[]) { | |
let cars = []; | |
cars.push(new Car("1", 'black', "Honda", "Civic")); | |
cars.push(new Car("2", 'blue', "Toyota", "Prius")); | |
cars.push(new Car("3", 'red', "Suzuki", "Ciaz")); | |
for (let i = 0; i < cars.length; i++) { | |
const car: Car = cars[i]; | |
await stubHelper.putState(car.id, car); | |
this.logger.info('Added <--> ', car); | |
} | |
} | |
async queryAllCars(stubHelper: StubHelper): Promise<any> { | |
return stubHelper.getQueryResultAsList( | |
{selector:{ docType: 'car'}} | |
); | |
} | |
} | |
class Car { | |
public docType?: string; | |
public id: string; | |
public color: string; | |
public make: string; | |
public model: string; | |
public constructor(id: string, color: string, make: string, model: string) { | |
this.docType = 'car'; | |
this.id = id; | |
this.color = color; | |
this.make = make; | |
this.model = model; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shim = require('fabric-shim'); | |
import Firstchaincode from './chaincode'; | |
shim.start(new Firstchaincode()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment