Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 4d5ff98

Browse files
committed
FABN-1238 NodeSDK add TS for lifecycle
Add typescript definitions for the new lifecycle API's Change-Id: I6b58613329d2ec46102a7c86b9ff5f5f1790707e Signed-off-by: Bret Harrison <beharrison@nc.rr.com>
1 parent 71e371b commit 4d5ff98

File tree

4 files changed

+146
-25
lines changed

4 files changed

+146
-25
lines changed

fabric-client/lib/Chaincode.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ const Chaincode = class {
174174
/**
175175
* Get the source code package
176176
*
177-
* @returns {number} The package of this chaincode
177+
* @returns {byte[]} The package of this chaincode
178178
*/
179179
getPackage() {
180180

@@ -195,12 +195,25 @@ const Chaincode = class {
195195

196196
/**
197197
* Get the chaincode type
198+
*
199+
* @returns {string} The type of this chaincode
198200
*/
199201
getType() {
200202

201203
return this._type;
202204
}
203205

206+
/**
207+
* Set the chaincode type
208+
* @param {string} type The type of this chaincode. Must be "golang",
209+
* "node", "java" or "car".
210+
*/
211+
setType(type) {
212+
this._type = Chaincode.checkType(type);
213+
214+
return this;
215+
}
216+
204217
/**
205218
* Set if the chaincode initialize is required
206219
* @param {boolean} required Indicates if this chaincode must be initialized
@@ -213,25 +226,18 @@ const Chaincode = class {
213226

214227
/**
215228
* Get the initialize required setting
229+
*
230+
* @returns {boolean}
216231
*/
217232
getInitRequired() {
218233

219234
return this._init_required;
220235
}
221236

222-
/**
223-
* Set the chaincode type
224-
* @param {string} type The type of this chaincode. Must be "golang",
225-
* "node", "java" or "car".
226-
*/
227-
setType(type) {
228-
this._type = Chaincode.checkType(type);
229-
230-
return this;
231-
}
232-
233237
/**
234238
* Get the chaincode path
239+
*
240+
* @returns {string}
235241
*/
236242
getChaincodePath() {
237243

@@ -250,6 +256,8 @@ const Chaincode = class {
250256

251257
/**
252258
* Get the chaincode path
259+
*
260+
* @returns {string}
253261
*/
254262
getMetadataPath() {
255263

@@ -268,6 +276,8 @@ const Chaincode = class {
268276

269277
/**
270278
* Get the goLang path
279+
*
280+
* @returns {string}
271281
*/
272282
getGoLangPath() {
273283

@@ -731,7 +741,7 @@ const Chaincode = class {
731741
}
732742

733743

734-
/**
744+
/*
735745
* Build a ApproveChaincodeDefinitionForMyOrgArgs protobuf object
736746
* based on this Chaincode definition
737747
*/
@@ -758,7 +768,7 @@ const Chaincode = class {
758768
return arg;
759769
}
760770

761-
/**
771+
/*
762772
* Build a QueryApprovalStatusArgs protobuf object
763773
* based on this Chaincode definition
764774
*/
@@ -774,7 +784,7 @@ const Chaincode = class {
774784
return arg;
775785
}
776786

777-
/**
787+
/*
778788
* Build a CommitChaincodeDefinitionArgs protobuf object
779789
* based on this Chaincode definition
780790
*/

fabric-client/lib/Channel.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3932,11 +3932,17 @@ const Channel = class {
39323932
* query. Required when using the admin idendity.
39333933
*/
39343934

3935+
/**
3936+
* @typedef {Object} QueryInstalledChaincodeResult
3937+
* @property {string} package_id - The package ID of the installed chaincode
3938+
* @property {string} label - The label as provided by the client application
3939+
*/
3940+
39353941
/**
39363942
* Sends a QueryInstalledChaincode request to one peer.
39373943
*
39383944
* @param {InstalledChaincodeRequest} request
3939-
* @returns {Promise} A Promise for a {@link Chaincode} instance
3945+
* @returns {Promise} A Promise for a {@link QueryInstalledChaincodeResult}
39403946
*/
39413947
async queryInstalledChaincode(request) {
39423948
const method = 'queryInstalledChaincode';
@@ -4003,7 +4009,7 @@ const Channel = class {
40034009
throw results;
40044010
}
40054011

4006-
return results;
4012+
return JSON.parse(results.encodeJSON());
40074013
}
40084014

40094015
/**
@@ -4019,7 +4025,7 @@ const Channel = class {
40194025
* Sends a QueryInstalledChaincodes request to one peer.
40204026
*
40214027
* @param {InstalledChaincodesRequest} request
4022-
* @returns {Promise} A Promise for a {@link Chaincode} instance
4028+
* @returns {Promise} A Promise for a {@link QueryInstalledChaincodeResult[]}
40234029
*/
40244030
async queryInstalledChaincodes(request) {
40254031
const method = 'queryInstalledChaincodes';
@@ -4082,7 +4088,7 @@ const Channel = class {
40824088
throw results;
40834089
}
40844090

4085-
return results;
4091+
return JSON.parse(results.encodeJSON());
40864092
}
40874093

40884094
/**

fabric-client/types/index.d.ts

Lines changed: 108 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*/
66

77
/* tslint:disable:max-classes-per-file */
8+
/* tslint:disable:ordered-imports */
89

9-
import FabricCAServices = require('fabric-ca-client');
1010
import { BaseClient } from './base';
11+
import FabricCAServices = require('fabric-ca-client');
12+
import { lstatSync } from 'fs';
1113

1214
interface ProtoBufObject {
1315
toBuffer(): Buffer;
@@ -48,7 +50,7 @@ declare class Client extends BaseClient {
4850
public queryPeers(request: Client.PeerQueryRequest): Promise<Client.PeerQueryResponse>;
4951
public queryChannels(peer: Client.Peer | string, useAdmin?: boolean): Promise<Client.ChannelQueryResponse>;
5052
public queryInstalledChaincodes(peer: Client.Peer | string, useAdmin?: boolean): Promise<Client.ChaincodeQueryResponse>;
51-
public installChaincode(request: Client.ChaincodeInstallRequest, timeout?: number): Promise<Client.ProposalResponseObject>;
53+
public installChaincode(request: Client.ChaincodeInstallRequestv1, timeout?: number): Promise<Client.ProposalResponseObject>;
5254
public initCredentialStores(): Promise<boolean>;
5355
public setStateStore(store: Client.IKeyValueStore): void;
5456
public setAdminSigningIdentity(privateKey: string, certificate: string, mspid: string): void;
@@ -155,6 +157,44 @@ declare namespace Client { // tslint:disable-line:no-namespace
155157
configUpdate?: Buffer;
156158
}
157159

160+
export interface ChaincodeDefinitionQueryRequest {
161+
target: Peer;
162+
chaincodeId: string;
163+
request_timeout?: number;
164+
txId?: TransactionId;
165+
}
166+
167+
export interface NamespaceDefinitionsRequest {
168+
target: Peer;
169+
request_timeout?: number;
170+
txId?: TransactionId;
171+
}
172+
173+
export interface ApprovalStatusRequest {
174+
target: Peer;
175+
request_timeout?: number;
176+
txId?: TransactionId;
177+
chaincode: Chaincode;
178+
}
179+
180+
export interface InstalledChaincodeRequest {
181+
target: Peer;
182+
request_timeout?: number;
183+
txId?: TransactionId;
184+
package_id: string;
185+
}
186+
187+
export interface InstalledChaincodesRequest {
188+
target: Peer;
189+
request_timeout?: number;
190+
txId?: TransactionId;
191+
}
192+
193+
export interface QueryInstalledChaincodeResult {
194+
package_id: string;
195+
label: string;
196+
}
197+
158198
export class Channel {
159199
public static sendSignedProposal(request: SignedProposal, timeout?: number): Promise<ProposalResponseObject>;
160200

@@ -222,6 +262,14 @@ declare namespace Client { // tslint:disable-line:no-namespace
222262
public queryByChaincode(request: ChaincodeQueryRequest, useAdmin?: boolean): Promise<Buffer[]>;
223263
public verifyProposalResponse(proposalResponse: ProposalResponse): boolean;
224264
public compareProposalResponseResults(proposalResponses: ProposalResponse[]): boolean;
265+
266+
public approveChaincodeForOrg(request: ChaincodeRequest): Promise<object>;
267+
public commitChaincode(request: ChaincodeRequest): Promise<object>;
268+
public queryChaincodeDefinition(request: ChaincodeDefinitionQueryRequest): Promise<Chaincode>;
269+
public queryNamespaceDefinitions(request: NamespaceDefinitionsRequest): Promise<object>;
270+
public queryApprovalStatus(request: ApprovalStatusRequest): Promise<object>;
271+
public queryInstalledChaincode(request: InstalledChaincodeRequest): Promise<QueryInstalledChaincodeResult>;
272+
public queryInstalledChaincodes(request: InstalledChaincodesRequest): Promise<QueryInstalledChaincodeResult[]>;
225273
}
226274

227275
export interface ChannelPeerRoles {
@@ -456,7 +504,7 @@ declare namespace Client { // tslint:disable-line:no-namespace
456504
metadataPath?: string;
457505
}
458506

459-
export type ChaincodeInstallRequest = ChaincodePackageInstallRequest | ChaincodePathInstallRequest;
507+
export type ChaincodeInstallRequestv1 = ChaincodePackageInstallRequest | ChaincodePathInstallRequest;
460508

461509
export interface ChaincodeInstantiateUpgradeRequest {
462510
targets?: Peer[] | string[];
@@ -492,6 +540,12 @@ declare namespace Client { // tslint:disable-line:no-namespace
492540
txId?: TransactionId;
493541
}
494542

543+
export interface ChaincodeRequest {
544+
targets?: Peer[] | string[];
545+
chaincode: Chaincode;
546+
txId?: TransactionId;
547+
}
548+
495549
export interface KeyOpts {
496550
ephemeral: boolean;
497551
}
@@ -727,4 +781,55 @@ declare namespace Client { // tslint:disable-line:no-namespace
727781
public getFileNames(): string[];
728782
public toBuffer(): Promise<Buffer>;
729783
}
784+
785+
export interface ChaincodePackageRequest {
786+
label?: string;
787+
chaincodeType: ChaincodeType;
788+
chaincodePath: string;
789+
metadataPath?: string;
790+
goPath?: string;
791+
}
792+
793+
export interface ChaincodeInstallRequest {
794+
target: Peer;
795+
request_timeout?: number;
796+
txId: TransactionId;
797+
}
798+
799+
export class Chaincode {
800+
public static fromQueryResult(name: string, payload: ByteBuffer, client: Client): Chaincode;
801+
constructor(name: string, version: string, client: Client);
802+
public getName(): string;
803+
public getVersion(): string;
804+
public setVersion(version: string): Chaincode;
805+
public getSequence(): Long;
806+
public setSequence(sequence: Long): Chaincode;
807+
public getPackage(): Buffer;
808+
public setPackage(packagedChaincode: Buffer): Chaincode;
809+
public getType(): ChaincodeType;
810+
public setType(type: ChaincodeType): Chaincode;
811+
public getInitRequired(): boolean;
812+
public setInitRequired(required: boolean): Chaincode;
813+
public getChaincodePath(): string;
814+
public setChaincodePath(path: string): Chaincode;
815+
public getMetadataPath(): string;
816+
public setMetadataPath(path: string): Chaincode;
817+
public getGoLangPath(): string;
818+
public setGoLangPath(path: string): Chaincode;
819+
public getLabel(): string;
820+
public setLabel(label: string): Chaincode;
821+
public getPackageId(): string;
822+
public setPackageId(packageId: string): Chaincode;
823+
public getEndorsementPolicyDefinition(): object;
824+
public setEndorsementPolicyDefinition(policy: object): Chaincode;
825+
public getEndorsementPolicy(): object;
826+
public setEndorsementPolicy(policy: object): Chaincode;
827+
public getCollectionConfigPackageDefinition(): object;
828+
public setCollectionConfigPackageDefinition(configPackage: object): Chaincode;
829+
public getCollectionConfigPackage(): object;
830+
public validate(): void;
831+
public package(request: ChaincodePackageRequest): Promise<Buffer>;
832+
public install(request: ChaincodeInstallRequest): Promise<string>;
833+
public toString(): string;
834+
}
730835
}

test/typescript/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
Block,
2121
BlockchainInfo,
2222
BroadcastResponse,
23-
ChaincodeInstallRequest,
23+
ChaincodeInstallRequestv1,
2424
ChaincodeInstantiateUpgradeRequest,
2525
ChaincodeInvokeRequest,
2626
ChaincodeQueryRequest,
@@ -248,7 +248,7 @@ test('use the connection profile file', async (t: any) => {
248248
logger.debug(`Set GOPATH to ${process.env.GOPATH}`);
249249
const txId: TransactionId = client.newTransactionID(true);
250250
// send proposal to endorser
251-
const request: ChaincodeInstallRequest = {
251+
const request: ChaincodeInstallRequestv1 = {
252252
chaincodeId: 'examplets',
253253
chaincodePath: 'github.com/example_cc',
254254
chaincodeVersion: 'v1',
@@ -274,7 +274,7 @@ test('use the connection profile file', async (t: any) => {
274274
t.pass('Successfully loaded the client configuration for org2');
275275
const txId: TransactionId = client.newTransactionID(true);
276276
// send proposal to endorser
277-
const request: ChaincodeInstallRequest = {
277+
const request: ChaincodeInstallRequestv1 = {
278278
chaincodeId: 'examplets',
279279
chaincodePath: 'github.com/example_cc',
280280
chaincodeVersion: 'v1',

0 commit comments

Comments
 (0)