Skip to content

Commit

Permalink
Merge pull request #89 from Cerebellum-Network/feature/add-type-bundl…
Browse files Browse the repository at this point in the history
…e-for-cere-mainnet

Add auto generation of Cere Network type bundle.
  • Loading branch information
shamilkhan authored Aug 17, 2023
2 parents 53b2ab8 + 46cbb8c commit ee6ba3c
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 27 deletions.
102 changes: 78 additions & 24 deletions packages/apps-config/src/api/chain/cere.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,82 @@
// Copyright 2017-2021 @polkadot/apps-config authors & contributors
// Copyright 2017-2023 @polkadot/apps-config authors & contributors
// SPDX-License-Identifier: Apache-2.0

// structs need to be in order
/* eslint-disable sort-keys */
import type { OverrideBundleDefinition } from '@polkadot/types/types';

export default {
ChainId: 'u8',
DepositNonce: 'u64',
ResourceId: '[u8; 32]',
ProposalStatus: {
_enum: ['Initiated', 'Approved', 'Rejected']
},
ProposalVotes: {
votes_for: 'Vec<AccountId>',
votes_against: 'Vec<AccountId>',
status: 'ProposalStatus',
expiry: 'BlockNumber'
},
TokenId: 'u256',
Erc721Token: {
id: 'TokenId',
metadata: 'Vec<u8>'
},
Address: 'MultiAddress',
LookupSource: 'MultiAddress',
AccountInfo: 'AccountInfoWithDualRefCount'
const definitions: OverrideBundleDefinition = {
types: [
{
minmax: [
266,
281
],
types: {
ChainId: 'u8',
DepositNonce: 'u64',
ResourceId: '[u8; 32]',
ProposalStatus: {
_enum: [
'Initiated',
'Approved',
'Rejected'
]
},
ProposalVotes: {
votes_for: 'Vec<AccountId>',
votes_against: 'Vec<AccountId>',
status: 'ProposalStatus',
expiry: 'BlockNumber'
},
TokenId: 'u256',
Erc721Token: {
id: 'TokenId',
metadata: 'Vec<u8>'
},
Address: 'IndicesLookupSource',
LookupSource: 'IndicesLookupSource',
AccountInfo: 'AccountInfoWithDualRefCount',
ValidatorPrefs: {
commission: 'Compact<Perbill>'
}
}
},
{
minmax: [
282,
294
],
types: {
ChainId: 'u8',
DepositNonce: 'u64',
ResourceId: '[u8; 32]',
ProposalStatus: {
_enum: [
'Initiated',
'Approved',
'Rejected'
]
},
ProposalVotes: {
votes_for: 'Vec<AccountId>',
votes_against: 'Vec<AccountId>',
status: 'ProposalStatus',
expiry: 'BlockNumber'
},
TokenId: 'u256',
Erc721Token: {
id: 'TokenId',
metadata: 'Vec<u8>'
},
Address: 'MultiAddress',
LookupSource: 'MultiAddress',
AccountInfo: 'AccountInfoWithDualRefCount'
}
},
{
minmax: [295, null],
types: {}
}
]
};

export default definitions;
13 changes: 13 additions & 0 deletions packages/apps-config/src/api/chain/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2017-2023 @polkadot/apps-config authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { OverrideBundleDefinition } from '@polkadot/types/types';

import cere from './cere.js';

// NOTE: The mapping is done from chain name in system.chain
const chain: Record<string, OverrideBundleDefinition> = {
'Cere Mainnet Beta': cere
};

export default chain;
15 changes: 14 additions & 1 deletion packages/apps-config/src/api/typesBundle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import fs from 'fs';

import { objectSpread } from '@polkadot/util';

import chain from './chain/index.js';
import spec from './spec';

it('generates the typesBundle', (): void => {
const specEntries = Object.entries(spec);
const typesBundle: { spec: Record<string, unknown> } = { spec: {} };
const chainEntries = Object.entries(chain);
const typesBundle: {
chain: Record<string, unknown>
spec: Record<string, unknown>
} = { chain: {}, spec: {} };

specEntries.forEach(([k, v]): void => {
const value = objectSpread<{ derives: unknown }>({}, v);
Expand All @@ -19,6 +24,14 @@ it('generates the typesBundle', (): void => {
typesBundle.spec[k] = value;
});

chainEntries.forEach(([k, v]): void => {
const value = objectSpread<{ derives: unknown }>({}, v);

delete value.derives;

typesBundle.chain[k] = value;
});

fs.writeFileSync('packages/apps-config/src/api/typesBundle.ts', `// Copyright 2017-2022 @polkadot/apps-config authors & contributors
// SPDX-License-Identifier: Apache-2.0
Expand Down
7 changes: 5 additions & 2 deletions packages/apps-config/src/api/typesBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,14 @@ export const typesBundle = {
}
},
{
"minmax": [295, null],
"minmax": [
295,
null
],
"types": {}
}
]
},
}
},
"spec": {
"Crab": {
Expand Down

0 comments on commit ee6ba3c

Please sign in to comment.