Typechecking indexes
As a consequence, it will not allow accidentally double-hardened indexes. It also won't allow strings or forgotten parameters.
This commit is contained in:
parent
75bd8331cd
commit
4a72001335
3 changed files with 51 additions and 0 deletions
src
|
@ -12,9 +12,13 @@ function Hash256bit (value) { return nBuffer(value, 32) }
|
|||
function Buffer256bit (value) { return nBuffer(value, 32) }
|
||||
|
||||
var UINT53_MAX = Math.pow(2, 53) - 1
|
||||
var UINT31_MAX = Math.pow(2, 31) - 1
|
||||
function UInt2 (value) { return (value & 3) === value }
|
||||
function UInt8 (value) { return (value & 0xff) === value }
|
||||
function UInt32 (value) { return (value >>> 0) === value }
|
||||
function UInt31 (value) {
|
||||
return UInt32(value) && value <= UINT31_MAX
|
||||
}
|
||||
function UInt53 (value) {
|
||||
return typeforce.Number(value) &&
|
||||
value >= 0 &&
|
||||
|
@ -51,6 +55,7 @@ var types = {
|
|||
Network: Network,
|
||||
UInt2: UInt2,
|
||||
UInt8: UInt8,
|
||||
UInt31: UInt31,
|
||||
UInt32: UInt32,
|
||||
UInt53: UInt53
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue