vanity cli updates (#1400)

* vanity cli updates

* Cleanup assertion

* any[]
This commit is contained in:
Jaco Greeff 2019-07-14 20:41:07 +02:00 committed by GitHub
parent 65d0b68a53
commit 012eb9e7b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 12 deletions

View File

@ -4,7 +4,7 @@
import { Generator$Calculation, Generator$Options } from './types';
function calculateAt (atOffset: number, test: Array<string>, address: string): Generator$Calculation {
function calculateAtOne (atOffset: number, test: string[], address: string): Generator$Calculation {
return {
count: test.reduce((count, c, index) => {
if (index === count) {
@ -17,7 +17,26 @@ function calculateAt (atOffset: number, test: Array<string>, address: string): G
};
}
export default function calculate (test: Array<string>, _address: string, { atOffset = -1, withCase = false }: Generator$Options): Generator$Calculation {
function calculateAt (atOffset: number, test: string[][], address: string): Generator$Calculation {
let bestCount = 0;
let bestOffset = 1;
for (let i = 0; i < test.length; i++) {
const { count, offset } = calculateAtOne(atOffset, test[i], address);
if (count > bestCount) {
bestCount = count;
bestOffset = offset;
}
}
return {
count: bestCount,
offset: bestOffset
};
}
export default function calculate (test: string[][], _address: string, { atOffset = -1, withCase = false }: Generator$Options): Generator$Calculation {
const address = withCase
? _address
: _address.toLowerCase();

View File

@ -24,7 +24,7 @@ interface Best {
const { match, mnemonic, type } = yargs
.option('match', {
default: 'EEEEE'
default: 'Test'
})
.option('type', {
choices: ['ed25519', 'sr25519'],
@ -53,11 +53,14 @@ let best: Best = {
};
let total: number = 0;
let indicator = -1;
const tests = match.split(',');
if (!matchRegex.test(match)) {
console.error("Invalid character found in match string, allowed is '1-9' (no '0'), 'A-H, J-N & P-Z' (no 'I' or 'O'), 'a-k & m-z' (no 'l') and '?' (wildcard)");
process.exit(-1);
}
tests.forEach((test): void => {
if (!matchRegex.test(test)) {
console.error("Invalid character found in match string, allowed is '1-9' (no '0'), 'A-H, J-N & P-Z' (no 'I' or 'O'), 'a-k & m-z' (no 'l') and '?' (wildcard)");
process.exit(-1);
}
});
console.log(options);

View File

@ -8,7 +8,7 @@ import { encodeAddress, mnemonicGenerate, naclKeypairFromSeed, randomAsU8a, schn
import calculate from './calculate';
export default function generator (test: Array<string>, options: Generator$Options): Generator$Match {
export default function generator (test: string[][], options: Generator$Options): Generator$Match {
const mnemonic = options.withHex
? undefined
: mnemonicGenerate(12);

View File

@ -8,9 +8,7 @@ import generate from './generate';
export default function generator (options: Generator$Options): Generator$Result {
const { match, runs = 10, withCase = false } = options;
const test = withCase
? match.split('')
: match.toLowerCase().split('');
const test = (withCase ? match : match.toLowerCase()).split(',').map((c) => c.split(''));
const startAt = Date.now();
const found: Generator$Matches = [];

View File

@ -12,7 +12,7 @@ import { getTypeDef, TypeDef } from '@polkadot/types';
interface Props {
isDisabled?: boolean;
params?: ContractABIFnArg[];
onChange: (values: Array<any>) => void;
onChange: (values: any[]) => void;
onEnter?: () => void;
}