From baacca9f0a6d24c1e9d0bfd188d3f89ec55595d1 Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Mon, 13 Nov 2023 10:52:38 -0500 Subject: [PATCH 1/2] Auto publish token pools, contract interfaces and APIs Signed-off-by: Nicko Guyer --- server/package-lock.json | 14 ++++----- server/package.json | 4 +-- server/src/controllers/contracts.ts | 46 ++++++++++++++++++----------- server/src/controllers/tokens.ts | 21 ++++++++----- 4 files changed, 50 insertions(+), 35 deletions(-) diff --git a/server/package-lock.json b/server/package-lock.json index cd2e22a..a47276e 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -9,7 +9,7 @@ "version": "1.1.3", "license": "ISC", "dependencies": { - "@hyperledger/firefly-sdk": "^1.2.3", + "@hyperledger/firefly-sdk": "^1.2.16", "body-parser": "^1.20.0", "class-transformer": "^0.3.1", "class-validator": "^0.12.2", @@ -855,9 +855,9 @@ "dev": true }, "node_modules/@hyperledger/firefly-sdk": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/@hyperledger/firefly-sdk/-/firefly-sdk-1.2.3.tgz", - "integrity": "sha512-icJYoztHF33EuPHbniypLyteJj6kfa/rei52YPvMbM6TIPNNPx3BA/w1jCRr7/uGVLsJoL/9uu2cBA718POuIw==", + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@hyperledger/firefly-sdk/-/firefly-sdk-1.2.16.tgz", + "integrity": "sha512-5ODqSLEbt2bIq9oHjuQBt1cua9PHisYv6Vi/WO0lK4clRCl+hc0f/U+sX1vVPYltCOG5ZTAYY11PKJMjDJumqg==", "dependencies": { "axios": "^0.26.1", "form-data": "^4.0.0", @@ -11355,9 +11355,9 @@ "dev": true }, "@hyperledger/firefly-sdk": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/@hyperledger/firefly-sdk/-/firefly-sdk-1.2.3.tgz", - "integrity": "sha512-icJYoztHF33EuPHbniypLyteJj6kfa/rei52YPvMbM6TIPNNPx3BA/w1jCRr7/uGVLsJoL/9uu2cBA718POuIw==", + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@hyperledger/firefly-sdk/-/firefly-sdk-1.2.16.tgz", + "integrity": "sha512-5ODqSLEbt2bIq9oHjuQBt1cua9PHisYv6Vi/WO0lK4clRCl+hc0f/U+sX1vVPYltCOG5ZTAYY11PKJMjDJumqg==", "requires": { "axios": "^0.26.1", "form-data": "^4.0.0", diff --git a/server/package.json b/server/package.json index 8d3a77c..2a60324 100644 --- a/server/package.json +++ b/server/package.json @@ -26,7 +26,7 @@ }, "homepage": "https://github.com/hyperledger/firefly-sandbox#readme", "dependencies": { - "@hyperledger/firefly-sdk": "^1.2.3", + "@hyperledger/firefly-sdk": "^1.2.16", "body-parser": "^1.20.0", "class-transformer": "^0.3.1", "class-validator": "^0.12.2", @@ -71,4 +71,4 @@ "typescript": "^4.6.3", "underscore": "^1.13.2" } -} +} \ No newline at end of file diff --git a/server/src/controllers/contracts.ts b/server/src/controllers/contracts.ts index cadf5b8..af0d966 100644 --- a/server/src/controllers/contracts.ts +++ b/server/src/controllers/contracts.ts @@ -51,7 +51,7 @@ export class ContractsController { input: { abi: body.schema }, }) : body.schema; - const result = await firefly.createContractInterface(ffi); + const result = await firefly.createContractInterface(ffi, { publish: true }); return { type: 'message', id: result.message }; } @@ -65,16 +65,21 @@ export class ContractsController { ): Promise { const firefly = getFireflyClient(namespace); // See ContractsTemplateController and keep template code up to date. - const api = await firefly.createContractAPI({ - name: body.name, - interface: { - name: body.interfaceName, - version: body.interfaceVersion, + const api = await firefly.createContractAPI( + { + name: body.name, + interface: { + name: body.interfaceName, + version: body.interfaceVersion, + }, + location: { + address: body.address, + }, }, - location: { - address: body.address, + { + publish: true, }, - }); + ); return { type: 'message', id: api.message }; } @@ -88,17 +93,22 @@ export class ContractsController { ): Promise { const firefly = getFireflyClient(namespace); // See ContractsTemplateController and keep template code up to date. - const api = await firefly.createContractAPI({ - name: body.name, - interface: { - name: body.interfaceName, - version: body.interfaceVersion, + const api = await firefly.createContractAPI( + { + name: body.name, + interface: { + name: body.interfaceName, + version: body.interfaceVersion, + }, + location: { + chaincode: body.chaincode, + channel: body.channel, + }, }, - location: { - chaincode: body.chaincode, - channel: body.channel, + { + publish: true, }, - }); + ); return { type: 'message', id: api.message }; } diff --git a/server/src/controllers/tokens.ts b/server/src/controllers/tokens.ts index 3f2e9e2..d252c8f 100644 --- a/server/src/controllers/tokens.ts +++ b/server/src/controllers/tokens.ts @@ -70,15 +70,20 @@ export class TokensController { ): Promise { const firefly = getFireflyClient(namespace); // See TokensTemplateController and keep template code up to date. - const pool = await firefly.createTokenPool({ - name: body.name, - symbol: body.symbol, - type: body.type, - config: { - address: body.address, - blockNumber: body.blockNumber, + const pool = await firefly.createTokenPool( + { + name: body.name, + symbol: body.symbol, + type: body.type, + config: { + address: body.address, + blockNumber: body.blockNumber, + }, }, - }); + { + publish: true, + }, + ); return { type: 'token_pool', id: pool.id }; } From d77c7ded8192cf0f3d93d4e0f10d37b70937002c Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Mon, 13 Nov 2023 10:57:12 -0500 Subject: [PATCH 2/2] Update unit tests to include {publish: true} Signed-off-by: Nicko Guyer --- server/test/contracts.test.ts | 34 ++++++++++++++++++++++------------ server/test/tokens.test.ts | 17 +++++++++++------ 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/server/test/contracts.test.ts b/server/test/contracts.test.ts index 20cbe6b..1170e11 100644 --- a/server/test/contracts.test.ts +++ b/server/test/contracts.test.ts @@ -41,7 +41,7 @@ describe('Smart Contracts', () => { .expect(202) .expect({ type: 'message', id: 'msg1' }); - expect(mockFireFly.createContractInterface).toHaveBeenCalledWith(req.schema); + expect(mockFireFly.createContractInterface).toHaveBeenCalledWith(req.schema, { publish: true }); }); test('Create contract interface from ABI', async () => { @@ -71,7 +71,7 @@ describe('Smart Contracts', () => { version: '1.0', input: { abi: req.schema }, }); - expect(mockFireFly.createContractInterface).toHaveBeenCalledWith(int); + expect(mockFireFly.createContractInterface).toHaveBeenCalledWith(int, { publish: true }); }); test('Create contract API', async () => { @@ -94,11 +94,16 @@ describe('Smart Contracts', () => { .expect(202) .expect({ type: 'message', id: 'msg1' }); - expect(mockFireFly.createContractAPI).toHaveBeenCalledWith({ - interface: { name: 'my-contract', version: '1.0' }, - location: { address: '0x123' }, - name: 'my-api', - }); + expect(mockFireFly.createContractAPI).toHaveBeenCalledWith( + { + interface: { name: 'my-contract', version: '1.0' }, + location: { address: '0x123' }, + name: 'my-api', + }, + { + publish: true, + }, + ); }); test('Create contract API with Fabric', async () => { @@ -122,11 +127,16 @@ describe('Smart Contracts', () => { .expect(202) .expect({ type: 'message', id: 'msg1' }); - expect(mockFireFly.createContractAPI).toHaveBeenCalledWith({ - interface: { name: 'my-contract', version: '1.0' }, - location: { chaincode: 'chaincode', channel: '0x123' }, - name: 'my-api-fabric', - }); + expect(mockFireFly.createContractAPI).toHaveBeenCalledWith( + { + interface: { name: 'my-contract', version: '1.0' }, + location: { chaincode: 'chaincode', channel: '0x123' }, + name: 'my-api-fabric', + }, + { + publish: true, + }, + ); }); test('Get contract Interfaces', async () => { diff --git a/server/test/tokens.test.ts b/server/test/tokens.test.ts index 09f86c1..143d243 100644 --- a/server/test/tokens.test.ts +++ b/server/test/tokens.test.ts @@ -53,12 +53,17 @@ describe('Tokens', () => { .expect(202) .expect({ type: 'token_pool', id: 'pool1' }); - expect(mockFireFly.createTokenPool).toHaveBeenCalledWith({ - name: 'my-pool', - symbol: 'P1', - type: 'fungible', - config: {}, - }); + expect(mockFireFly.createTokenPool).toHaveBeenCalledWith( + { + name: 'my-pool', + symbol: 'P1', + type: 'fungible', + config: {}, + }, + { + publish: true, + }, + ); }); test('Mint tokens', async () => {