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

Migrate transaction commands - Partially closes #558 #577

Merged
merged 6 commits into from
Sep 19, 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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
"signature": {
"description": "Commands relating to signatures for Lisk transactions from multisignature accounts."
},
"transaction": {
"description": "Commands relating to Lisk transactions."
},
"warranty": {
"description": "Displays warranty notice."
}
Expand Down
66 changes: 66 additions & 0 deletions src/commands/transaction/broadcast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* LiskHQ/lisk-commander
* Copyright © 2017–2018 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
import BaseCommand from '../../base';
import parseTransactionString from '../../utils/transactions';
import { ValidationError } from '../../utils/error';
import { getRawStdIn } from '../../utils/input/utils';
import getAPIClient from '../../utils/api';

const getTransactionInput = async () =>
getRawStdIn()
.then(rawStdIn => {
if (rawStdIn.length <= 0) {
throw new ValidationError('No transaction was provided.');
}
return rawStdIn[0];
})
.catch(() => {
throw new ValidationError('No transaction was provided.');
});

export default class BroadcastCommand extends BaseCommand {
async run() {
const { args: { transaction } } = this.parse(BroadcastCommand);
const transactionInput =
transaction || (await getTransactionInput(transaction));
willclarktech marked this conversation as resolved.
Show resolved Hide resolved
const transactionObject = parseTransactionString(transactionInput);
const client = getAPIClient(this.userConfig.api);
const response = await client.transactions.broadcast(transactionObject);
this.print(response.data);
}
}

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

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

BroadcastCommand.description = `
Broadcasts a transaction to the network via the node specified in the current config.
Accepts a stringified JSON transaction as an argument, or a transaction 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 = [
'broadcast transaction \'{"type":0,"amount":"100",...}\'',
'echo \'{"type":0,"amount":"100",...}\' | lisk transaction:broadcast',
willclarktech marked this conversation as resolved.
Show resolved Hide resolved
];
59 changes: 59 additions & 0 deletions src/commands/transaction/get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* LiskHQ/lisk-commander
* Copyright © 2017–2018 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
import BaseCommand from '../../base';
import getAPIClient from '../../utils/api';
import query from '../../utils/query';

export default class GetCommand extends BaseCommand {
async run() {
const { args: { ids } } = this.parse(GetCommand);
const req = ids.map(id => ({
query: {
limit: 1,
id,
},
placeholder: {
id,
message: 'Transaction not found.',
},
}));
const client = getAPIClient(this.userConfig.api);
const results = await query(client, 'transactions', req);
this.print(results);
}
}

GetCommand.args = [
{
name: 'ids',
required: true,
description: 'Comma-separated transaction ID(s) to get information about.',
parse: input => input.split(',').filter(Boolean),
},
];

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

GetCommand.description = `
Gets transaction information from the blockchain.
`;

GetCommand.examples = [
'transaction:get 10041151099734832021',
'transaction:get 10041151099734832021,1260076503909567890',
];
94 changes: 94 additions & 0 deletions src/commands/transaction/sign.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* LiskHQ/lisk-commander
* Copyright © 2017–2018 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
import elements from 'lisk-elements';
import { flags as flagParser } from '@oclif/command';
import BaseCommand from '../../base';
import { getRawStdIn } from '../../utils/input/utils';
import { ValidationError } from '../../utils/error';
import parseTransactionString from '../../utils/transactions';
import getInputsFromSources from '../../utils/input';
import commonFlags from '../../utils/flags';

const getTransactionInput = async () =>
getRawStdIn()
.then(rawStdIn => {
if (rawStdIn.length <= 0) {
throw new ValidationError('No transaction was provided.');
}
return rawStdIn[0];
})
.catch(() => {
throw new ValidationError('No transaction was provided.');
});

export default class SignCommand extends BaseCommand {
async run() {
const {
args: { transaction },
flags: {
passphrase: passphraseSource,
'second-passphrase': secondPassphraseSource,
},
} = this.parse(SignCommand);

const transactionInput =
transaction || (await getTransactionInput(transaction));

const transactionObject = parseTransactionString(transactionInput);

const { passphrase, secondPassphrase } = await getInputsFromSources({
passphrase: {
source: passphraseSource,
repeatPrompt: true,
},
secondPassphrase: !secondPassphraseSource
? null
: {
source: secondPassphraseSource,
repeatPrompt: true,
},
});

const result = elements.transaction.utils.prepareTransaction(
transactionObject,
passphrase,
secondPassphrase,
);

this.print(result);
}
}

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

SignCommand.flags = {
...BaseCommand.flags,
passphrase: flagParser.string(commonFlags.passphrase),
'second-passphrase': flagParser.string(commonFlags.secondPassphrase),
};

SignCommand.description = `
Sign a transaction using your secret passphrase.
`;

SignCommand.examples = [
'transaction:sign \'{"amount":"100","recipientId":"13356260975429434553L","senderPublicKey":null,"timestamp":52871598,"type":0,"fee":"10000000","recipientPublicKey":null,"asset":{}}\'',
];
91 changes: 91 additions & 0 deletions src/commands/transaction/verify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* LiskHQ/lisk-commander
* Copyright © 2017–2018 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
import elements from 'lisk-elements';
import { flags as flagParser } from '@oclif/command';
import BaseCommand from '../../base';
import parseTransactionString from '../../utils/transactions';
import { getRawStdIn, getData } from '../../utils/input/utils';
import { ValidationError } from '../../utils/error';

const secondPublicKeyDescription = `Specifies a source for providing a second public key to the command. The second public key must be provided via this option. Sources must be one of \`file\` or \`stdin\`. In the case of \`file\`, a corresponding identifier must also be provided.

Note: if both transaction and second public key are passed via stdin, the transaction must be the first line.

Examples:
- --second-public-key file:/path/to/my/message.txt
- --second-public-key 790049f919979d5ea42cca7b7aa0812cbae8f0db3ee39c1fe3cef18e25b67951
`;

const getTransactionInput = async () =>
getRawStdIn()
.then(rawStdIn => {
if (rawStdIn.length <= 0) {
throw new ValidationError('No transaction was provided.');
willclarktech marked this conversation as resolved.
Show resolved Hide resolved
}
return rawStdIn[0];
})
.catch(() => {
throw new ValidationError('No transaction was provided.');
});

const processSecondPublicKey = async secondPublicKey =>
secondPublicKey.includes(':') ? getData(secondPublicKey) : secondPublicKey;

export default class VerifyCommand extends BaseCommand {
async run() {
const {
args: { transaction },
flags: { 'second-public-key': secondPublicKeySource },
} = this.parse(VerifyCommand);

const transactionInput = transaction || (await getTransactionInput());
const transactionObject = parseTransactionString(transactionInput);

const secondPublicKey = secondPublicKeySource
? await processSecondPublicKey(secondPublicKeySource)
: null;

const verified = elements.transaction.utils.verifyTransaction(
transactionObject,
secondPublicKey,
);
this.print({ verified });
}
}

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

VerifyCommand.flags = {
...BaseCommand.flags,
'second-public-key': flagParser.string({
name: 'Second public key',
description: secondPublicKeyDescription,
}),
};

VerifyCommand.description = `
Verifies a transaction has a valid signature.
`;

VerifyCommand.examples = [
'transaction:verify \'{"type":0,"amount":"100",...}\'',
'transaction:verify \'{"type":0,"amount":"100",...}\' --second-public-key=647aac1e2df8a5c870499d7ddc82236b1e10936977537a3844a6b05ea33f9ef6',
];
71 changes: 0 additions & 71 deletions src/commands_old/broadcast_transaction.js

This file was deleted.

Loading