File tree 2 files changed +21
-0
lines changed
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,11 @@ function UInt31 (value) {
6
6
return typeforce . UInt32 ( value ) && value <= UINT31_MAX
7
7
}
8
8
9
+ var SATOSHI_MAX = 2.1 * 1e15
10
+ function Satoshi ( value ) {
11
+ return typeforce . UInt53 ( value ) && value <= SATOSHI_MAX
12
+ }
13
+
9
14
function Bip32Path ( value ) {
10
15
return typeforce . String ( value ) &&
11
16
value . match ( / ^ ( m \/ ) ? ( \d + ' ? \/ ) * \d + ' ? $ / )
@@ -38,6 +43,7 @@ var types = {
38
43
Hash160bit : typeforce . BufferN ( 20 ) ,
39
44
Hash256bit : typeforce . BufferN ( 32 ) ,
40
45
Network : Network ,
46
+ Satoshi : Satoshi ,
41
47
UInt2 : UInt2 ,
42
48
UInt31 : UInt31 ,
43
49
Bip32Path : Bip32Path
Original file line number Diff line number Diff line change @@ -46,4 +46,19 @@ describe('types', function () {
46
46
} , / E x p e c t e d B u f f e r \( L e n g t h : 3 2 \) , g o t B u f f e r \( L e n g t h : 2 0 \) / )
47
47
} )
48
48
} )
49
+
50
+ describe ( 'Satoshi' , function ( ) {
51
+ [
52
+ { value : - 1 , result : false } ,
53
+ { value : 0 , result : true } ,
54
+ { value : 1 , result : true } ,
55
+ { value : 20999999 * 1e8 , result : true } ,
56
+ { value : 21000000 * 1e8 , result : true } ,
57
+ { value : 21000001 * 1e8 , result : false }
58
+ ] . forEach ( function ( f ) {
59
+ it ( 'returns ' + f . result + ' for valid for ' + f . value , function ( ) {
60
+ assert . strictEqual ( types . Satoshi ( f . value ) , f . result )
61
+ } )
62
+ } )
63
+ } )
49
64
} )
You can’t perform that action at this time.
0 commit comments