All files / src/transaction makeThresholdCondition.js

20% Statements 2/10
0% Branches 0/10
0% Functions 0/2
20% Lines 2/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 294x   4x                                                    
import cc from 'five-bells-condition'
 
import ccJsonify from './utils/ccJsonify'
 
 
/**
 * @public
 * Create an Sha256 Threshold Cryptocondition from threshold to put into an Output of a Transaction
 * @param {number} threshold
 * @param {Array} [subconditions=[]]
 * @param {boolean} [json=true] If true returns a json object otherwise a crypto-condition type
 * @returns {object} Sha256 Threshold Condition (that will need to wrapped in an Output)
 */
export default function makeThresholdCondition(threshold, subconditions = [], json = true) {
    const thresholdCondition = new cc.ThresholdSha256()
    thresholdCondition.threshold = threshold
 
    subconditions.forEach((subcondition) => {
        // TODO: add support for Condition and URIs
        thresholdCondition.addSubfulfillment(subcondition)
    })
 
    if (json) {
        return ccJsonify(thresholdCondition)
    }
 
    return thresholdCondition
}