Files: cc2f7e5e75589bab19cc4621f39f35fe4eb262d3 / u256.js
744 bytesRaw
1 | const BN = require('bn.js') |
2 | const ethUtils = require('ethereumjs-util') |
3 | |
4 | module.exports = class U256 { |
5 | constructor (value) { |
6 | if ((typeof value === 'string') && ethUtils.isHexPrefixed(value)) { |
7 | this._value = new BN(value, 16) |
8 | } else { |
9 | this._value = new BN(value, 10) |
10 | } |
11 | } |
12 | |
13 | toString (radix = 10) { |
14 | if (radix === 16) { |
15 | return '0x' + this._value.toString(16) |
16 | } |
17 | return this._value.toString(radix) |
18 | } |
19 | |
20 | toBuffer () { |
21 | return this._value.toBuffer('be', 32) |
22 | } |
23 | |
24 | sub (u256) { |
25 | return this._value.sub(u256._value) |
26 | } |
27 | |
28 | add (u256) { |
29 | return this._value.add(u256._value) |
30 | } |
31 | |
32 | lt (u256) { |
33 | return this._value.lt(u256._value) |
34 | } |
35 | |
36 | gt (u256) { |
37 | return this._value.gt(u256._value) |
38 | } |
39 | } |
40 |
Built with git-ssb-web