* "Guess" whether the input script is pay-to-scripthash. * This method is not 100% reliable. * @returns {Boolean}
()
| 2340 | */ |
| 2341 | |
| 2342 | isScripthashInput() { |
| 2343 | if (this.code.length < 1) |
| 2344 | return false; |
| 2345 | |
| 2346 | // Grab the raw redeem script. |
| 2347 | const raw = this.getData(-1); |
| 2348 | |
| 2349 | // Last data element should be an array |
| 2350 | // for the redeem script. |
| 2351 | if (!raw) |
| 2352 | return false; |
| 2353 | |
| 2354 | // Testing for scripthash inputs requires |
| 2355 | // some evil magic to work. We do it by |
| 2356 | // ruling things _out_. This test will not |
| 2357 | // be correct 100% of the time. We rule |
| 2358 | // out that the last data element is: a |
| 2359 | // null dummy, a valid signature, a valid |
| 2360 | // key, and we ensure that it is at least |
| 2361 | // a script that does not use undefined |
| 2362 | // opcodes. |
| 2363 | if (raw.length === 0) |
| 2364 | return false; |
| 2365 | |
| 2366 | if (common.isSignatureEncoding(raw)) |
| 2367 | return false; |
| 2368 | |
| 2369 | if (common.isKeyEncoding(raw)) |
| 2370 | return false; |
| 2371 | |
| 2372 | const redeem = Script.fromRaw(raw); |
| 2373 | |
| 2374 | if (!redeem.isCode()) |
| 2375 | return false; |
| 2376 | |
| 2377 | if (redeem.isUnspendable()) |
| 2378 | return false; |
| 2379 | |
| 2380 | if (!this.isPushOnly()) |
| 2381 | return false; |
| 2382 | |
| 2383 | return true; |
| 2384 | } |
| 2385 | |
| 2386 | /** |
| 2387 | * Get P2SH redeem script if present. |
no test coverage detected