|
1 |
| -import { NUMBER } from "../../../universal-tokens"; |
| 1 | +import { CLOSE_PAREN, NUMBER } from "../../../universal-tokens"; |
2 | 2 | import { lexKeyword } from "../../../lex-utils";
|
3 | 3 | import { Types } from "../../../miniscript-types";
|
4 | 4 | import {
|
@@ -37,10 +37,12 @@ export class AFTER
|
37 | 37 | static parse = (parseContext: ParseContext) => {
|
38 | 38 | parseContext.eat(this.tokenType);
|
39 | 39 |
|
40 |
| - let locktime = NUMBER.parse(parseContext); |
| 40 | + let locktime = parseContext.eat(NUMBER.tokenType)?.value; |
41 | 41 |
|
42 | 42 | this.validateLocktime(locktime);
|
43 | 43 |
|
| 44 | + parseContext.eat(CLOSE_PAREN.tokenType); |
| 45 | + |
44 | 46 | return new AFTER(locktime);
|
45 | 47 | };
|
46 | 48 |
|
@@ -77,15 +79,21 @@ export class AFTER
|
77 | 79 | return `${this.locktime} OP_CHECKLOCKTIMEVERIFY`;
|
78 | 80 | };
|
79 | 81 |
|
80 |
| - static fromScript = (opcodes: string[]) => { |
81 |
| - let locktime = parseInt(opcodes[1]); |
82 |
| - if (isNaN(locktime)) { |
| 82 | + static fromScript = (scriptParseContext: any) => { |
| 83 | + let {reversedScript} = scriptParseContext; |
| 84 | + if (reversedScript[0] != "OP_CHECKLOCKTIMEVERIFY") { |
83 | 85 | return;
|
84 | 86 | }
|
85 | 87 |
|
86 |
| - if (opcodes[0] == "OP_CHECKLOCKTIMEVERIFY") { |
87 |
| - return new AFTER(locktime); |
| 88 | + let locktime = parseInt(reversedScript[1]); |
| 89 | + if (isNaN(locktime)) { |
| 90 | + return; |
88 | 91 | }
|
| 92 | + |
| 93 | + reversedScript.shift(); |
| 94 | + reversedScript.shift(); |
| 95 | + |
| 96 | + return new AFTER(locktime); |
89 | 97 | };
|
90 | 98 |
|
91 | 99 | private static validateLocktime(locktime: number) {
|
|
0 commit comments