mirror of
https://github.com/pezkuwichain/pezkuwi-ui.git
synced 2026-06-13 19:11:01 +00:00
Add genesisHash checks to all loads (#197)
* Add genesisHash checks to all loads * Only match when genesisHash is supplied * Swap to bash * Naming * Check for empty json * Filter injected on genesisHash as well * Bump deps
This commit is contained in:
@@ -25,8 +25,8 @@
|
||||
"react": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^1.2.0-beta.5",
|
||||
"@polkadot/util-crypto": "^1.2.0-beta.5",
|
||||
"@polkadot/keyring": "^1.2.0-beta.6",
|
||||
"@polkadot/util-crypto": "^1.2.0-beta.6",
|
||||
"xmlserializer": "^0.6.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
"styled-components": "^4.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^1.2.0-beta.5",
|
||||
"@polkadot/types": "^0.91.0-beta.10",
|
||||
"@polkadot/util": "^1.2.0-beta.5"
|
||||
"@polkadot/keyring": "^1.2.0-beta.6",
|
||||
"@polkadot/types": "^0.91.0-beta.14",
|
||||
"@polkadot/util": "^1.2.0-beta.6"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/keyring": "*",
|
||||
|
||||
@@ -193,6 +193,9 @@ export class Keyring extends Base implements KeyringStruct {
|
||||
);
|
||||
const [, hexAddr] = key.split(':');
|
||||
|
||||
// move genesisHash to top-level (TODO Remove from contracts section?)
|
||||
json.meta.genesisHash = json.meta.genesisHash || (json.meta.contract && json.meta.contract.genesisHash);
|
||||
|
||||
this.contracts.add(this._store, address, json);
|
||||
this.rewriteKey(json, key, hexAddr, contractKey);
|
||||
}
|
||||
@@ -210,26 +213,40 @@ export class Keyring extends Base implements KeyringStruct {
|
||||
this.accounts.add(this._store, pair.address, json);
|
||||
}
|
||||
|
||||
private allowGenesis (json?: KeyringJson | { meta: KeyringJson$Meta } | null): boolean {
|
||||
if (json && json.meta && this.genesisHash) {
|
||||
if (json.meta.genesisHash) {
|
||||
return this.genesisHash === json.meta.genesisHash;
|
||||
} else if (json.meta.contract) {
|
||||
return this.genesisHash === json.meta.contract.genesisHash;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public loadAll (options: KeyringOptions, injected: { address: string; meta: KeyringJson$Meta }[] = []): void {
|
||||
super.initKeyring(options);
|
||||
|
||||
this._store.all((key: string, json: KeyringJson): void => {
|
||||
if (options.filter ? options.filter(json) : true) {
|
||||
if (accountRegex.test(key)) {
|
||||
this.loadAccount(json, key);
|
||||
} else if (addressRegex.test(key)) {
|
||||
this.loadAddress(json, key);
|
||||
} else if (contractRegex.test(key)) {
|
||||
if (json.meta && json.meta.contract && this.genesisHash && this.genesisHash === json.meta.contract.genesisHash) {
|
||||
if (this.allowGenesis(json)) {
|
||||
if (accountRegex.test(key)) {
|
||||
this.loadAccount(json, key);
|
||||
} else if (addressRegex.test(key)) {
|
||||
this.loadAddress(json, key);
|
||||
} else if (contractRegex.test(key)) {
|
||||
this.loadContract(json, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
injected.forEach(({ address, meta }): void =>
|
||||
this.loadInjected(address, meta)
|
||||
);
|
||||
injected.forEach((account): void => {
|
||||
if (this.allowGenesis(account)) {
|
||||
this.loadInjected(account.address, account.meta);
|
||||
}
|
||||
});
|
||||
|
||||
keyringOption.init(this);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { AddressSubject, SingleAddress } from './observable/types';
|
||||
|
||||
export interface ContractMeta {
|
||||
abi: string;
|
||||
genesisHash?: string;
|
||||
genesisHash?: string | null;
|
||||
}
|
||||
|
||||
export interface KeyringStore {
|
||||
@@ -29,6 +29,7 @@ export interface KeyringOptions extends KeyringOptionsBase {
|
||||
// eslint-disable-next-line @typescript-eslint/class-name-casing
|
||||
export interface KeyringJson$Meta {
|
||||
contract?: ContractMeta;
|
||||
genesisHash?: string | null;
|
||||
isInjected?: boolean;
|
||||
isRecent?: boolean;
|
||||
isTesting?: boolean;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"store": "^2.0.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util": "^1.2.0-beta.5"
|
||||
"@polkadot/util": "^1.2.0-beta.6"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "*"
|
||||
|
||||
@@ -17,6 +17,6 @@
|
||||
"@polkadot/util-crypto": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util-crypto": "^1.2.0-beta.5"
|
||||
"@polkadot/util-crypto": "^1.2.0-beta.6"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user