Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Update signature commands to TypeScript #679

Merged
merged 4 commits into from
Dec 14, 2018
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
121 changes: 14 additions & 107 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,56 @@
*
*/
import BaseCommand from '../../base';
import { getAPIClient } from '../../utils/api';
import { ValidationError } from '../../utils/error';
import { getStdIn } from '../../utils/input/utils';
import { getAPIClient } from '../../utils/api';

interface Args {
readonly signature?: string;
}

const getSignatureInput = async () => {
try {
const { data } = await getStdIn({ dataIsRequired: true });
if (!data) {
throw new ValidationError('No signature was provided.');
}

return data;
} catch (e) {
throw new ValidationError('No signature was provided.');
}
};

export default class BroadcastCommand extends BaseCommand {
async run() {
const { args: { signature } } = this.parse(BroadcastCommand);
static args = [
{
name: 'signature',
description: 'Signature to broadcast.',
},
];

static description = `
Broadcasts a signature for a transaction from a multisignature account.
Accepts a stringified JSON signature as an argument, or a signature can be piped from a previous command.
If piping make sure to quote out the entire command chain to avoid piping-related conflicts in your shell.
`;

static examples = [
'signature:broadcast \'{"transactionId":"abcd1234","publicKey":"abcd1234","signature":"abcd1234"}\'',
'echo \'{"transactionId":"abcd1234","publicKey":"abcd1234","signature":"abcd1234"}\' | lisk signature:broadcast',
];

static lags = {
...BaseCommand.flags,
};

async run(): Promise<void> {
const { args } = this.parse(BroadcastCommand);
const { signature }: Args = args;
const signatureInput = signature || (await getSignatureInput());
let signatureObject;
// tslint:disable-next-line no-let
let signatureObject: object;
try {
signatureObject = JSON.parse(signatureInput);
} catch (error) {
Expand All @@ -48,24 +77,3 @@ export default class BroadcastCommand extends BaseCommand {
}
}

BroadcastCommand.args = [
{
name: 'signature',
description: 'Signature to broadcast.',
},
];

BroadcastCommand.flags = {
...BaseCommand.flags,
};

BroadcastCommand.description = `
Broadcasts a signature for a transaction from a multisignature account.
Accepts a stringified JSON signature as an argument, or a signature can be piped from a previous command.
If piping make sure to quote out the entire command chain to avoid piping-related conflicts in your shell.
`;

BroadcastCommand.examples = [
'signature:broadcast \'{"transactionId":"abcd1234","publicKey":"abcd1234","signature":"abcd1234"}\'',
'echo \'{"transactionId":"abcd1234","publicKey":"abcd1234","signature":"abcd1234"}\' | lisk signature:broadcast',
];
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,58 @@
import * as transactions from '@liskhq/lisk-transactions';
import { flags as flagParser } from '@oclif/command';
import BaseCommand from '../../base';
import { getStdIn } from '../../utils/input/utils';
import { ValidationError } from '../../utils/error';
import { parseTransactionString } from '../../utils/transactions';
import { getInputsFromSources } from '../../utils/input';
import { flags as commonFlags } from '../../utils/flags';
import { getInputsFromSources } from '../../utils/input';
import { getStdIn } from '../../utils/input/utils';
import { parseTransactionString } from '../../utils/transactions';

const getTransactionInput = async () => {
interface Args {
readonly transaction?: string;
}

const getTransactionInput = async (): Promise<string> => {
try {
const { data } = await getStdIn({ dataIsRequired: true });
if (!data) {
throw new ValidationError('No transaction was provided.');
}

return data;
} catch (e) {
throw new ValidationError('No transaction was provided.');
}
};

export default class CreateCommand extends BaseCommand {
async run() {
static args = [
{
name: 'transaction',
description: 'Transaction in JSON format.',
},
];

static description = `
Create a signature object for a transaction from a multisignature account.
Accepts a stringified JSON transaction as an argument.
`;

static examples = [
'signature:create \'{"amount":"10","recipientId":"8050281191221330746L","senderPublicKey":"3358a1562f9babd523a768e700bb12ad58f230f84031055802dc0ea58cef1e1b","timestamp":59353522,"type":0,"asset":{},"signature":"b84b95087c381ad25b5701096e2d9366ffd04037dcc941cd0747bfb0cf93111834a6c662f149018be4587e6fc4c9f5ba47aa5bbbd3dd836988f153aa8258e604"}\'',
];

static flags = {
...BaseCommand.flags,
passphrase: flagParser.string(commonFlags.passphrase),
};

async run(): Promise<void> {
const {
args: { transaction },
args,
flags: { passphrase: passphraseSource },
} = this.parse(CreateCommand);

const { transaction }: Args = args;
const transactionInput = transaction || (await getTransactionInput());

const transactionObject = parseTransactionString(transactionInput);
Expand All @@ -57,32 +84,15 @@ export default class CreateCommand extends BaseCommand {
},
});

if (!passphrase) {
throw new ValidationError('No passphrase was provided.');
}

const result = transactions.createSignatureObject(
transactionObject,
passphrase,
);

this.print(result);
}
}

CreateCommand.args = [
{
name: 'transaction',
description: 'Transaction in JSON format.',
},
];

CreateCommand.flags = {
...BaseCommand.flags,
passphrase: flagParser.string(commonFlags.passphrase),
};

CreateCommand.description = `
Create a signature object for a transaction from a multisignature account.
Accepts a stringified JSON transaction as an argument.
`;

CreateCommand.examples = [
'signature:create \'{"amount":"10","recipientId":"8050281191221330746L","senderPublicKey":"3358a1562f9babd523a768e700bb12ad58f230f84031055802dc0ea58cef1e1b","timestamp":59353522,"type":0,"asset":{},"signature":"b84b95087c381ad25b5701096e2d9366ffd04037dcc941cd0747bfb0cf93111834a6c662f149018be4587e6fc4c9f5ba47aa5bbbd3dd836988f153aa8258e604"}\'',
];
}
Loading