Last active
December 2, 2019 23:09
-
-
Save xhliu/391014bcaeb2db56078490970265c986 to your computer and use it in GitHub Desktop.
Sample code to evaluate bitcoin script using Bitcoin SV Library (bsv) https://docs.moneybutton.com/docs/bsv-overview.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let bsv = require('bsv') | |
const slockStr = "OP_2 OP_EQUAL" | |
const slock = bsv.Script.fromASM(slockStr) | |
console.log("\nLocking script loaded\n") | |
const sunlockStr = "OP_2" | |
const sunlock = bsv.Script.fromASM(sunlockStr) | |
console.log("\nUnlocking script loaded\n") | |
const opcode_cnt = slock.chunks.length + sunlock.chunks.length | |
console.log(opcode_cnt + " opcodes to process ...") | |
const si = bsv.Script.Interpreter() | |
const verified = si.verify(sunlock, slock, null, null, bsv.Script.Interpreter.SCRIPT_VERIFY_P2SH | | |
bsv.Script.Interpreter.SCRIPT_ENABLE_MAGNETIC_OPCODES | bsv.Script.Interpreter.SCRIPT_ENABLE_MONOLITH_OPCODES) | |
if (verified) { | |
console.log("\n\x1b[32m%s\x1b[0m", "True") | |
} else { | |
console.log("\n\x1b[31m%s\x1b[0m", "False: " + si.errstr) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment