Skip to content

Instantly share code, notes, and snippets.

@acastellana
Created January 24, 2017 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acastellana/fb95066649ef459917e642420a53cf89 to your computer and use it in GitHub Desktop.
Save acastellana/fb95066649ef459917e642420a53cf89 to your computer and use it in GitHub Desktop.
/**
* _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