Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto publish token pools, contract interfaces and APIs #119

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -71,4 +71,4 @@
"typescript": "^4.6.3",
"underscore": "^1.13.2"
}
}
}
46 changes: 28 additions & 18 deletions server/src/controllers/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand All @@ -65,16 +65,21 @@ export class ContractsController {
): Promise<AsyncResponse> {
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 };
}

Expand All @@ -88,17 +93,22 @@ export class ContractsController {
): Promise<AsyncResponse> {
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 };
}

Expand Down
21 changes: 13 additions & 8 deletions server/src/controllers/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,20 @@ export class TokensController {
): Promise<AsyncResponse> {
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 };
}

Expand Down
34 changes: 22 additions & 12 deletions server/test/contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand Down
17 changes: 11 additions & 6 deletions server/test/tokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down