Skip to content
This repository was archived by the owner on Oct 8, 2019. It is now read-only.

Commit f8887ed

Browse files
committed
issue #25 Crash when sending from a new account
1 parent 9cd5273 commit f8887ed

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

index.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,16 @@ function postTransaction(container, transaction, cb){
150150
};
151151

152152
let senderAddress = arkjs.crypto.getAddress(transaction.senderPublicKey);
153-
getFromNode('http://' + server + '/api/accounts?address=' + senderAddress,
154-
function(err, response, body){
155-
// handle the potential error
156-
if(err) {
157-
vorpal.log('Someting went wrong: '+err);
158-
159-
} else {
160-
if(body) {
161-
body = JSON.parse(body);
162-
if (body.account.secondSignature) {
153+
getFromNode('http://' + server + '/api/accounts?address=' + senderAddress, function(err, response, body){
154+
155+
if(!err && body) {
156+
try {
157+
body = JSON.parse(body);
158+
if ( !body.hasOwnProperty('success') || body.success === false) {
159+
// The account does not yet exist on the connected node.
160+
throw "Failed: " + body.error;
161+
}
162+
if (body.hasOwnProperty('account') && body.account.secondSignature) {
163163
container.prompt({
164164
type: 'password',
165165
name: 'passphrase',
@@ -169,16 +169,16 @@ function postTransaction(container, transaction, cb){
169169
var secondKeys = arkjs.crypto.getKeys(result.passphrase);
170170
arkjs.crypto.secondSign(transaction, secondKeys);
171171
transaction.id = arkjs.crypto.getId(transaction);
172-
173172
} else {
174-
vorpal.log('No second passphrase given. Trying without.');
175-
173+
vorpal.log('No second passphrase given. Trying without.');
176174
}
177175
});
178-
}
179-
performPost();
180-
} // if(body)
181-
} // if(err)
176+
}
177+
} catch (error) {
178+
vorpal.log(colors.red(error));
179+
}
180+
} // if(body)
181+
performPost();
182182
});
183183
}
184184

0 commit comments

Comments
 (0)