Skip to content

Commit

Permalink
Merge pull request #55 from kaleido-io/token-address
Browse files Browse the repository at this point in the history
Add datatypes, contract address
  • Loading branch information
dechdev committed Apr 19, 2022
2 parents 724e611 + 444b700 commit 5b8d25c
Show file tree
Hide file tree
Showing 32 changed files with 1,083 additions and 291 deletions.
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.

2 changes: 1 addition & 1 deletion 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": "^0.1.0-alpha.4",
"@hyperledger/firefly-sdk": "^0.1.0-alpha.5",
"body-parser": "^1.20.0",
"class-transformer": "^0.3.1",
"class-validator": "^0.12.2",
Expand Down
12 changes: 6 additions & 6 deletions server/src/controllers/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class ContractsController {
? await firefly.generateContractInterface({
name: body.name,
version: body.version,
input: { abi: body.schema },
input: { abi: body.schema } as any,
})
: body.schema;
const result = await firefly.createContractInterface(ffi);
Expand All @@ -64,7 +64,7 @@ export class ContractsController {
},
location: {
address: body.address,
},
} as any,
});
return { type: 'message', id: api.message };
}
Expand All @@ -84,7 +84,7 @@ export class ContractsController {
const apis = await firefly.getContractAPIs();
return apis.map((api) => ({
name: api.name,
address: api.location?.address,
address: (api.location as any)?.address,
urls: api.urls,
}));
}
Expand All @@ -100,7 +100,7 @@ export class ContractsController {
const ffi = await firefly.getContractInterface(api.interface.id, true);
return {
name: api.name,
address: api.location?.address,
address: (api.location as any)?.address,
urls: api.urls,
events: ffi.events?.map((e) => ({ pathname: e.pathname })),
};
Expand All @@ -119,7 +119,7 @@ export class ContractsController {
id: l.id,
name: l.name,
topic: l.topic,
address: l.location.address,
address: (l.location as any)?.address,
eventName: l.event.name,
}));
}
Expand All @@ -137,7 +137,7 @@ export class ContractsController {
id: listener.id,
name: listener.name,
topic: listener.topic,
address: listener.location.address,
address: listener.location,
eventName: listener.event.name,
};
}
Expand Down
11 changes: 6 additions & 5 deletions server/src/controllers/datatypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class DatatypesController {
@Param('name') name: string,
@Param('version') version: string,
): Promise<DatatypeInterface> {
const datatype = await firefly.getDatatype({ name, version });
const datatype = await firefly.getDatatype(name, version);
if (datatype === undefined) {
throw new NotFoundError();
}
Expand All @@ -51,10 +51,11 @@ export class DatatypesController {
@OpenAPI({ summary: 'Creates and broadcasts a new datatype' })
async createDatatype(@Body() body: DatatypeInterface): Promise<AsyncResponse> {
// See DatatypesTemplateController and keep template code up to date.
const datatype = await firefly.createDatatype(
{ name: body.name, version: body.version },
body.schema,
);
const datatype = await firefly.createDatatype({
name: body.name,
version: body.version,
value: body.schema,
});
return { type: 'datatype', id: datatype.id };
}
}
Expand Down
6 changes: 6 additions & 0 deletions server/src/controllers/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export class TokensController {
name: body.name,
symbol: body.symbol,
type: body.type,
config: {
address: body.address,
},
});
return { type: 'token_pool', id: pool.id };
}
Expand Down Expand Up @@ -122,6 +125,9 @@ export class TokensTemplateController {
name: <%= ${q('name')} %>,
symbol: <%= ${q('symbol')} %>,
type: <%= ${q('type')} %>,
config: {
address: <%= ${q('address')} %>
}
});
return { type: 'token_pool', id: pool.id };
`);
Expand Down
28 changes: 18 additions & 10 deletions server/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { FireFlyTokenPoolType } from '@hyperledger/firefly-sdk';
import {
ArrayNotEmpty,
IsDefined,
IsEnum,
IsInstance,
IsInt,
IsNumberString,
IsObject,
IsOptional,
IsString,
IsUUID,
Min,
} from 'class-validator';
import { JSONSchema } from 'class-validator-jsonschema';

Expand Down Expand Up @@ -94,15 +91,27 @@ export class Verifier {
value: string;
}

export class TokenConfig {
@IsString()
address: string;
}

export class TokenPoolInput {
@IsString()
name: string;

@IsString()
symbol: string;

@IsEnum(FireFlyTokenPoolType)
type: FireFlyTokenPoolType;
@IsString()
type: 'fungible' | 'nonfungible';

@IsOptional()
config?: TokenConfig;

@IsString()
@IsOptional()
address?: string;
}

export class TokenPool extends TokenPoolInput {
Expand All @@ -114,9 +123,8 @@ export class TokenMint {
@IsString()
pool: string;

@IsInt()
@Min(0)
amount: number;
@IsString()
amount: string;
}

export class TokenBurn extends TokenMint {
Expand Down Expand Up @@ -190,10 +198,10 @@ export class ContractAPI {

export class ContractAPIURLs {
@IsString()
openapi: string;
openapi?: string;

@IsString()
ui: string;
ui?: string;
}

export class ContractAPILookup {
Expand Down
24 changes: 15 additions & 9 deletions server/test/common.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as request from 'supertest';
import FireFly, {
FireFlyOrganization,
FireFlyStatus,
FireFlyVerifier,
FireFlyOrganizationResponse,
FireFlyStatusResponse,
FireFlyVerifierResponse,
} from '@hyperledger/firefly-sdk';
import server from '../src/server';
import { firefly } from '../src/clients/firefly';
Expand All @@ -12,7 +12,10 @@ const mockFireFly = firefly as jest.MockedObject<FireFly>;

describe('Common Operations', () => {
test('List organizations', async () => {
const orgs = [{ id: 'org1' } as FireFlyOrganization, { id: 'org2' } as FireFlyOrganization];
const orgs = [
{ id: 'org1' } as FireFlyOrganizationResponse,
{ id: 'org2' } as FireFlyOrganizationResponse,
];

mockFireFly.getOrganizations.mockResolvedValueOnce(orgs);

Expand All @@ -25,8 +28,11 @@ describe('Common Operations', () => {
});

test('List organizations without self', async () => {
const status = { org: { id: 'org1' } } as FireFlyStatus;
const orgs = [{ id: 'org1' } as FireFlyOrganization, { id: 'org2' } as FireFlyOrganization];
const status = { org: { id: 'org1' } } as FireFlyStatusResponse;
const orgs = [
{ id: 'org1' } as FireFlyOrganizationResponse,
{ id: 'org2' } as FireFlyOrganizationResponse,
];

mockFireFly.getStatus.mockResolvedValueOnce(status);
mockFireFly.getOrganizations.mockResolvedValueOnce(orgs);
Expand All @@ -41,7 +47,7 @@ describe('Common Operations', () => {
});

test('Get self', async () => {
const status = { org: { id: 'org1' } } as FireFlyStatus;
const status = { org: { id: 'org1' } } as FireFlyStatusResponse;

mockFireFly.getStatus.mockResolvedValueOnce(status);

Expand All @@ -51,8 +57,8 @@ describe('Common Operations', () => {
});

test('List verifiers', async () => {
const orgs = [{ id: 'org1', did: 'did:org1' } as FireFlyOrganization];
const verifiers = [{ identity: 'org1', value: '0x123' } as FireFlyVerifier];
const orgs = [{ id: 'org1', did: 'did:org1' } as FireFlyOrganizationResponse];
const verifiers = [{ identity: 'org1', value: '0x123' } as FireFlyVerifierResponse];

mockFireFly.getOrganizations.mockResolvedValueOnce(orgs);
mockFireFly.getVerifiers.mockResolvedValueOnce(verifiers);
Expand Down
29 changes: 15 additions & 14 deletions server/test/contracts.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as request from 'supertest';
import FireFly, {
FireFlyContractAPI,
FireFlyContractInterface,
FireFlyContractListener,
FireFlyContractAPIResponse,
FireFlyContractInterfaceResponse,
FireFlyContractListenerResponse,
} from '@hyperledger/firefly-sdk';
import server from '../src/server';
import { firefly } from '../src/clients/firefly';
Expand Down Expand Up @@ -31,7 +31,7 @@ describe('Smart Contracts', () => {
name: 'my-contract',
version: '1.0',
message: 'msg1',
} as FireFlyContractInterface;
} as FireFlyContractInterfaceResponse;

mockFireFly.createContractInterface.mockResolvedValueOnce(int);

Expand All @@ -55,7 +55,7 @@ describe('Smart Contracts', () => {
name: 'my-contract',
version: '1.0',
message: 'msg1',
} as FireFlyContractInterface;
} as FireFlyContractInterfaceResponse;

mockFireFly.generateContractInterface.mockResolvedValueOnce(int);
mockFireFly.createContractInterface.mockResolvedValueOnce(int);
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('Smart Contracts', () => {
const api = {
name: 'my-api',
message: 'msg1',
} as FireFlyContractAPI;
} as FireFlyContractAPIResponse;

mockFireFly.createContractAPI.mockResolvedValueOnce(api);

Expand All @@ -100,6 +100,7 @@ describe('Smart Contracts', () => {
name: 'my-api',
});
});

test('Get contract Interfaces', async () => {
const int = [
{
Expand All @@ -112,7 +113,7 @@ describe('Smart Contracts', () => {
description: '',
version: '1.1',
},
] as FireFlyContractInterface[];
] as FireFlyContractInterfaceResponse[];

mockFireFly.getContractInterfaces.mockResolvedValueOnce(int);

Expand All @@ -130,12 +131,12 @@ describe('Smart Contracts', () => {
openapi: 'openapi-url',
ui: 'ui-url',
},
} as FireFlyContractAPI;
} as FireFlyContractAPIResponse;
const int = {
name: 'my-contract',
version: '1.0',
message: 'msg1',
} as FireFlyContractInterface;
} as FireFlyContractInterfaceResponse;

mockFireFly.getContractAPI.mockResolvedValueOnce(api);
mockFireFly.getContractInterface.mockResolvedValueOnce(int);
Expand Down Expand Up @@ -166,13 +167,13 @@ describe('Smart Contracts', () => {
openapi: 'openapi-url',
ui: 'ui-url',
},
} as FireFlyContractAPI;
} as FireFlyContractAPIResponse;
const listener = {
id: 'listener1',
topic: 'my-app',
location: { address: '0x123' },
location: { address: '0x123' } as any,
event: { name: 'event1' },
} as FireFlyContractListener;
} as FireFlyContractListenerResponse;

mockFireFly.getContractAPI.mockResolvedValueOnce(api);
mockFireFly.getContractListeners.mockResolvedValueOnce([listener]);
Expand Down Expand Up @@ -201,9 +202,9 @@ describe('Smart Contracts', () => {
const listener = {
id: 'listener1',
topic: 'my-app',
location: { address: '0x123' },
location: '0x123',
event: { name: 'Changed' },
} as FireFlyContractListener;
} as FireFlyContractListenerResponse;

mockFireFly.createContractAPIListener.mockResolvedValueOnce(listener);

Expand Down
Loading

0 comments on commit 5b8d25c

Please sign in to comment.