File tree 1 file changed +20
-7
lines changed
modules/bitcoin-miniscript/fragments
1 file changed +20
-7
lines changed Original file line number Diff line number Diff line change 1
- import {
2
- NUMBER ,
3
- } from "../../../universal-tokens" ;
1
+ import { NUMBER } from "../../../universal-tokens" ;
4
2
import { lexKeyword } from "../../../lex-utils" ;
5
3
import { Types } from "../../../miniscript-types" ;
6
4
import {
@@ -41,9 +39,7 @@ export class AFTER
41
39
42
40
let locktime = NUMBER . parse ( parseContext ) ;
43
41
44
- if ( locktime < 1 || locktime >= 0x80000000 ) {
45
- throw new Error ( "Locktime invalid" ) ;
46
- }
42
+ this . validateLocktime ( locktime ) ;
47
43
48
44
return new AFTER ( locktime ) ;
49
45
} ;
@@ -78,6 +74,23 @@ export class AFTER
78
74
} ;
79
75
80
76
toScript = ( ) => {
81
- return `${ this . locktime } CHECKLOCKTIMEVERIFY` ;
77
+ return `${ this . locktime } OP_CHECKLOCKTIMEVERIFY` ;
78
+ } ;
79
+
80
+ static fromScript = ( opcodes : string [ ] ) => {
81
+ let locktime = parseInt ( opcodes [ 1 ] ) ;
82
+ if ( isNaN ( locktime ) ) {
83
+ return ;
84
+ }
85
+
86
+ if ( opcodes [ 0 ] == "OP_CHECKLOCKTIMEVERIFY" ) {
87
+ return new AFTER ( locktime ) ;
88
+ }
82
89
} ;
90
+
91
+ private static validateLocktime ( locktime : number ) {
92
+ if ( locktime < 1 || locktime >= 0x80000000 ) {
93
+ throw new Error ( "Locktime invalid" ) ;
94
+ }
95
+ }
83
96
}
You can’t perform that action at this time.
0 commit comments