Code Duplication    Length = 20-20 lines in 2 locations

test/size_estimation.test.js 2 locations

@@ 152-171 (lines=20) @@
149
150
    return bitcoin.script.multisig.output.encode(m, keys);
151
}
152
function multisigScriptSizes(m, script) {
153
    var bareSize = 1/*op0*/ + m * (1 + SizeEstimation.SIZE_DER_SIGNATURE);
154
    var bareSig = 1 + bareSize;
155
    var p2shSig = bareSize + SizeEstimation.getLengthForScriptPush(script.length) + script.length;
156
157
    var p2wshHash = bitcoin.crypto.sha256(script);
158
    var p2wshScript = bitcoin.script.witnessScriptHash.output.encode(p2wshHash);
159
160
    var nestedSig = 1 + 1 + p2wshScript.length;
161
    var witSize = 1 + m * (1 + SizeEstimation.SIZE_DER_SIGNATURE);
162
    var nestedWit = witSize + 1 + 1 + script.length;
163
164
    return {
165
        bareSig: bareSig,
166
        p2shSig: SizeEstimation.getLengthForVarInt(p2shSig) + p2shSig,
167
        p2wshScript: p2wshScript,
168
        nestedSig: nestedSig,
169
        nestedWit: nestedWit
170
    };
171
}
172
173
var varIntFixtures = [
174
    [0, 1],
@@ 106-125 (lines=20) @@
103
    return bitcoin.script.pubKey.output.encode(keyu);
104
}
105
106
function p2pkhScriptSizes(script, compressed) {
107
    var bareSize = (1 + SizeEstimation.SIZE_DER_SIGNATURE) + (1 + (compressed ? 33 : 65));
108
    var bareSig = 1 + bareSize;
109
    var p2shSig = 1 + bareSize + 1 + script.length;
110
111
    var p2wshHash = bitcoin.crypto.sha256(script);
112
    var p2wshScript = bitcoin.script.witnessScriptHash.output.encode(p2wshHash);
113
114
    var nestedSig = 1 + 1 + p2wshScript.length;
115
    var witSize = (1 + SizeEstimation.SIZE_DER_SIGNATURE) + (1 + (compressed ? 33 : 65));
116
    var nestedWit = witSize + 1 + 1 + script.length;
117
118
    return {
119
        bareSig: bareSig,
120
        p2shSig: p2shSig,
121
        p2wshScript: p2wshScript,
122
        nestedSig: nestedSig,
123
        nestedWit: nestedWit
124
    };
125
}
126
127
function p2pkhMakeScript(wif, network) {
128
    var eckey = bitcoin.ECPair.fromWIF(wif, network);