@@ -157,8 +157,7 @@ function fromASM (asm) {
157157 } ) )
158158}
159159
160- function toStack ( chunks ) {
161- chunks = decompile ( chunks )
160+ function toWitness ( chunks ) {
162161 typeforce ( isPushOnly , chunks )
163162
164163 return chunks . map ( function ( op ) {
@@ -169,6 +168,12 @@ function toStack (chunks) {
169168 } )
170169}
171170
171+ function toStack ( chunks ) {
172+ console . warn ( 'toStack is deprecated, use toWitness' )
173+ chunks = decompile ( chunks )
174+ return toWitness ( chunks )
175+ }
176+
172177function isCanonicalPubKey ( buffer ) {
173178 if ( ! Buffer . isBuffer ( buffer ) ) return false
174179 if ( buffer . length < 33 ) return false
@@ -203,17 +208,76 @@ module.exports = {
203208 decompile : decompile ,
204209 fromASM : fromASM ,
205210 toASM : toASM ,
206- toStack : toStack ,
211+ toWitness : toWitness ,
207212
208213 number : require ( './script_number' ) ,
209214
210215 isCanonicalPubKey : isCanonicalPubKey ,
211216 isCanonicalSignature : isCanonicalSignature ,
217+ isDefinedHashType : isDefinedHashType ,
212218 isPushOnly : isPushOnly ,
213- isDefinedHashType : isDefinedHashType
219+
220+ // TODO: remove in 4.0.0
221+ toStack : toStack
214222}
215223
216224var templates = require ( './templates' )
217225for ( var key in templates ) {
218- module . exports [ key ] = templates [ key ]
226+ var template = templates [ key ]
227+
228+ // TODO: remove the wrappers in 4.0.0???
229+ if ( template . input ) {
230+ var input = template . input
231+
232+ if ( ! input . checkWitness ) {
233+ input . checkWitness = function checkWitness ( witness , allowIncomplete ) {
234+ typeforce ( types . Witness , witness )
235+ return input . checkRaw ( witness , allowIncomplete )
236+ }
237+ input . checkWitness . toJSON = input . checkRaw . toJSON
238+ }
239+ if ( ! input . check ) {
240+ input . check = function check ( script , allowIncomplete ) {
241+ typeforce ( types . Buffer , script )
242+ return input . checkRaw ( decompile ( script ) , allowIncomplete )
243+ }
244+ input . check . toJSON = input . checkRaw . toJSON
245+ }
246+
247+ if ( ! input . encodeWitness ) {
248+ input . encodeWitness = function encodeWitness ( ) {
249+ return toWitness ( input . encodeRaw . apply ( null , arguments ) )
250+ }
251+ }
252+ if ( ! input . noScript && ! input . encode ) {
253+ input . encode = function encode ( ) {
254+ return compile ( input . encodeRaw . apply ( null , arguments ) )
255+ }
256+ }
257+
258+ if ( ! input . decodeWitness ) {
259+ input . decode = function decodeWitness ( witness , allowIncomplete ) {
260+ typeforce ( types . Witness , witness )
261+ return input . decodeRaw ( decompile ( witness ) , allowIncomplete )
262+ }
263+ }
264+ if ( ! input . noScript && ! input . decode ) {
265+ input . decode = function decode ( script , allowIncomplete ) {
266+ typeforce ( types . Buffer , script )
267+ return input . decodeRaw ( decompile ( script ) , allowIncomplete )
268+ }
269+ }
270+
271+ // TODO: deprecated, remove in 4.0.0
272+ input . decodeStack = function decodeStack ( ) {
273+ console . warn ( 'decodeStack/encodeStack is deprecated, see #863' )
274+ return input . decodeRaw . apply ( null , arguments )
275+ }
276+ input . encodeStack = function encodeStack ( ) {
277+ console . warn ( 'decodeStack/encodeStack is deprecated, see #863' )
278+ return input . encodeRaw . apply ( null , arguments )
279+ }
280+ }
281+
282+ module . exports [ key ] = template
219283}
0 commit comments