Skip to content

Commit

Permalink
Merge pull request #8846 from hicommonwealth/8845.jake.remove-substra…
Browse files Browse the repository at this point in the history
…te-spec

Remove substrate_spec field on communities.
  • Loading branch information
jnaviask authored Aug 14, 2024
2 parents 7cebf7f + 11e7ec1 commit 8bf8d02
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 149 deletions.
1 change: 0 additions & 1 deletion common_knowledge/Database-ERD.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ erDiagram
boolean collapsed_on_homepage
character-varying(255) base
integer ss58_prefix
jsonb substrate_spec
boolean has_chain_events_listener
character-varying(255) custom_domain
character-varying(255) terms
Expand Down
12 changes: 0 additions & 12 deletions libs/api-client/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,6 @@ export interface CommunityGetCommunity200Response {
* @memberof CommunityGetCommunity200Response
*/
collapsed_on_homepage?: boolean;
/**
*
* @type {string}
* @memberof CommunityGetCommunity200Response
*/
substrate_spec?: string;
/**
*
* @type {boolean}
Expand Down Expand Up @@ -2149,12 +2143,6 @@ export interface CommunitySetStake200Response {
* @memberof CommunitySetStake200Response
*/
collapsed_on_homepage?: boolean;
/**
*
* @type {string}
* @memberof CommunitySetStake200Response
*/
substrate_spec?: string;
/**
*
* @type {boolean}
Expand Down
1 change: 0 additions & 1 deletion libs/model/src/community/GetCommunities.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export function GetCommunities(): Query<typeof schemas.GetCommunities> {
"Community"."block_explorer_ids",
"Community"."collapsed_on_homepage",
"Community"."type",
"Community"."substrate_spec",
"Community"."has_chain_events_listener",
"Community"."default_summary_view",
"Community"."default_page",
Expand Down
1 change: 0 additions & 1 deletion libs/model/src/models/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export default (
defaultValue: false,
},
type: { type: Sequelize.STRING, allowNull: false, defaultValue: 'chain' },
substrate_spec: { type: Sequelize.JSONB, allowNull: true },
has_chain_events_listener: {
type: Sequelize.BOOLEAN,
allowNull: false,
Expand Down
1 change: 0 additions & 1 deletion libs/schemas/src/commands/community.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const CreateCommunity = {
cosmos_chain_id: z.string().optional(),
address: z.string().optional(), // address for the contract of the chain
decimals: PG_INT.optional(),
substrate_spec: z.string().optional(),
bech32_prefix: z.string().optional(), // required for cosmos communities
token_name: z.string().optional(),

Expand Down
1 change: 0 additions & 1 deletion libs/schemas/src/entities/community.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const Community = z.object({
custom_domain: z.string().nullish(),
block_explorer_ids: z.string().nullish(),
collapsed_on_homepage: z.boolean().default(false),
substrate_spec: z.string().nullish(),
has_chain_events_listener: z.boolean().default(false),
default_summary_view: z.boolean().nullish(),
default_page: z.nativeEnum(DefaultPage).nullish(),
Expand Down
6 changes: 0 additions & 6 deletions packages/commonwealth/client/scripts/models/ChainInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
DefaultPage,
} from '@hicommonwealth/shared';
import { ChainBase } from '@hicommonwealth/shared';
import type { RegisteredTypes } from '@polkadot/types/types';
import axios from 'axios';
import app from 'state';
import { SERVER_URL } from 'state/api/config';
Expand Down Expand Up @@ -46,7 +45,6 @@ class ChainInfo {
public readonly ss58Prefix: string;
public readonly bech32Prefix: string;
public decimals: number;
public substrateSpec: RegisteredTypes;
public adminOnlyPolling: boolean;
public communityBanner?: string;
public discordConfigId?: string;
Expand Down Expand Up @@ -83,7 +81,6 @@ class ChainInfo {
bech32_prefix,
type,
decimals,
substrateSpec,
chain_node_id,
ChainNode,
CommunityStakes,
Expand Down Expand Up @@ -122,7 +119,6 @@ class ChainInfo {
this.ss58Prefix = ss58_prefix;
this.bech32Prefix = bech32_prefix;
this.decimals = decimals;
this.substrateSpec = substrateSpec;
this.chainNodeId = chain_node_id;
this.ChainNode = ChainNode;
this.CommunityStakes = CommunityStakes;
Expand Down Expand Up @@ -163,7 +159,6 @@ class ChainInfo {
ss58_prefix,
bech32_prefix,
type,
substrate_spec,
token_name,
Contracts,
chain_node_id,
Expand Down Expand Up @@ -221,7 +216,6 @@ class ChainInfo {
bech32_prefix,
type,
decimals: parseInt(decimals, 10),
substrateSpec: substrate_spec,
tokenName: token_name,
chain_node_id,
ChainNode: ChainNode,
Expand Down
4 changes: 0 additions & 4 deletions packages/commonwealth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,8 @@
"@openfeature/server-sdk": "^1.11.0",
"@osmonauts/lcd": "^0.10.0",
"@phosphor-icons/react": "^2.0.8",
"@polkadot/api": "6.0.5",
"@polkadot/api-derive": "6.0.5",
"@polkadot/extension-dapp": "0.40.3",
"@polkadot/extension-inject": "0.47.4",
"@polkadot/keyring": "12.6.2",
"@polkadot/types": "6.0.5",
"@polkadot/util": "12.6.2",
"@polkadot/util-crypto": "12.6.2",
"@popperjs/core": "^2.0.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import Web3 from 'web3';
import { z } from 'zod';
import { bech32ToHex, urlHasValidHTTPPrefix } from '../../../shared/utils';
import { config } from '../../config';
import testSubstrateSpec from '../../util/testSubstrateSpec';
import { ServerCommunitiesController } from '../server_communities_controller';

// Warning: Probably part of zod validation
Expand Down Expand Up @@ -113,7 +112,6 @@ export async function __createCommunity(
let url = community.node_url;
let altWalletUrl = community.alt_wallet_url;
let privateUrl: string | undefined;
let sanitizedSpec;
let hex;

// Warning: this looks like input validation
Expand Down Expand Up @@ -230,7 +228,6 @@ export async function __createCommunity(
`${Errors.UnegisteredCosmosChain}: ${cosmos_chain_id}`,
);
}

// test cosmos endpoint validity -- must be http(s)
if (!urlHasValidHTTPPrefix(url)) {
throw new AppError(Errors.InvalidNodeUrl);
Expand All @@ -241,21 +238,8 @@ export async function __createCommunity(
} catch (err) {
throw new AppError(Errors.InvalidNode);
}

// TODO: test altWalletUrl if available
} else if (
community.base === ChainBase.Substrate &&
community.type !== ChainType.Offchain
) {
const spec = community.substrate_spec || '{}';
if (community.substrate_spec) {
try {
sanitizedSpec = await testSubstrateSpec(spec, community.node_url);
} catch (e) {
throw new AppError(Errors.InvalidNode);
}
}
} else {
// TODO: test altWalletUrl if available
if (!url || !url.trim()) {
throw new AppError(Errors.InvalidNodeUrl);
}
Expand Down Expand Up @@ -377,7 +361,6 @@ export async function __createCommunity(
base,
bech32_prefix,
active: true,
substrate_spec: sanitizedSpec || '',
// @ts-expect-error StrictNullChecks
chain_node_id: node.id,
token_name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use strict';
const { query } = require('@polkadot/api-derive/staking');
const { toChecksumAddress } = require('web3-utils');

module.exports = {
up: async (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction(async (transaction) => {
const addresses = await queryInterface.sequelize.query(
`SELECT * FROM "Addresses" WHERE chain='axie-infinity';`,
{ transaction }
{ transaction },
);

const addressesToUpdate = {};
Expand All @@ -25,61 +24,61 @@ module.exports = {
// update admin role now
const role = await queryInterface.sequelize.query(
`SELECT * FROM "Roles" WHERE permission='admin' AND chain_id='axie-infinity';`,
{ transaction }
{ transaction },
);

console.log(JSON.stringify(addressesToDelete));
for (const [idToDelete, idToUpdate] of Object.entries(
addressesToDelete
addressesToDelete,
)) {
await queryInterface.sequelize.query(
`UPDATE "Collaborations" SET address_id=${idToUpdate} WHERE address_id=${idToDelete};`,
{ transaction }
{ transaction },
);

const adminRole = await queryInterface.sequelize.query(
`SELECT * FROM "Roles" WHERE permission='admin' AND chain_id='axie-infinity' AND address_id = ${idToDelete};`,
{ transaction }
{ transaction },
);

if (adminRole[0].length > 0) {
await queryInterface.sequelize.query(
`UPDATE "Roles" SET permission='admin' WHERE address_id = ${idToUpdate};`,
{ transaction }
{ transaction },
);
}

await queryInterface.sequelize.query(
`DELETE FROM "Roles" WHERE address_id=${idToDelete};`,
{ transaction }
{ transaction },
);

await queryInterface.sequelize.query(
`UPDATE "OffchainComments" SET address_id=${idToUpdate} WHERE address_id=${idToDelete};`,
{ transaction }
{ transaction },
);
await queryInterface.sequelize.query(
`UPDATE "OffchainThreads" SET address_id=${idToUpdate} WHERE address_id=${idToDelete};`,
{ transaction }
{ transaction },
);
await queryInterface.sequelize.query(
`UPDATE "OffchainReactions" SET address_id=${idToUpdate} WHERE address_id=${idToDelete};`,
{ transaction }
{ transaction },
);
await queryInterface.sequelize.query(
`DELETE FROM "OffchainProfiles" WHERE address_id=${idToDelete};`,
{ transaction }
{ transaction },
);
await queryInterface.sequelize.query(
`DELETE FROM "Addresses" WHERE id=${idToDelete};`,
{ transaction }
{ transaction },
);
}

for (const [address, id] of Object.entries(addressesToUpdate)) {
await queryInterface.sequelize.query(
`UPDATE "Addresses" SET address='${address}' WHERE id=${id};`,
{ transaction }
{ transaction },
);
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.sequelize.transaction(async (t) => {
await queryInterface.sequelize.query(
`ALTER TABLE public."Communities" DROP COLUMN IF EXISTS "substrate_spec";`,
{
transaction: t,
},
);
});
},

async down(queryInterface, Sequelize) {
await queryInterface.sequelize.transaction(async (t) => {
await queryInterface.sequelize.query(
`ALTER TABLE public."Communities" ADD COLUMN IF NOT EXISTS "substrate_spec" JSONB;`,
{
transaction: t,
},
);
});
},
};
61 changes: 0 additions & 61 deletions packages/commonwealth/server/util/testSubstrateSpec.ts

This file was deleted.

17 changes: 0 additions & 17 deletions packages/commonwealth/shared/substrate.ts

This file was deleted.

Loading

0 comments on commit 8bf8d02

Please sign in to comment.