UNPKG

1.56 kBJavaScriptView Raw
1const JSBI = require('jsbi');
2
3JSBI.prototype.toJSON = function () {
4 // https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/BigInt
5 return this.toString();
6};
7
8const WORD_BYTES = 32; // byte number pre abi word
9const WORD_CHARS = WORD_BYTES * 2;
10const UINT_BOUND = JSBI.leftShift(JSBI.BigInt(1), JSBI.BigInt(WORD_BYTES * 8)); // 2**256
11const MAX_UINT = JSBI.subtract(UINT_BOUND, JSBI.BigInt(1)); // 2**256-1
12
13/**
14 * epochNumber label
15 *
16 * - `LATEST_MINED` 'latest_mined': latest epoch.
17 * - `LATEST_STATE` 'latest_state': latest state, about 5 epoch less then `LATEST_MINED`
18 * - `LATEST_CONFIRMED` 'latest_confirmed': latest epoch which confirmation risk less 1e-8.
19 * - `LATEST_CHECKPOINT` 'latest_checkpoint': latest check point epoch.
20 * - `EARLIEST` 'earliest': earliest epoch number, same as 0.
21 */
22const EPOCH_NUMBER = {
23 LATEST_MINED: 'latest_mined',
24 LATEST_STATE: 'latest_state',
25 LATEST_CONFIRMED: 'latest_confirmed',
26 LATEST_CHECKPOINT: 'latest_checkpoint',
27 EARLIEST: 'earliest',
28};
29
30/**
31 * min gas price for transaction
32 *
33 * @type {number} 1
34 */
35const MIN_GAS_PRICE = 1;
36
37/**
38 * gas use for pure transfer transaction
39 *
40 * @type {number} 2100
41 */
42const TRANSACTION_GAS = 21000;
43
44/**
45 * storage limit for pure transfer transaction
46 *
47 * @type {number} 0
48 */
49const TRANSACTION_STORAGE_LIMIT = 0;
50
51module.exports = {
52 WORD_BYTES,
53 WORD_CHARS,
54 UINT_BOUND,
55 MAX_UINT,
56 EPOCH_NUMBER,
57 MIN_GAS_PRICE,
58 TRANSACTION_GAS,
59 TRANSACTION_STORAGE_LIMIT,
60};