<commit_before>/**
 * @fileOverview FundCtrl angular controller
 */

define(['./module', 'bitcoinjs-lib'],
function (controllers, Bitcoin) {
  'use strict';

  var convert = Bitcoin.convert;

  controllers.controller('FundCtrl', ['$scope', 'notify', function($scope, notify) {

  $scope.Object = Object;

  /**
   * Check if we have enough signatures and put them into the transaction
   */
  var finishSigning = function(fund, task) {
    // task format:
    // task: {tx: tx, task: task} (added in frontend)
    // task: {tx: hexTx, 'pending': pending, stealth: metadata.stealth};
    // pending:  [{output: utxo.output, address: utxo.address, index: idx, signatures: {}, type: outAddress?outAddress.type:'signature'}] ...

    var script = convert.hexToBytes(fund.script);

    var organizeSignatures = function(hexSigs) {
        var signatures = [];
        $scope.pocket.participants.forEach(function(participant, i) {
            if (hexSigs.hasOwnProperty(i)) {
                signatures.push(hexSigs[i]);
            } else {
                signatures.push(null);
            }
        });
        signatures.reverse();
        return signatures;
    }
    var finished = true;
    task.task.pending.forEach(function(input) {
        var hexSigs = organizeSignatures(input.signatures);

        console.log(fund.m, hexSigs, Object.keys(input.signatures))
        if (Object.keys(input.signatures).length >= fund.m) {
            // convert inputs to bytes
            var sigs = hexSigs.map(function(sig) {return sig?convert.hexToBytes(sig):sig});
            console.log("apply multisigs"); 
            // apply multisigs
            task.tx.applyMultisigs(input.index, script, sigs, 1);
        } else {
            finished = false;
        }
    });
    if (finished) {
        task.task.tx = task.tx.serializeHex();
    }
    return finished;
  }

  /**
   * Import a signature
   */
  $scope.importFundSig = function(form, task) {<commit_msg>Fix composing the signatures for a multisig.<commit_after>/**
 * @fileOverview FundCtrl angular controller
 */

define(['./module', 'bitcoinjs-lib'],
function (controllers, Bitcoin) {
  'use strict';

  var convert = Bitcoin.convert;

  controllers.controller('FundCtrl', ['$scope', 'notify', function($scope, notify) {

  $scope.Object = Object;

  /**
   * Check if we have enough signatures and put them into the transaction
   */
  var finishSigning = function(fund, task) {
    // task format:
    // task: {tx: tx, task: task} (added in frontend)
    // task: {tx: hexTx, 'pending': pending, stealth: metadata.stealth};
    // pending:  [{output: utxo.output, address: utxo.address, index: idx, signatures: {}, type: outAddress?outAddress.type:'signature'}] ...

    var script = convert.hexToBytes(fund.script);

    var organizeSignatures = function(hexSigs) {
        var signatures = [];
        $scope.pocket.participants.forEach(function(participant, i) {
            if (hexSigs.hasOwnProperty(i)) {
                signatures.push(hexSigs[i]);
            } else {
                // do nothing
            }
        });
        return signatures;
    }
    var finished = true;
    task.task.pending.forEach(function(input) {
        var hexSigs = organizeSignatures(input.signatures);

        console.log(fund.m, hexSigs, Object.keys(input.signatures))
        if (Object.keys(input.signatures).length >= fund.m) {
            // convert inputs to bytes
            var sigs = hexSigs.map(function(sig) {return sig?convert.hexToBytes(sig):sig});
            console.log("apply multisigs"); 
            // apply multisigs
            task.tx.applyMultisigs(input.index, script, sigs, 1);
        } else {
            finished = false;
        }
    });
    if (finished) {
        task.task.tx = task.tx.serializeHex();
    }
    return finished;
  }

  /**
   * Import a signature
   */
  $scope.importFundSig = function(form, task) {
{'fraction_non_alphanumeric': 0.1388036809815951, 'fraction_numerical': 0.0005112474437627812, 'mean_word_length': 2.4658990256864484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6936386', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1143, 'n_words': 262}