Skip to content

Commit efd362e

Browse files
authored
Merge pull request #72 from ltonetwork/OwnablesKeywords
keywords added to ownables
2 parents 4ea7c89 + 01c54a0 commit efd362e

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

Diff for: src/App.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default function App() {
3232
const [showSidebar, setShowSidebar] = useState(false);
3333
const [showPackages, setShowPackages] = React.useState(false);
3434
const [address, setAddress] = useState(LTOService.address);
35-
const [ownables, setOwnables] = useState<Array<{chain: EventChain, package: string}>>([]);
35+
const [ownables, setOwnables] = useState<Array<{chain: EventChain, package: string, keywords:string[]}>>([]);
3636
const [consuming, setConsuming] = useState<{chain: EventChain, package: string, info: TypedOwnableInfo}|null>(null);
3737
const [alert, setAlert] = useState<{title: string, message: React.ReactNode, severity: AlertColor}|null>(null);
3838
const [confirm, setConfirm] =
@@ -62,7 +62,7 @@ export default function App() {
6262

6363
const forge = async (pkg: TypedPackage) => {
6464
const chain = OwnableService.create(pkg);
65-
setOwnables([...ownables, {chain, package: pkg.cid}]);
65+
setOwnables([...ownables, {chain, package: pkg.cid, keywords: pkg.keywords || []}]);
6666
setShowPackages(false);
6767
enqueueSnackbar(`${pkg.title} forged`, {variant: "success"});
6868
}

Diff for: src/interfaces/TypedPackage.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface TypedPackage extends TypedPackageCapabilities {
1313
description?: string;
1414
cid: string;
1515
versions: Array<{date: Date, cid: string}>;
16+
keywords: string[];
1617
}
1718

1819
export interface TypedPackageStub {

Diff for: src/services/EventChain.service.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface StoredChainInfo {
1111
state: string;
1212
package: string;
1313
created: Date;
14+
keywords: string[];
1415
}
1516

1617
export default class EventChainService {
@@ -24,25 +25,27 @@ export default class EventChainService {
2425
this._anchoring = enabled;
2526
}
2627

27-
static async loadAll(): Promise<Array<{chain: EventChain, package: string, created: Date}>> {
28+
static async loadAll(): Promise<Array<{chain: EventChain, package: string, created: Date, keywords: string[]}>> {
2829
const ids = (await IDBService.listStores())
2930
.filter(name => name.match(/^ownable:\w+$/))
3031
.map(name => name.replace(/^ownable:(\w+)$/, '$1'));
3132

32-
return (await Promise.all(ids.map(id => this.load(id))))
33-
.sort(({created: a}, {created: b}) => a.getTime() - b.getTime())
33+
return (await Promise.all(ids.map(async id => {
34+
const { chain, package: packageCid, created, keywords} = await this.load(id);
35+
return { chain, package: packageCid, created, keywords };
36+
}))).sort(({created: a}, {created: b}) => a.getTime() - b.getTime());
3437
}
3538

36-
static async load(id: string): Promise<{chain: EventChain, package: string, created: Date}> {
39+
static async load(id: string): Promise<{chain: EventChain, package: string, created: Date, keywords: string[]}> {
3740
const chainInfo = await IDBService.getMap(`ownable:${id}`)
3841
.then(map => Object.fromEntries(map.entries())) as StoredChainInfo;
3942

40-
const {chain: chainJson, package: packageCid, created} = chainInfo;
43+
const {chain: chainJson, package: packageCid, created, keywords} = chainInfo;
4144

42-
return { chain: EventChain.from(chainJson), package: packageCid, created };
45+
return { chain: EventChain.from(chainJson), package: packageCid, created, keywords };
4346
}
4447

45-
static async store(...chains: Array<{ chain: EventChain, stateDump: StateDump }>): Promise<void> {
48+
static async store(...chains: Array<{ chain: EventChain, stateDump: StateDump,keywords?: string[] }>): Promise<void> {
4649
const anchors: Array<{ key: Binary, value: Binary }> = [];
4750
const data: TypedDict<TypedDict | Map<any, any>> = {};
4851

@@ -66,7 +69,7 @@ export default class EventChainService {
6669
await IDBService.setAll(data);
6770
}
6871

69-
static async initStore(chain: EventChain, pkg: string, stateDump?: StateDump): Promise<void> {
72+
static async initStore(chain: EventChain, pkg: string, stateDump?: StateDump, keywords?: string[]): Promise<void> {
7073
if (await IDBService.hasStore(`ownable:${chain.id}`)) {
7174
return;
7275
}
@@ -80,6 +83,7 @@ export default class EventChainService {
8083
latestHash: chain.latestHash.hex,
8184
package: pkg,
8285
created: new Date(),
86+
keywords: keywords,
8387
};
8488

8589
const data: TypedDict = {};

Diff for: src/services/Ownable.service.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export interface OwnableRPC {
3838
export default class OwnableService {
3939
private static readonly _rpc = new Map<string,OwnableRPC>();
4040

41-
static async loadAll(): Promise<Array<{chain: EventChain, package: string, created: Date}>> {
41+
static async loadAll(): Promise<Array<{chain: EventChain, package: string, created: Date, keywords: string[]}>> {
4242
return EventChainService.loadAll();
4343
}
4444

@@ -73,6 +73,7 @@ export default class OwnableService {
7373
ownable_id: chain.id,
7474
package: pkg.cid,
7575
network_id: LTOService.networkId,
76+
keywords: pkg.keywords,
7677
};
7778

7879
new Event(msg)
@@ -223,6 +224,7 @@ export default class OwnableService {
223224
state: chain.state.hex,
224225
package: pkg,
225226
created: new Date(),
227+
keywords: PackageService.info(pkg).keywords,
226228
};
227229

228230
const data: TypedDict = {};

Diff for: src/services/Package.service.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,17 @@ export default class PackageService {
5454
name: string,
5555
description: string|undefined,
5656
cid: string,
57-
capabilities: TypedPackageCapabilities
57+
capabilities: TypedPackageCapabilities,
58+
keywords: string[],
5859
): TypedPackage {
5960
const packages = (LocalStorageService.get('packages') || []) as TypedPackage[];
6061
let pkg = packages.find(pkg => pkg.name === name);
6162

6263
if (!pkg) {
63-
pkg = {title, name, description, cid, ...capabilities, versions: []};
64+
pkg = {title, name, description, cid, ...capabilities,keywords, versions: []};
6465
packages.push(pkg);
6566
} else {
66-
Object.assign(pkg, {cid, description, ...capabilities});
67+
Object.assign(pkg, {cid, description, ...capabilities, keywords});
6768
}
6869

6970
pkg.versions.push({date: new Date(), cid});
@@ -140,9 +141,10 @@ export default class PackageService {
140141

141142
const cid = await calculateCid(files);
142143
const capabilities = await this.getCapabilities(files);
144+
const keywords: string[] = packageJson.keywords || '';
143145

144146
await this.storeAssets(cid, files);
145-
return this.storePackageInfo(title, name, description, cid, capabilities);
147+
return this.storePackageInfo(title, name, description, cid, capabilities, keywords);
146148
}
147149

148150
static async downloadExample(key: string): Promise<TypedPackage> {

0 commit comments

Comments
 (0)