Created
January 24, 2017 01:51
-
-
Save acastellana/fb95066649ef459917e642420a53cf89 to your computer and use it in GitHub Desktop.
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
/** | |
* _sendOwnedBySelf(subjectAccount) | |
* > subjectFullAccount.publicKey | |
* > subjectFullAccount.privateKey | |
* > subjectFullAccount.account | |
* > ownersArray[0].publicKey | |
*/ | |
_sendOwnedBy(subjectFullAccount, ownerAccounts) { | |
console.log("@_sendOwnedBy",subjectAccount,ownerAccounts); | |
ownersArray = []; | |
var deferred = this._q.defer(); | |
var promise = deferred.promise; | |
// We need to get the public keys of each ownerAccount | |
// Got this from: http://stackoverflow.com/questions/17757654/how-to-chain-a-variable-number-of-promises-in-q-in-order/17764496#17764496 | |
var chain = ownerAccounts.reduce((previous, item)=>{ | |
return previous.then((ownersArray)=>{ | |
// do what you want with previous value | |
// return your async operation | |
return this._NetworkRequests.getAccountData(helpers.getHostname(this._Wallet.node), item).then((account)=>{ | |
console.log("PubKey found for",account) | |
// Obtain public key and address | |
ownersArray[ownersArray.length] = { | |
address : account.account.address, | |
pubKey : account.account.publicKey | |
}; | |
deferred.resolve(ownersArray); //is this one necessary? | |
}, | |
(err) => { | |
//TODO: create proper alert! | |
this._Alert.createWalletFailed(err); | |
deferred.reject(false); | |
}); | |
}); | |
}, deferred.resolve(ownersArray)); | |
chain.then((ownersArray)=>{ | |
// Set transferData | |
let transferData = {}; | |
//TODO: MINCOSIGS SHOULD BE 2 FOR SECURITY | |
transferData.minCosigs = 2; | |
transferData.accountToConvert = subjectFullAccount.publicKey; // OJO!!!! | |
transferData.multisigPubKey = subjectFullAccount.publicKey; | |
// Build the entity to send | |
console.log("subjectFullAccount", subjectFullAccount); | |
let entity = this._Transactions._constructAggregate(transferData, ownersArray); | |
return this._send(entity, subjectFullAccount); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment