Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

added unlock and send #700

Merged
merged 1 commit into from
May 25, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Template['popupWindows_sendTransactionConfirmation'].events({
@event click .cancel
*/
'click .cancel': function(){
ipc.send('backendAction_unlockedAccount', 'Transaction not confirmed');
ipc.send('backendAction_unlockedAccountAndSentTransaction', 'Transaction not confirmed');
ipc.send('backendAction_closePopupWindow');
},
/**
Expand All @@ -189,21 +189,26 @@ Template['popupWindows_sendTransactionConfirmation'].events({
'submit form': function(e, template){
e.preventDefault();

var pw = template.find('input[type="password"]').value,
var data = Session.get('data'),
pw = template.find('input[type="password"]').value,
gas = web3.fromDecimal(TemplateVar.get('providedGas'));

console.log('Choosen Gas: ', gas, TemplateVar.get('providedGas'));

if(!gas || !_.isFinite(gas))
return;
else
data.gas = gas;

TemplateVar.set('unlocking', true);
web3.personal.unlockAccount(Session.get('data').from, pw || '', 2, function(e, res){

// unlock and send transaction!
web3.personal.unlockAccountAndSendTransaction(data, pw || '', function(e, res){
pw = null;
TemplateVar.set(template, 'unlocking', false);

if(!e && res) {
ipc.send('backendAction_unlockedAccount', null, gas);
ipc.send('backendAction_unlockedAccountAndSentTransaction', null, res);

} else {
Tracker.afterFlush(function(){
Expand Down
55 changes: 47 additions & 8 deletions modules/ipc/ipcProviderBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ module.exports = function(){
return error;
};

/**
Make the retrun response object.

@method makeReturnValue
*/
var makeReturnValue = function(payload, value) {
var result = {"jsonrpc": "2.0"};
if(value)
result.result = value;
result.id = payload.id;

return result;
};

/**
Make the error response object for either an error or an batch array of errors

Expand All @@ -67,6 +81,21 @@ module.exports = function(){
}
};

/**
Make the return response object

@method returnValue
*/
var returnValue = function(payload, value) {
if(_.isArray(payload)) {
return _.map(payload, function(load){
return makeReturnValue(load, value);
});
} else {
return makeReturnValue(payload, value);
}
};


/**
The IPC wrapper backend, handling one socket connection per view
Expand Down Expand Up @@ -398,7 +427,7 @@ module.exports = function(){
}
});

ipc.once('backendAction_unlockedAccount', function(ev, err, result){
ipc.once('backendAction_unlockedAccountAndSentTransaction', function(ev, err, result){
if(modalWindow.webContents && ev.sender.getId() === modalWindow.id) {
if(err || !result) {
log.info('Confirmation error:', err);
Expand All @@ -409,12 +438,11 @@ module.exports = function(){
}

} else {
// set the changed provided gas
filteredPayload.params[0].gas = result;

log.info('Confirmed transaction on socket '+ _this.id +':', filteredPayload.params[0]);
log.info('Transaction send on socket '+ modalWindow.id +':', result);
if(!called) {
callback(null, filteredPayload);
// call with result, rather than allowing transaction to go through
callback(null, null, result);
}
}

Expand Down Expand Up @@ -587,10 +615,21 @@ module.exports = function(){



socket.checkRequests(filteredPayload, event, function(e, result){
socket.checkRequests(filteredPayload, event, function(e, result, returnVal){
log.trace('Got result', e, result);

if(!e && !_.isEmpty(result)) {
// RETURN VALUE
if(!e && !_.isEmpty(returnVal)) {
log.trace('Return value received');

if(event.sync)
event.returnValue = JSON.stringify(returnValue(jsonPayload, returnVal));
else
event.sender.send('ipcProvider-data', JSON.stringify(returnValue(jsonPayload, returnVal)));


// SEND REQUEST
} else if(!e && !_.isEmpty(result)) {
log.trace('Success');

// SEND REQUEST
Expand All @@ -609,7 +648,7 @@ module.exports = function(){

socket.ipcSocket.write(JSON.stringify(result));

// SEND error
// RETURN ERROR
} else if(e && e !== true){
log.trace('Error');

Expand Down