bundle_transactions_to_distribute is an array of tuples, [(CandidateFrom, BundleTransactions)]

def distribute_bundle_transactions(self, candidate_votes, bundle_transactions_to_distribute, transfer_value):
        "bundle_transactions_to_distribute is an array of tuples, [(CandidateFrom, BundleTransactions)]"

        # figure out how many net votes, and which ticket_tpls, go where
        incoming_tickets = defaultdict(list)
        exhausted_papers = 0

        # determine how many papers go to each candidate; effectively we unpack each transaction bundle into
        # preference flows, split as needed, and then repack into new bundles
        for from_candidate_id, bundle_transactions in bundle_transactions_to_distribute:
            for bundle_transaction in bundle_transactions:
                # take the bundle away from the candidate
                candidate_votes[from_candidate_id] -= bundle_transaction.votes
                self.candidate_bundle_transactions.transfer_from(from_candidate_id, bundle_transaction)

                for bundle in bundle_transaction.bundles:
                    # determine the candidate(s) that this bundle of papers flows to
                    to_candidate, next_ticket_state = self.bundle_to_next_candidate(bundle)
                    if to_candidate is None:
                        exhausted_papers += bundle.size
                        continue
                    incoming_tickets[to_candidate].append((next_ticket_state, bundle.size))

        for candidate_id in sorted(incoming_tickets, key=self.candidate_order_fn):
            bundles_moving = []
            for ticket, new_count in incoming_tickets[candidate_id]:
                bundles_moving.append(PaperBundle(ticket, new_count))
            bundle_transaction = make_bundle_transaction(bundles_moving, transfer_value)
            self.candidate_bundle_transactions.transfer_to(candidate_id, bundle_transaction)
            candidate_votes[candidate_id] += bundle_transaction.votes

        exhausted_votes = int(exhausted_papers * transfer_value)
        return exhausted_votes, exhausted_papers