File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,11 @@ function UInt31 (value) {
66 return typeforce . UInt32 ( value ) && value <= UINT31_MAX
77}
88
9+ var SATOSHI_MAX = 2.1 * 1e15
10+ function Satoshi ( value ) {
11+ return typeforce . UInt53 ( value ) && value <= SATOSHI_MAX
12+ }
13+
914function Bip32Path ( value ) {
1015 return typeforce . String ( value ) &&
1116 value . match ( / ^ ( m \/ ) ? ( \d + ' ? \/ ) * \d + ' ? $ / )
@@ -38,6 +43,7 @@ var types = {
3843 Hash160bit : typeforce . BufferN ( 20 ) ,
3944 Hash256bit : typeforce . BufferN ( 32 ) ,
4045 Network : Network ,
46+ Satoshi : Satoshi ,
4147 UInt2 : UInt2 ,
4248 UInt31 : UInt31 ,
4349 Bip32Path : Bip32Path
Original file line number Diff line number Diff line change @@ -46,4 +46,19 @@ describe('types', function () {
4646 } , / 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 \) / )
4747 } )
4848 } )
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+ } )
4964} )
You can’t perform that action at this time.
0 commit comments