github.com/luckypickle/go-ethereum-vet@v1.14.2/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  	"ethash":     Ethash_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 Ethash_JS = `
   114  web3._extend({
   115  	property: 'ethash',
   116  	methods: [
   117  		new web3._extend.Method({
   118  			name: 'getWork',
   119  			call: 'ethash_getWork',
   120  			params: 0
   121  		}),
   122  		new web3._extend.Method({
   123  			name: 'getHashrate',
   124  			call: 'ethash_getHashrate',
   125  			params: 0
   126  		}),
   127  		new web3._extend.Method({
   128  			name: 'submitWork',
   129  			call: 'ethash_submitWork',
   130  			params: 3,
   131  		}),
   132  		new web3._extend.Method({
   133  			name: 'submitHashRate',
   134  			call: 'ethash_submitHashRate',
   135  			params: 2,
   136  		}),
   137  	]
   138  });
   139  `
   140  
   141  const Admin_JS = `
   142  web3._extend({
   143  	property: 'admin',
   144  	methods: [
   145  		new web3._extend.Method({
   146  			name: 'addPeer',
   147  			call: 'admin_addPeer',
   148  			params: 1
   149  		}),
   150  		new web3._extend.Method({
   151  			name: 'removePeer',
   152  			call: 'admin_removePeer',
   153  			params: 1
   154  		}),
   155  		new web3._extend.Method({
   156  			name: 'addTrustedPeer',
   157  			call: 'admin_addTrustedPeer',
   158  			params: 1
   159  		}),
   160  		new web3._extend.Method({
   161  			name: 'removeTrustedPeer',
   162  			call: 'admin_removeTrustedPeer',
   163  			params: 1
   164  		}),
   165  		new web3._extend.Method({
   166  			name: 'exportChain',
   167  			call: 'admin_exportChain',
   168  			params: 1,
   169  			inputFormatter: [null]
   170  		}),
   171  		new web3._extend.Method({
   172  			name: 'importChain',
   173  			call: 'admin_importChain',
   174  			params: 1
   175  		}),
   176  		new web3._extend.Method({
   177  			name: 'sleepBlocks',
   178  			call: 'admin_sleepBlocks',
   179  			params: 2
   180  		}),
   181  		new web3._extend.Method({
   182  			name: 'startRPC',
   183  			call: 'admin_startRPC',
   184  			params: 4,
   185  			inputFormatter: [null, null, null, null]
   186  		}),
   187  		new web3._extend.Method({
   188  			name: 'stopRPC',
   189  			call: 'admin_stopRPC'
   190  		}),
   191  		new web3._extend.Method({
   192  			name: 'startWS',
   193  			call: 'admin_startWS',
   194  			params: 4,
   195  			inputFormatter: [null, null, null, null]
   196  		}),
   197  		new web3._extend.Method({
   198  			name: 'stopWS',
   199  			call: 'admin_stopWS'
   200  		}),
   201  	],
   202  	properties: [
   203  		new web3._extend.Property({
   204  			name: 'nodeInfo',
   205  			getter: 'admin_nodeInfo'
   206  		}),
   207  		new web3._extend.Property({
   208  			name: 'peers',
   209  			getter: 'admin_peers'
   210  		}),
   211  		new web3._extend.Property({
   212  			name: 'datadir',
   213  			getter: 'admin_datadir'
   214  		}),
   215  	]
   216  });
   217  `
   218  
   219  const Debug_JS = `
   220  web3._extend({
   221  	property: 'debug',
   222  	methods: [
   223  		new web3._extend.Method({
   224  			name: 'printBlock',
   225  			call: 'debug_printBlock',
   226  			params: 1
   227  		}),
   228  		new web3._extend.Method({
   229  			name: 'getBlockRlp',
   230  			call: 'debug_getBlockRlp',
   231  			params: 1
   232  		}),
   233  		new web3._extend.Method({
   234  			name: 'setHead',
   235  			call: 'debug_setHead',
   236  			params: 1
   237  		}),
   238  		new web3._extend.Method({
   239  			name: 'seedHash',
   240  			call: 'debug_seedHash',
   241  			params: 1
   242  		}),
   243  		new web3._extend.Method({
   244  			name: 'dumpBlock',
   245  			call: 'debug_dumpBlock',
   246  			params: 1
   247  		}),
   248  		new web3._extend.Method({
   249  			name: 'chaindbProperty',
   250  			call: 'debug_chaindbProperty',
   251  			params: 1,
   252  			outputFormatter: console.log
   253  		}),
   254  		new web3._extend.Method({
   255  			name: 'chaindbCompact',
   256  			call: 'debug_chaindbCompact',
   257  		}),
   258  		new web3._extend.Method({
   259  			name: 'metrics',
   260  			call: 'debug_metrics',
   261  			params: 1
   262  		}),
   263  		new web3._extend.Method({
   264  			name: 'verbosity',
   265  			call: 'debug_verbosity',
   266  			params: 1
   267  		}),
   268  		new web3._extend.Method({
   269  			name: 'vmodule',
   270  			call: 'debug_vmodule',
   271  			params: 1
   272  		}),
   273  		new web3._extend.Method({
   274  			name: 'backtraceAt',
   275  			call: 'debug_backtraceAt',
   276  			params: 1,
   277  		}),
   278  		new web3._extend.Method({
   279  			name: 'stacks',
   280  			call: 'debug_stacks',
   281  			params: 0,
   282  			outputFormatter: console.log
   283  		}),
   284  		new web3._extend.Method({
   285  			name: 'freeOSMemory',
   286  			call: 'debug_freeOSMemory',
   287  			params: 0,
   288  		}),
   289  		new web3._extend.Method({
   290  			name: 'setGCPercent',
   291  			call: 'debug_setGCPercent',
   292  			params: 1,
   293  		}),
   294  		new web3._extend.Method({
   295  			name: 'memStats',
   296  			call: 'debug_memStats',
   297  			params: 0,
   298  		}),
   299  		new web3._extend.Method({
   300  			name: 'gcStats',
   301  			call: 'debug_gcStats',
   302  			params: 0,
   303  		}),
   304  		new web3._extend.Method({
   305  			name: 'cpuProfile',
   306  			call: 'debug_cpuProfile',
   307  			params: 2
   308  		}),
   309  		new web3._extend.Method({
   310  			name: 'startCPUProfile',
   311  			call: 'debug_startCPUProfile',
   312  			params: 1
   313  		}),
   314  		new web3._extend.Method({
   315  			name: 'stopCPUProfile',
   316  			call: 'debug_stopCPUProfile',
   317  			params: 0
   318  		}),
   319  		new web3._extend.Method({
   320  			name: 'goTrace',
   321  			call: 'debug_goTrace',
   322  			params: 2
   323  		}),
   324  		new web3._extend.Method({
   325  			name: 'startGoTrace',
   326  			call: 'debug_startGoTrace',
   327  			params: 1
   328  		}),
   329  		new web3._extend.Method({
   330  			name: 'stopGoTrace',
   331  			call: 'debug_stopGoTrace',
   332  			params: 0
   333  		}),
   334  		new web3._extend.Method({
   335  			name: 'blockProfile',
   336  			call: 'debug_blockProfile',
   337  			params: 2
   338  		}),
   339  		new web3._extend.Method({
   340  			name: 'setBlockProfileRate',
   341  			call: 'debug_setBlockProfileRate',
   342  			params: 1
   343  		}),
   344  		new web3._extend.Method({
   345  			name: 'writeBlockProfile',
   346  			call: 'debug_writeBlockProfile',
   347  			params: 1
   348  		}),
   349  		new web3._extend.Method({
   350  			name: 'mutexProfile',
   351  			call: 'debug_mutexProfile',
   352  			params: 2
   353  		}),
   354  		new web3._extend.Method({
   355  			name: 'setMutexProfileFraction',
   356  			call: 'debug_setMutexProfileFraction',
   357  			params: 1
   358  		}),
   359  		new web3._extend.Method({
   360  			name: 'writeMutexProfile',
   361  			call: 'debug_writeMutexProfile',
   362  			params: 1
   363  		}),
   364  		new web3._extend.Method({
   365  			name: 'writeMemProfile',
   366  			call: 'debug_writeMemProfile',
   367  			params: 1
   368  		}),
   369  		new web3._extend.Method({
   370  			name: 'traceBlock',
   371  			call: 'debug_traceBlock',
   372  			params: 2,
   373  			inputFormatter: [null, null]
   374  		}),
   375  		new web3._extend.Method({
   376  			name: 'traceBlockFromFile',
   377  			call: 'debug_traceBlockFromFile',
   378  			params: 2,
   379  			inputFormatter: [null, null]
   380  		}),
   381  		new web3._extend.Method({
   382  			name: 'traceBlockByNumber',
   383  			call: 'debug_traceBlockByNumber',
   384  			params: 2,
   385  			inputFormatter: [null, null]
   386  		}),
   387  		new web3._extend.Method({
   388  			name: 'traceBlockByHash',
   389  			call: 'debug_traceBlockByHash',
   390  			params: 2,
   391  			inputFormatter: [null, null]
   392  		}),
   393  		new web3._extend.Method({
   394  			name: 'traceTransaction',
   395  			call: 'debug_traceTransaction',
   396  			params: 2,
   397  			inputFormatter: [null, null]
   398  		}),
   399  		new web3._extend.Method({
   400  			name: 'preimage',
   401  			call: 'debug_preimage',
   402  			params: 1,
   403  			inputFormatter: [null]
   404  		}),
   405  		new web3._extend.Method({
   406  			name: 'getBadBlocks',
   407  			call: 'debug_getBadBlocks',
   408  			params: 0,
   409  		}),
   410  		new web3._extend.Method({
   411  			name: 'storageRangeAt',
   412  			call: 'debug_storageRangeAt',
   413  			params: 5,
   414  		}),
   415  		new web3._extend.Method({
   416  			name: 'getModifiedAccountsByNumber',
   417  			call: 'debug_getModifiedAccountsByNumber',
   418  			params: 2,
   419  			inputFormatter: [null, null],
   420  		}),
   421  		new web3._extend.Method({
   422  			name: 'getModifiedAccountsByHash',
   423  			call: 'debug_getModifiedAccountsByHash',
   424  			params: 2,
   425  			inputFormatter:[null, null],
   426  		}),
   427  	],
   428  	properties: []
   429  });
   430  `
   431  
   432  const Eth_JS = `
   433  web3._extend({
   434  	property: 'eth',
   435  	methods: [
   436  		new web3._extend.Method({
   437  			name: 'sign',
   438  			call: 'eth_sign',
   439  			params: 2,
   440  			inputFormatter: [web3._extend.formatters.inputAddressFormatter, null]
   441  		}),
   442  		new web3._extend.Method({
   443  			name: 'resend',
   444  			call: 'eth_resend',
   445  			params: 3,
   446  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
   447  		}),
   448  		new web3._extend.Method({
   449  			name: 'signTransaction',
   450  			call: 'eth_signTransaction',
   451  			params: 1,
   452  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   453  		}),
   454  		new web3._extend.Method({
   455  			name: 'submitTransaction',
   456  			call: 'eth_submitTransaction',
   457  			params: 1,
   458  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   459  		}),
   460  		new web3._extend.Method({
   461  			name: 'getRawTransaction',
   462  			call: 'eth_getRawTransactionByHash',
   463  			params: 1
   464  		}),
   465  		new web3._extend.Method({
   466  			name: 'getRawTransactionFromBlock',
   467  			call: function(args) {
   468  				return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex';
   469  			},
   470  			params: 2,
   471  			inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex]
   472  		}),
   473  	],
   474  	properties: [
   475  		new web3._extend.Property({
   476  			name: 'pendingTransactions',
   477  			getter: 'eth_pendingTransactions',
   478  			outputFormatter: function(txs) {
   479  				var formatted = [];
   480  				for (var i = 0; i < txs.length; i++) {
   481  					formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i]));
   482  					formatted[i].blockHash = null;
   483  				}
   484  				return formatted;
   485  			}
   486  		}),
   487  	]
   488  });
   489  `
   490  
   491  const Miner_JS = `
   492  web3._extend({
   493  	property: 'miner',
   494  	methods: [
   495  		new web3._extend.Method({
   496  			name: 'start',
   497  			call: 'miner_start',
   498  			params: 1,
   499  			inputFormatter: [null]
   500  		}),
   501  		new web3._extend.Method({
   502  			name: 'stop',
   503  			call: 'miner_stop'
   504  		}),
   505  		new web3._extend.Method({
   506  			name: 'setEtherbase',
   507  			call: 'miner_setEtherbase',
   508  			params: 1,
   509  			inputFormatter: [web3._extend.formatters.inputAddressFormatter]
   510  		}),
   511  		new web3._extend.Method({
   512  			name: 'setExtra',
   513  			call: 'miner_setExtra',
   514  			params: 1
   515  		}),
   516  		new web3._extend.Method({
   517  			name: 'setGasPrice',
   518  			call: 'miner_setGasPrice',
   519  			params: 1,
   520  			inputFormatter: [web3._extend.utils.fromDecimal]
   521  		}),
   522  		new web3._extend.Method({
   523  			name: 'setRecommitInterval',
   524  			call: 'miner_setRecommitInterval',
   525  			params: 1,
   526  		}),
   527  		new web3._extend.Method({
   528  			name: 'getHashrate',
   529  			call: 'miner_getHashrate'
   530  		}),
   531  	],
   532  	properties: []
   533  });
   534  `
   535  
   536  const Net_JS = `
   537  web3._extend({
   538  	property: 'net',
   539  	methods: [],
   540  	properties: [
   541  		new web3._extend.Property({
   542  			name: 'version',
   543  			getter: 'net_version'
   544  		}),
   545  	]
   546  });
   547  `
   548  
   549  const Personal_JS = `
   550  web3._extend({
   551  	property: 'personal',
   552  	methods: [
   553  		new web3._extend.Method({
   554  			name: 'importRawKey',
   555  			call: 'personal_importRawKey',
   556  			params: 2
   557  		}),
   558  		new web3._extend.Method({
   559  			name: 'sign',
   560  			call: 'personal_sign',
   561  			params: 3,
   562  			inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null]
   563  		}),
   564  		new web3._extend.Method({
   565  			name: 'ecRecover',
   566  			call: 'personal_ecRecover',
   567  			params: 2
   568  		}),
   569  		new web3._extend.Method({
   570  			name: 'openWallet',
   571  			call: 'personal_openWallet',
   572  			params: 2
   573  		}),
   574  		new web3._extend.Method({
   575  			name: 'deriveAccount',
   576  			call: 'personal_deriveAccount',
   577  			params: 3
   578  		}),
   579  		new web3._extend.Method({
   580  			name: 'signTransaction',
   581  			call: 'personal_signTransaction',
   582  			params: 2,
   583  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null]
   584  		}),
   585  	],
   586  	properties: [
   587  		new web3._extend.Property({
   588  			name: 'listWallets',
   589  			getter: 'personal_listWallets'
   590  		}),
   591  	]
   592  })
   593  `
   594  
   595  const RPC_JS = `
   596  web3._extend({
   597  	property: 'rpc',
   598  	methods: [],
   599  	properties: [
   600  		new web3._extend.Property({
   601  			name: 'modules',
   602  			getter: 'rpc_modules'
   603  		}),
   604  	]
   605  });
   606  `
   607  
   608  const Shh_JS = `
   609  web3._extend({
   610  	property: 'shh',
   611  	methods: [
   612  	],
   613  	properties:
   614  	[
   615  		new web3._extend.Property({
   616  			name: 'version',
   617  			getter: 'shh_version',
   618  			outputFormatter: web3._extend.utils.toDecimal
   619  		}),
   620  		new web3._extend.Property({
   621  			name: 'info',
   622  			getter: 'shh_info'
   623  		}),
   624  	]
   625  });
   626  `
   627  
   628  const SWARMFS_JS = `
   629  web3._extend({
   630  	property: 'swarmfs',
   631  	methods:
   632  	[
   633  		new web3._extend.Method({
   634  			name: 'mount',
   635  			call: 'swarmfs_mount',
   636  			params: 2
   637  		}),
   638  		new web3._extend.Method({
   639  			name: 'unmount',
   640  			call: 'swarmfs_unmount',
   641  			params: 1
   642  		}),
   643  		new web3._extend.Method({
   644  			name: 'listmounts',
   645  			call: 'swarmfs_listmounts',
   646  			params: 0
   647  		}),
   648  	]
   649  });
   650  `
   651  
   652  const TxPool_JS = `
   653  web3._extend({
   654  	property: 'txpool',
   655  	methods: [],
   656  	properties:
   657  	[
   658  		new web3._extend.Property({
   659  			name: 'content',
   660  			getter: 'txpool_content'
   661  		}),
   662  		new web3._extend.Property({
   663  			name: 'inspect',
   664  			getter: 'txpool_inspect'
   665  		}),
   666  		new web3._extend.Property({
   667  			name: 'status',
   668  			getter: 'txpool_status',
   669  			outputFormatter: function(status) {
   670  				status.pending = web3._extend.utils.toDecimal(status.pending);
   671  				status.queued = web3._extend.utils.toDecimal(status.queued);
   672  				return status;
   673  			}
   674  		}),
   675  	]
   676  });
   677  `