Skip to content

Commit

Permalink
fix: use createFromUri instead of addFromUri for keys
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeCap08055 committed Jul 31, 2024
1 parent 793726b commit 50492dc
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 62 deletions.
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
2 changes: 1 addition & 1 deletion services/account/libs/common/src/blockchain/create-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function createKeys(uri: string): KeyringPair {
keyring = new Keyring({ type: 'sr25519' });
}

const keys = keyring.addFromUri(uri);
const keys = keyring.createFromUri(uri);

return keys;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function createKeys(uri: string): KeyringPair {
keyring = new Keyring({ type: 'sr25519' });
}

const keys = keyring.addFromUri(uri);
const keys = keyring.createFromUri(uri);

return keys;
}
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
Expand Up @@ -8,7 +8,7 @@ export function createKeys(uri: string): KeyringPair {
keyring = new Keyring({ type: 'sr25519' });
}

const keys = keyring.addFromUri(uri);
const keys = keyring.createFromUri(uri);

return keys;
}
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
2 changes: 1 addition & 1 deletion services/graph/libs/common/src/blockchain/create-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function createKeys(uri: string): KeyringPair {
keyring = new Keyring({ type: 'sr25519' });
}

const keys = keyring.addFromUri(uri);
const keys = keyring.createFromUri(uri);

return keys;
}

0 comments on commit 50492dc

Please sign in to comment.