This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #577 from LiskHQ/558-migrate_transaction_commands
Migrate transaction commands - Partially closes #558
- Loading branch information
Showing
15 changed files
with
1,168 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
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', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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":{}}\'', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'); | ||
} | ||
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', | ||
]; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.