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

fix: use createFromUri instead of addFromUri for keys #320

Merged
merged 2 commits into from
Aug 1, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { decodeAddress } from '@polkadot/util-crypto';
import { KeysRequest } from '#lib/types/dtos/keys.request.dto';
import { PublishHandleRequest } from '#lib/types/dtos/handles.request.dto';
import { TransactionData } from '#lib/types/dtos/transaction.request.dto';
import { Extrinsic } from './extrinsic';
import { HandleResponseDTO } from '#lib/types/dtos/accounts.response.dto';
import { Extrinsic } from './extrinsic';

export type Sr25519Signature = { Sr25519: HexString };
interface SIWFTxnValues {
Expand Down Expand Up @@ -252,8 +252,8 @@ export class BlockchainService implements OnApplicationBootstrap, OnApplicationS
base_handle: handle.base_handle.toString(),
canonical_base: handle.canonical_base.toString(),
suffix: handle.suffix.toNumber(),
};
}
}

this.logger.error(`getHandleForMsa: No handle found for msaId: ${msaId}`);
return null;
Expand Down
11 changes: 2 additions & 9 deletions services/account/libs/common/src/blockchain/create-keys.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import { Keyring } from '@polkadot/api';
import { KeyringPair } from '@polkadot/keyring/types';

// eslint-disable-next-line import/no-mutable-exports
export let keyring: Keyring;
const keyring: Keyring = new Keyring({ type: 'sr25519' });

export function createKeys(uri: string): KeyringPair {
if (!keyring) {
keyring = new Keyring({ type: 'sr25519' });
}

const keys = keyring.addFromUri(uri);

return keys;
return keyring.createFromUri(uri);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { Keyring } from '@polkadot/api';
import { KeyringPair } from '@polkadot/keyring/types';

export let keyring: Keyring;
const keyring: Keyring = new Keyring({ type: 'sr25519' });

export function createKeys(uri: string): KeyringPair {
if (!keyring) {
keyring = new Keyring({ type: 'sr25519' });
}

const keys = keyring.addFromUri(uri);

return keys;
return keyring.createFromUri(uri);
}
116 changes: 61 additions & 55 deletions services/content-publishing/scripts/local-init.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { options } = require("@frequency-chain/api-augment");
const { WsProvider, ApiPromise, Keyring } = require("@polkadot/api");
const { deploy } = require("@dsnp/frequency-schemas/cli/deploy");
const { options } = require('@frequency-chain/api-augment');
const { WsProvider, ApiPromise, Keyring } = require('@polkadot/api');
const { deploy } = require('@dsnp/frequency-schemas/cli/deploy');

// Given a list of events, a section and a method,
// returns the first event with matching section and method.
Expand All @@ -10,82 +10,88 @@ const eventWithSectionAndMethod = (events, section, method) => {
};

const main = async () => {
console.log("A quick script that will setup a clean localhost instance of Frequency for DSNP ");
console.log('A quick script that will setup a clean localhost instance of Frequency for DSNP ');

const providerUri = "ws://127.0.0.1:9944";
const providerUri = 'ws://127.0.0.1:9944';
const provider = new WsProvider(providerUri);
const api = await ApiPromise.create({ provider, throwOnConnect: true, ...options });
const keys = new Keyring().addFromUri("//Alice", {}, "sr25519");
const keys = new Keyring().createFromUri('//Alice', {}, 'sr25519');

// Create alice msa
await new Promise((resolve, reject) => {
console.log("Creating an MSA...");
api.tx.msa.create()
.signAndSend(keys, {}, ({ status, events, dispatchError }) => {
if (dispatchError) {
console.error("ERROR: ", dispatchError.toHuman());
console.log('Creating an MSA...');
api.tx.msa.create().signAndSend(keys, {}, ({ status, events, dispatchError }) => {
if (dispatchError) {
console.error('ERROR: ', dispatchError.toHuman());
reject();
} else if (status.isInBlock || status.isFinalized) {
const evt = eventWithSectionAndMethod(events, 'msa', 'MsaCreated');
if (evt) {
const id = evt?.data[0];
console.log('SUCCESS: MSA Created:' + id);
resolve();
} else {
console.error(
'ERROR: Expected event not found',
events.map((x) => x.toHuman()),
);
reject();
} else if (status.isInBlock || status.isFinalized) {
const evt = eventWithSectionAndMethod(events, "msa", "MsaCreated");
if (evt) {
const id = evt?.data[0];
console.log("SUCCESS: MSA Created:" + id);
resolve();
} else {
console.error("ERROR: Expected event not found", events.map(x => x.toHuman()));
reject();
}
}
});
}
});
});

// Create alice provider
await new Promise((resolve, reject) => {
console.log("Creating an Provider...");
api.tx.msa.createProvider("alice")
.signAndSend(keys, {}, ({ status, events, dispatchError }) => {
if (dispatchError) {
console.error("ERROR: ", dispatchError.toHuman());
console.log('Creating an Provider...');
api.tx.msa.createProvider('alice').signAndSend(keys, {}, ({ status, events, dispatchError }) => {
if (dispatchError) {
console.error('ERROR: ', dispatchError.toHuman());
reject();
} else if (status.isInBlock || status.isFinalized) {
const evt = eventWithSectionAndMethod(events, 'msa', 'ProviderCreated');
if (evt) {
const id = evt?.data[0];
console.log('SUCCESS: Provider Created:' + id);
resolve();
} else {
console.error(
'ERROR: Expected event not found',
events.map((x) => x.toHuman()),
);
reject();
} else if (status.isInBlock || status.isFinalized) {
const evt = eventWithSectionAndMethod(events, "msa", "ProviderCreated");
if (evt) {
const id = evt?.data[0];
console.log("SUCCESS: Provider Created:" + id);
resolve();
} else {
console.error("ERROR: Expected event not found", events.map(x => x.toHuman()));
reject();
}
}
});
}
});
});

// Alice provider get Capacity
await new Promise((resolve, reject) => {
console.log("Staking for Capacity...");
api.tx.capacity.stake("1", 500_000 * Math.pow(8, 10))
.signAndSend(keys, {}, ({ status, events, dispatchError }) => {
if (dispatchError) {
console.error("ERROR: ", dispatchError.toHuman());
console.log('Staking for Capacity...');
api.tx.capacity.stake('1', 500_000 * Math.pow(8, 10)).signAndSend(keys, {}, ({ status, events, dispatchError }) => {
if (dispatchError) {
console.error('ERROR: ', dispatchError.toHuman());
reject();
} else if (status.isInBlock || status.isFinalized) {
const evt = eventWithSectionAndMethod(events, 'capacity', 'Staked');
if (evt) {
console.log('SUCCESS: Provider Staked:', evt.data.toHuman());
resolve();
} else {
console.error(
'ERROR: Expected event not found',
events.map((x) => x.toHuman()),
);
reject();
} else if (status.isInBlock || status.isFinalized) {
const evt = eventWithSectionAndMethod(events, "capacity", "Staked");
if (evt) {
console.log("SUCCESS: Provider Staked:", evt.data.toHuman());
resolve();
} else {
console.error("ERROR: Expected event not found", events.map(x => x.toHuman()));
reject();
}
}
});
}
});
});

// Deploy Schemas
await deploy();

console.log("Setup Complete!");
}
console.log('Setup Complete!');
};

main().catch(console.error).finally(process.exit);
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { Keyring } from '@polkadot/api';
import { KeyringPair } from '@polkadot/keyring/types';

export let keyring: Keyring;
const keyring: Keyring = new Keyring({ type: 'sr25519' });

export function createKeys(uri: string): KeyringPair {
if (!keyring) {
keyring = new Keyring({ type: 'sr25519' });
}

const keys = keyring.addFromUri(uri);

return keys;
return keyring.createFromUri(uri);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const main = async () => {
const providerUri = 'ws://127.0.0.1:9944';
const provider = new WsProvider(providerUri);
const api = await ApiPromise.create({ provider, throwOnConnect: true, ...options });
const keys = new Keyring().addFromUri('//Alice', {}, 'sr25519');
const keys = new Keyring().createFromUri('//Alice', {}, 'sr25519');

// Create alice msa
await new Promise((resolve, reject) => {
Expand Down
10 changes: 2 additions & 8 deletions services/graph/libs/common/src/blockchain/create-keys.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { Keyring } from '@polkadot/api';
import { KeyringPair } from '@polkadot/keyring/types';

export let keyring: Keyring;
const keyring: Keyring = new Keyring({ type: 'sr25519' });

export function createKeys(uri: string): KeyringPair {
if (!keyring) {
keyring = new Keyring({ type: 'sr25519' });
}

const keys = keyring.addFromUri(uri);

return keys;
return keyring.createFromUri(uri);
}
Loading