github.com/nnlgsakib/mind-dpos@v0.0.0-20230606105614-f3c8ca06f808/internal/web3ext/web3ext.go (about)

     1  // Copyright 2015 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  // package web3ext contains geth specific web3.js extensions.
    18  package web3ext
    19  
    20  var Modules = map[string]string{
    21  	"admin":      Admin_JS,
    22  	"chequebook": Chequebook_JS,
    23  	"clique":     Clique_JS,
    24  	"alien":      Alien_JS,
    25  	"debug":      Debug_JS,
    26  	"eth":        Eth_JS,
    27  	"miner":      Miner_JS,
    28  	"net":        Net_JS,
    29  	"personal":   Personal_JS,
    30  	"rpc":        RPC_JS,
    31  	"shh":        Shh_JS,
    32  	"swarmfs":    SWARMFS_JS,
    33  	"txpool":     TxPool_JS,
    34  }
    35  
    36  const Chequebook_JS = `
    37  web3._extend({
    38  	property: 'chequebook',
    39  	methods: [
    40  		new web3._extend.Method({
    41  			name: 'deposit',
    42  			call: 'chequebook_deposit',
    43  			params: 1,
    44  			inputFormatter: [null]
    45  		}),
    46  		new web3._extend.Property({
    47  			name: 'balance',
    48  			getter: 'chequebook_balance',
    49  			outputFormatter: web3._extend.utils.toDecimal
    50  		}),
    51  		new web3._extend.Method({
    52  			name: 'cash',
    53  			call: 'chequebook_cash',
    54  			params: 1,
    55  			inputFormatter: [null]
    56  		}),
    57  		new web3._extend.Method({
    58  			name: 'issue',
    59  			call: 'chequebook_issue',
    60  			params: 2,
    61  			inputFormatter: [null, null]
    62  		}),
    63  	]
    64  });
    65  `
    66  
    67  const Clique_JS = `
    68  web3._extend({
    69  	property: 'clique',
    70  	methods: [
    71  		new web3._extend.Method({
    72  			name: 'getSnapshot',
    73  			call: 'clique_getSnapshot',
    74  			params: 1,
    75  			inputFormatter: [null]
    76  		}),
    77  		new web3._extend.Method({
    78  			name: 'getSnapshotAtHash',
    79  			call: 'clique_getSnapshotAtHash',
    80  			params: 1
    81  		}),
    82  		new web3._extend.Method({
    83  			name: 'getSigners',
    84  			call: 'clique_getSigners',
    85  			params: 1,
    86  			inputFormatter: [null]
    87  		}),
    88  		new web3._extend.Method({
    89  			name: 'getSignersAtHash',
    90  			call: 'clique_getSignersAtHash',
    91  			params: 1
    92  		}),
    93  		new web3._extend.Method({
    94  			name: 'propose',
    95  			call: 'clique_propose',
    96  			params: 2
    97  		}),
    98  		new web3._extend.Method({
    99  			name: 'discard',
   100  			call: 'clique_discard',
   101  			params: 1
   102  		}),
   103  	],
   104  	properties: [
   105  		new web3._extend.Property({
   106  			name: 'proposals',
   107  			getter: 'clique_proposals'
   108  		}),
   109  	]
   110  });
   111  `
   112  
   113  const Alien_JS = `
   114  web3._extend({
   115  	property: 'alien',
   116  	methods: [
   117  		new web3._extend.Method({
   118  			name: 'getSnapshot',
   119  			call: 'alien_getSnapshot',
   120  			params: 1,
   121  			inputFormatter: [null]
   122  		}),
   123  		new web3._extend.Method({
   124  			name: 'getSnapshotAtHash',
   125  			call: 'alien_getSnapshotAtHash',
   126  			params: 1
   127  		}),
   128  		new web3._extend.Method({
   129  			name: 'getSnapshotAtNumber',
   130  			call: 'alien_getSnapshotAtNumber',
   131  			params: 1
   132  		}),
   133  		new web3._extend.Method({
   134  			name: 'getSnapshotByHeaderTime',
   135  			call: 'alien_getSnapshotByHeaderTime',
   136  			params: 2
   137  		}),
   138  	]
   139  });
   140  `
   141  
   142  const Admin_JS = `
   143  web3._extend({
   144  	property: 'admin',
   145  	methods: [
   146  		new web3._extend.Method({
   147  			name: 'addPeer',
   148  			call: 'admin_addPeer',
   149  			params: 1
   150  		}),
   151  		new web3._extend.Method({
   152  			name: 'removePeer',
   153  			call: 'admin_removePeer',
   154  			params: 1
   155  		}),
   156  		new web3._extend.Method({
   157  			name: 'exportChain',
   158  			call: 'admin_exportChain',
   159  			params: 1,
   160  			inputFormatter: [null]
   161  		}),
   162  		new web3._extend.Method({
   163  			name: 'importChain',
   164  			call: 'admin_importChain',
   165  			params: 1
   166  		}),
   167  		new web3._extend.Method({
   168  			name: 'sleepBlocks',
   169  			call: 'admin_sleepBlocks',
   170  			params: 2
   171  		}),
   172  		new web3._extend.Method({
   173  			name: 'startRPC',
   174  			call: 'admin_startRPC',
   175  			params: 4,
   176  			inputFormatter: [null, null, null, null]
   177  		}),
   178  		new web3._extend.Method({
   179  			name: 'stopRPC',
   180  			call: 'admin_stopRPC'
   181  		}),
   182  		new web3._extend.Method({
   183  			name: 'startWS',
   184  			call: 'admin_startWS',
   185  			params: 4,
   186  			inputFormatter: [null, null, null, null]
   187  		}),
   188  		new web3._extend.Method({
   189  			name: 'stopWS',
   190  			call: 'admin_stopWS'
   191  		}),
   192  	],
   193  	properties: [
   194  		new web3._extend.Property({
   195  			name: 'nodeInfo',
   196  			getter: 'admin_nodeInfo'
   197  		}),
   198  		new web3._extend.Property({
   199  			name: 'peers',
   200  			getter: 'admin_peers'
   201  		}),
   202  		new web3._extend.Property({
   203  			name: 'datadir',
   204  			getter: 'admin_datadir'
   205  		}),
   206  	]
   207  });
   208  `
   209  
   210  const Debug_JS = `
   211  web3._extend({
   212  	property: 'debug',
   213  	methods: [
   214  		new web3._extend.Method({
   215  			name: 'printBlock',
   216  			call: 'debug_printBlock',
   217  			params: 1
   218  		}),
   219  		new web3._extend.Method({
   220  			name: 'getBlockRlp',
   221  			call: 'debug_getBlockRlp',
   222  			params: 1
   223  		}),
   224  		new web3._extend.Method({
   225  			name: 'setHead',
   226  			call: 'debug_setHead',
   227  			params: 1
   228  		}),
   229  		new web3._extend.Method({
   230  			name: 'seedHash',
   231  			call: 'debug_seedHash',
   232  			params: 1
   233  		}),
   234  		new web3._extend.Method({
   235  			name: 'dumpBlock',
   236  			call: 'debug_dumpBlock',
   237  			params: 1
   238  		}),
   239  		new web3._extend.Method({
   240  			name: 'chaindbProperty',
   241  			call: 'debug_chaindbProperty',
   242  			params: 1,
   243  			outputFormatter: console.log
   244  		}),
   245  		new web3._extend.Method({
   246  			name: 'chaindbCompact',
   247  			call: 'debug_chaindbCompact',
   248  		}),
   249  		new web3._extend.Method({
   250  			name: 'metrics',
   251  			call: 'debug_metrics',
   252  			params: 1
   253  		}),
   254  		new web3._extend.Method({
   255  			name: 'verbosity',
   256  			call: 'debug_verbosity',
   257  			params: 1
   258  		}),
   259  		new web3._extend.Method({
   260  			name: 'vmodule',
   261  			call: 'debug_vmodule',
   262  			params: 1
   263  		}),
   264  		new web3._extend.Method({
   265  			name: 'backtraceAt',
   266  			call: 'debug_backtraceAt',
   267  			params: 1,
   268  		}),
   269  		new web3._extend.Method({
   270  			name: 'stacks',
   271  			call: 'debug_stacks',
   272  			params: 0,
   273  			outputFormatter: console.log
   274  		}),
   275  		new web3._extend.Method({
   276  			name: 'freeOSMemory',
   277  			call: 'debug_freeOSMemory',
   278  			params: 0,
   279  		}),
   280  		new web3._extend.Method({
   281  			name: 'setGCPercent',
   282  			call: 'debug_setGCPercent',
   283  			params: 1,
   284  		}),
   285  		new web3._extend.Method({
   286  			name: 'memStats',
   287  			call: 'debug_memStats',
   288  			params: 0,
   289  		}),
   290  		new web3._extend.Method({
   291  			name: 'gcStats',
   292  			call: 'debug_gcStats',
   293  			params: 0,
   294  		}),
   295  		new web3._extend.Method({
   296  			name: 'cpuProfile',
   297  			call: 'debug_cpuProfile',
   298  			params: 2
   299  		}),
   300  		new web3._extend.Method({
   301  			name: 'startCPUProfile',
   302  			call: 'debug_startCPUProfile',
   303  			params: 1
   304  		}),
   305  		new web3._extend.Method({
   306  			name: 'stopCPUProfile',
   307  			call: 'debug_stopCPUProfile',
   308  			params: 0
   309  		}),
   310  		new web3._extend.Method({
   311  			name: 'goTrace',
   312  			call: 'debug_goTrace',
   313  			params: 2
   314  		}),
   315  		new web3._extend.Method({
   316  			name: 'startGoTrace',
   317  			call: 'debug_startGoTrace',
   318  			params: 1
   319  		}),
   320  		new web3._extend.Method({
   321  			name: 'stopGoTrace',
   322  			call: 'debug_stopGoTrace',
   323  			params: 0
   324  		}),
   325  		new web3._extend.Method({
   326  			name: 'blockProfile',
   327  			call: 'debug_blockProfile',
   328  			params: 2
   329  		}),
   330  		new web3._extend.Method({
   331  			name: 'setBlockProfileRate',
   332  			call: 'debug_setBlockProfileRate',
   333  			params: 1
   334  		}),
   335  		new web3._extend.Method({
   336  			name: 'writeBlockProfile',
   337  			call: 'debug_writeBlockProfile',
   338  			params: 1
   339  		}),
   340  		new web3._extend.Method({
   341  			name: 'mutexProfile',
   342  			call: 'debug_mutexProfile',
   343  			params: 2
   344  		}),
   345  		new web3._extend.Method({
   346  			name: 'setMutexProfileRate',
   347  			call: 'debug_setMutexProfileRate',
   348  			params: 1
   349  		}),
   350  		new web3._extend.Method({
   351  			name: 'writeMutexProfile',
   352  			call: 'debug_writeMutexProfile',
   353  			params: 1
   354  		}),
   355  		new web3._extend.Method({
   356  			name: 'writeMemProfile',
   357  			call: 'debug_writeMemProfile',
   358  			params: 1
   359  		}),
   360  		new web3._extend.Method({
   361  			name: 'traceBlock',
   362  			call: 'debug_traceBlock',
   363  			params: 2,
   364  			inputFormatter: [null, null]
   365  		}),
   366  		new web3._extend.Method({
   367  			name: 'traceBlockFromFile',
   368  			call: 'debug_traceBlockFromFile',
   369  			params: 2,
   370  			inputFormatter: [null, null]
   371  		}),
   372  		new web3._extend.Method({
   373  			name: 'traceBlockByNumber',
   374  			call: 'debug_traceBlockByNumber',
   375  			params: 2,
   376  			inputFormatter: [null, null]
   377  		}),
   378  		new web3._extend.Method({
   379  			name: 'traceBlockByHash',
   380  			call: 'debug_traceBlockByHash',
   381  			params: 2,
   382  			inputFormatter: [null, null]
   383  		}),
   384  		new web3._extend.Method({
   385  			name: 'traceTransaction',
   386  			call: 'debug_traceTransaction',
   387  			params: 2,
   388  			inputFormatter: [null, null]
   389  		}),
   390  		new web3._extend.Method({
   391  			name: 'preimage',
   392  			call: 'debug_preimage',
   393  			params: 1,
   394  			inputFormatter: [null]
   395  		}),
   396  		new web3._extend.Method({
   397  			name: 'getBadBlocks',
   398  			call: 'debug_getBadBlocks',
   399  			params: 0,
   400  		}),
   401  		new web3._extend.Method({
   402  			name: 'storageRangeAt',
   403  			call: 'debug_storageRangeAt',
   404  			params: 5,
   405  		}),
   406  		new web3._extend.Method({
   407  			name: 'getModifiedAccountsByNumber',
   408  			call: 'debug_getModifiedAccountsByNumber',
   409  			params: 2,
   410  			inputFormatter: [null, null],
   411  		}),
   412  		new web3._extend.Method({
   413  			name: 'getModifiedAccountsByHash',
   414  			call: 'debug_getModifiedAccountsByHash',
   415  			params: 2,
   416  			inputFormatter:[null, null],
   417  		}),
   418  	],
   419  	properties: []
   420  });
   421  `
   422  
   423  const Eth_JS = `
   424  web3._extend({
   425  	property: 'eth',
   426  	methods: [
   427  		new web3._extend.Method({
   428  			name: 'sign',
   429  			call: 'eth_sign',
   430  			params: 2,
   431  			inputFormatter: [web3._extend.formatters.inputAddressFormatter, null]
   432  		}),
   433  		new web3._extend.Method({
   434  			name: 'resend',
   435  			call: 'eth_resend',
   436  			params: 3,
   437  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
   438  		}),
   439  		new web3._extend.Method({
   440  			name: 'signTransaction',
   441  			call: 'eth_signTransaction',
   442  			params: 1,
   443  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   444  		}),
   445  		new web3._extend.Method({
   446  			name: 'submitTransaction',
   447  			call: 'eth_submitTransaction',
   448  			params: 1,
   449  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   450  		}),
   451  		new web3._extend.Method({
   452  			name: 'getRawTransaction',
   453  			call: 'eth_getRawTransactionByHash',
   454  			params: 1
   455  		}),
   456  		new web3._extend.Method({
   457  			name: 'getRawTransactionFromBlock',
   458  			call: function(args) {
   459  				return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex';
   460  			},
   461  			params: 2,
   462  			inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex]
   463  		}),
   464  	],
   465  	properties: [
   466  		new web3._extend.Property({
   467  			name: 'pendingTransactions',
   468  			getter: 'eth_pendingTransactions',
   469  			outputFormatter: function(txs) {
   470  				var formatted = [];
   471  				for (var i = 0; i < txs.length; i++) {
   472  					formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i]));
   473  					formatted[i].blockHash = null;
   474  				}
   475  				return formatted;
   476  			}
   477  		}),
   478  		new web3._extend.Property({
   479  			name: 'chainId',
   480  			getter: 'eth_chainId'
   481  		}),
   482  	]
   483  });
   484  `
   485  
   486  const Miner_JS = `
   487  web3._extend({
   488  	property: 'miner',
   489  	methods: [
   490  		new web3._extend.Method({
   491  			name: 'start',
   492  			call: 'miner_start',
   493  			params: 1,
   494  			inputFormatter: [null]
   495  		}),
   496  		new web3._extend.Method({
   497  			name: 'stop',
   498  			call: 'miner_stop'
   499  		}),
   500  		new web3._extend.Method({
   501  			name: 'setEtherbase',
   502  			call: 'miner_setEtherbase',
   503  			params: 1,
   504  			inputFormatter: [web3._extend.formatters.inputAddressFormatter]
   505  		}),
   506  		new web3._extend.Method({
   507  			name: 'setExtra',
   508  			call: 'miner_setExtra',
   509  			params: 1
   510  		}),
   511  		new web3._extend.Method({
   512  			name: 'setGasPrice',
   513  			call: 'miner_setGasPrice',
   514  			params: 1,
   515  			inputFormatter: [web3._extend.utils.fromDecimal]
   516  		}),
   517  		new web3._extend.Method({
   518  			name: 'getHashrate',
   519  			call: 'miner_getHashrate'
   520  		}),
   521  	],
   522  	properties: []
   523  });
   524  `
   525  
   526  const Net_JS = `
   527  web3._extend({
   528  	property: 'net',
   529  	methods: [],
   530  	properties: [
   531  		new web3._extend.Property({
   532  			name: 'version',
   533  			getter: 'net_version'
   534  		}),
   535  	]
   536  });
   537  `
   538  
   539  const Personal_JS = `
   540  web3._extend({
   541  	property: 'personal',
   542  	methods: [
   543  		new web3._extend.Method({
   544  			name: 'importRawKey',
   545  			call: 'personal_importRawKey',
   546  			params: 2
   547  		}),
   548  		new web3._extend.Method({
   549  			name: 'sign',
   550  			call: 'personal_sign',
   551  			params: 3,
   552  			inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null]
   553  		}),
   554  		new web3._extend.Method({
   555  			name: 'ecRecover',
   556  			call: 'personal_ecRecover',
   557  			params: 2
   558  		}),
   559  		new web3._extend.Method({
   560  			name: 'openWallet',
   561  			call: 'personal_openWallet',
   562  			params: 2
   563  		}),
   564  		new web3._extend.Method({
   565  			name: 'deriveAccount',
   566  			call: 'personal_deriveAccount',
   567  			params: 3
   568  		}),
   569  		new web3._extend.Method({
   570  			name: 'signTransaction',
   571  			call: 'personal_signTransaction',
   572  			params: 2,
   573  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null]
   574  		}),
   575  	],
   576  	properties: [
   577  		new web3._extend.Property({
   578  			name: 'listWallets',
   579  			getter: 'personal_listWallets'
   580  		}),
   581  	]
   582  })
   583  `
   584  
   585  const RPC_JS = `
   586  web3._extend({
   587  	property: 'rpc',
   588  	methods: [],
   589  	properties: [
   590  		new web3._extend.Property({
   591  			name: 'modules',
   592  			getter: 'rpc_modules'
   593  		}),
   594  	]
   595  });
   596  `
   597  
   598  const Shh_JS = `
   599  web3._extend({
   600  	property: 'shh',
   601  	methods: [
   602  	],
   603  	properties:
   604  	[
   605  		new web3._extend.Property({
   606  			name: 'version',
   607  			getter: 'shh_version',
   608  			outputFormatter: web3._extend.utils.toDecimal
   609  		}),
   610  		new web3._extend.Property({
   611  			name: 'info',
   612  			getter: 'shh_info'
   613  		}),
   614  	]
   615  });
   616  `
   617  
   618  const SWARMFS_JS = `
   619  web3._extend({
   620  	property: 'swarmfs',
   621  	methods:
   622  	[
   623  		new web3._extend.Method({
   624  			name: 'mount',
   625  			call: 'swarmfs_mount',
   626  			params: 2
   627  		}),
   628  		new web3._extend.Method({
   629  			name: 'unmount',
   630  			call: 'swarmfs_unmount',
   631  			params: 1
   632  		}),
   633  		new web3._extend.Method({
   634  			name: 'listmounts',
   635  			call: 'swarmfs_listmounts',
   636  			params: 0
   637  		}),
   638  	]
   639  });
   640  `
   641  
   642  const TxPool_JS = `
   643  web3._extend({
   644  	property: 'txpool',
   645  	methods: [],
   646  	properties:
   647  	[
   648  		new web3._extend.Property({
   649  			name: 'content',
   650  			getter: 'txpool_content'
   651  		}),
   652  		new web3._extend.Property({
   653  			name: 'inspect',
   654  			getter: 'txpool_inspect'
   655  		}),
   656  		new web3._extend.Property({
   657  			name: 'status',
   658  			getter: 'txpool_status',
   659  			outputFormatter: function(status) {
   660  				status.pending = web3._extend.utils.toDecimal(status.pending);
   661  				status.queued = web3._extend.utils.toDecimal(status.queued);
   662  				return status;
   663  			}
   664  		}),
   665  	]
   666  });
   667  `