github.com/nitinawathare/ethereumassignment3@v0.0.0-20211021213010-f07344c2b868/go-ethereum/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  	"accounting": AccountingJs,
    22  	"admin":      AdminJs,
    23  	"chequebook": ChequebookJs,
    24  	"clique":     CliqueJs,
    25  	"ethash":     EthashJs,
    26  	"debug":      DebugJs,
    27  	"eth":        EthJs,
    28  	"miner":      MinerJs,
    29  	"net":        NetJs,
    30  	"personal":   PersonalJs,
    31  	"rpc":        RpcJs,
    32  	"shh":        ShhJs,
    33  	"swarmfs":    SwarmfsJs,
    34  	"txpool":     TxpoolJs,
    35  }
    36  
    37  const ChequebookJs = `
    38  web3._extend({
    39  	property: 'chequebook',
    40  	methods: [
    41  		new web3._extend.Method({
    42  			name: 'deposit',
    43  			call: 'chequebook_deposit',
    44  			params: 1,
    45  			inputFormatter: [null]
    46  		}),
    47  		new web3._extend.Property({
    48  			name: 'balance',
    49  			getter: 'chequebook_balance',
    50  			outputFormatter: web3._extend.utils.toDecimal
    51  		}),
    52  		new web3._extend.Method({
    53  			name: 'cash',
    54  			call: 'chequebook_cash',
    55  			params: 1,
    56  			inputFormatter: [null]
    57  		}),
    58  		new web3._extend.Method({
    59  			name: 'issue',
    60  			call: 'chequebook_issue',
    61  			params: 2,
    62  			inputFormatter: [null, null]
    63  		}),
    64  	]
    65  });
    66  `
    67  
    68  const CliqueJs = `
    69  web3._extend({
    70  	property: 'clique',
    71  	methods: [
    72  		new web3._extend.Method({
    73  			name: 'getSnapshot',
    74  			call: 'clique_getSnapshot',
    75  			params: 1,
    76  			inputFormatter: [null]
    77  		}),
    78  		new web3._extend.Method({
    79  			name: 'getSnapshotAtHash',
    80  			call: 'clique_getSnapshotAtHash',
    81  			params: 1
    82  		}),
    83  		new web3._extend.Method({
    84  			name: 'getSigners',
    85  			call: 'clique_getSigners',
    86  			params: 1,
    87  			inputFormatter: [null]
    88  		}),
    89  		new web3._extend.Method({
    90  			name: 'getSignersAtHash',
    91  			call: 'clique_getSignersAtHash',
    92  			params: 1
    93  		}),
    94  		new web3._extend.Method({
    95  			name: 'propose',
    96  			call: 'clique_propose',
    97  			params: 2
    98  		}),
    99  		new web3._extend.Method({
   100  			name: 'discard',
   101  			call: 'clique_discard',
   102  			params: 1
   103  		}),
   104  	],
   105  	properties: [
   106  		new web3._extend.Property({
   107  			name: 'proposals',
   108  			getter: 'clique_proposals'
   109  		}),
   110  	]
   111  });
   112  `
   113  
   114  const EthashJs = `
   115  web3._extend({
   116  	property: 'ethash',
   117  	methods: [
   118  		new web3._extend.Method({
   119  			name: 'getWork',
   120  			call: 'ethash_getWork',
   121  			params: 0
   122  		}),
   123  		new web3._extend.Method({
   124  			name: 'getHashrate',
   125  			call: 'ethash_getHashrate',
   126  			params: 0
   127  		}),
   128  		new web3._extend.Method({
   129  			name: 'submitWork',
   130  			call: 'ethash_submitWork',
   131  			params: 3,
   132  		}),
   133  		new web3._extend.Method({
   134  			name: 'submitHashRate',
   135  			call: 'ethash_submitHashRate',
   136  			params: 2,
   137  		}),
   138  	]
   139  });
   140  `
   141  
   142  const AdminJs = `
   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: 'addTrustedPeer',
   158  			call: 'admin_addTrustedPeer',
   159  			params: 1
   160  		}),
   161  		new web3._extend.Method({
   162  			name: 'removeTrustedPeer',
   163  			call: 'admin_removeTrustedPeer',
   164  			params: 1
   165  		}),
   166  		new web3._extend.Method({
   167  			name: 'exportChain',
   168  			call: 'admin_exportChain',
   169  			params: 1,
   170  			inputFormatter: [null]
   171  		}),
   172  		new web3._extend.Method({
   173  			name: 'importChain',
   174  			call: 'admin_importChain',
   175  			params: 1
   176  		}),
   177  		new web3._extend.Method({
   178  			name: 'sleepBlocks',
   179  			call: 'admin_sleepBlocks',
   180  			params: 2
   181  		}),
   182  		new web3._extend.Method({
   183  			name: 'startRPC',
   184  			call: 'admin_startRPC',
   185  			params: 4,
   186  			inputFormatter: [null, null, null, null]
   187  		}),
   188  		new web3._extend.Method({
   189  			name: 'stopRPC',
   190  			call: 'admin_stopRPC'
   191  		}),
   192  		new web3._extend.Method({
   193  			name: 'startWS',
   194  			call: 'admin_startWS',
   195  			params: 4,
   196  			inputFormatter: [null, null, null, null]
   197  		}),
   198  		new web3._extend.Method({
   199  			name: 'stopWS',
   200  			call: 'admin_stopWS'
   201  		}),
   202  	],
   203  	properties: [
   204  		new web3._extend.Property({
   205  			name: 'nodeInfo',
   206  			getter: 'admin_nodeInfo'
   207  		}),
   208  		new web3._extend.Property({
   209  			name: 'peers',
   210  			getter: 'admin_peers'
   211  		}),
   212  		new web3._extend.Property({
   213  			name: 'datadir',
   214  			getter: 'admin_datadir'
   215  		}),
   216  	]
   217  });
   218  `
   219  
   220  const DebugJs = `
   221  web3._extend({
   222  	property: 'debug',
   223  	methods: [
   224  		new web3._extend.Method({
   225  			name: 'printBlock',
   226  			call: 'debug_printBlock',
   227  			params: 1
   228  		}),
   229  		new web3._extend.Method({
   230  			name: 'getBlockRlp',
   231  			call: 'debug_getBlockRlp',
   232  			params: 1
   233  		}),
   234  		new web3._extend.Method({
   235  			name: 'testSignCliqueBlock',
   236  			call: 'debug_testSignCliqueBlock',
   237  			params: 2,
   238  			inputFormatters: [web3._extend.formatters.inputAddressFormatter, null],
   239  		}),
   240  		new web3._extend.Method({
   241  			name: 'setHead',
   242  			call: 'debug_setHead',
   243  			params: 1
   244  		}),
   245  		new web3._extend.Method({
   246  			name: 'seedHash',
   247  			call: 'debug_seedHash',
   248  			params: 1
   249  		}),
   250  		new web3._extend.Method({
   251  			name: 'dumpBlock',
   252  			call: 'debug_dumpBlock',
   253  			params: 1
   254  		}),
   255  		new web3._extend.Method({
   256  			name: 'chaindbProperty',
   257  			call: 'debug_chaindbProperty',
   258  			params: 1,
   259  			outputFormatter: console.log
   260  		}),
   261  		new web3._extend.Method({
   262  			name: 'chaindbCompact',
   263  			call: 'debug_chaindbCompact',
   264  		}),
   265  		new web3._extend.Method({
   266  			name: 'verbosity',
   267  			call: 'debug_verbosity',
   268  			params: 1
   269  		}),
   270  		new web3._extend.Method({
   271  			name: 'vmodule',
   272  			call: 'debug_vmodule',
   273  			params: 1
   274  		}),
   275  		new web3._extend.Method({
   276  			name: 'backtraceAt',
   277  			call: 'debug_backtraceAt',
   278  			params: 1,
   279  		}),
   280  		new web3._extend.Method({
   281  			name: 'stacks',
   282  			call: 'debug_stacks',
   283  			params: 0,
   284  			outputFormatter: console.log
   285  		}),
   286  		new web3._extend.Method({
   287  			name: 'freeOSMemory',
   288  			call: 'debug_freeOSMemory',
   289  			params: 0,
   290  		}),
   291  		new web3._extend.Method({
   292  			name: 'setGCPercent',
   293  			call: 'debug_setGCPercent',
   294  			params: 1,
   295  		}),
   296  		new web3._extend.Method({
   297  			name: 'memStats',
   298  			call: 'debug_memStats',
   299  			params: 0,
   300  		}),
   301  		new web3._extend.Method({
   302  			name: 'gcStats',
   303  			call: 'debug_gcStats',
   304  			params: 0,
   305  		}),
   306  		new web3._extend.Method({
   307  			name: 'cpuProfile',
   308  			call: 'debug_cpuProfile',
   309  			params: 2
   310  		}),
   311  		new web3._extend.Method({
   312  			name: 'startCPUProfile',
   313  			call: 'debug_startCPUProfile',
   314  			params: 1
   315  		}),
   316  		new web3._extend.Method({
   317  			name: 'stopCPUProfile',
   318  			call: 'debug_stopCPUProfile',
   319  			params: 0
   320  		}),
   321  		new web3._extend.Method({
   322  			name: 'goTrace',
   323  			call: 'debug_goTrace',
   324  			params: 2
   325  		}),
   326  		new web3._extend.Method({
   327  			name: 'startGoTrace',
   328  			call: 'debug_startGoTrace',
   329  			params: 1
   330  		}),
   331  		new web3._extend.Method({
   332  			name: 'stopGoTrace',
   333  			call: 'debug_stopGoTrace',
   334  			params: 0
   335  		}),
   336  		new web3._extend.Method({
   337  			name: 'blockProfile',
   338  			call: 'debug_blockProfile',
   339  			params: 2
   340  		}),
   341  		new web3._extend.Method({
   342  			name: 'setBlockProfileRate',
   343  			call: 'debug_setBlockProfileRate',
   344  			params: 1
   345  		}),
   346  		new web3._extend.Method({
   347  			name: 'writeBlockProfile',
   348  			call: 'debug_writeBlockProfile',
   349  			params: 1
   350  		}),
   351  		new web3._extend.Method({
   352  			name: 'mutexProfile',
   353  			call: 'debug_mutexProfile',
   354  			params: 2
   355  		}),
   356  		new web3._extend.Method({
   357  			name: 'setMutexProfileFraction',
   358  			call: 'debug_setMutexProfileFraction',
   359  			params: 1
   360  		}),
   361  		new web3._extend.Method({
   362  			name: 'writeMutexProfile',
   363  			call: 'debug_writeMutexProfile',
   364  			params: 1
   365  		}),
   366  		new web3._extend.Method({
   367  			name: 'writeMemProfile',
   368  			call: 'debug_writeMemProfile',
   369  			params: 1
   370  		}),
   371  		new web3._extend.Method({
   372  			name: 'traceBlock',
   373  			call: 'debug_traceBlock',
   374  			params: 2,
   375  			inputFormatter: [null, null]
   376  		}),
   377  		new web3._extend.Method({
   378  			name: 'traceBlockFromFile',
   379  			call: 'debug_traceBlockFromFile',
   380  			params: 2,
   381  			inputFormatter: [null, null]
   382  		}),
   383  		new web3._extend.Method({
   384  			name: 'traceBadBlock',
   385  			call: 'debug_traceBadBlock',
   386  			params: 1,
   387  			inputFormatter: [null]
   388  		}),
   389  		new web3._extend.Method({
   390  			name: 'standardTraceBadBlockToFile',
   391  			call: 'debug_standardTraceBadBlockToFile',
   392  			params: 2,
   393  			inputFormatter: [null, null]
   394  		}),
   395  		new web3._extend.Method({
   396  			name: 'standardTraceBlockToFile',
   397  			call: 'debug_standardTraceBlockToFile',
   398  			params: 2,
   399  			inputFormatter: [null, null]
   400  		}),
   401  		new web3._extend.Method({
   402  			name: 'traceBlockByNumber',
   403  			call: 'debug_traceBlockByNumber',
   404  			params: 2,
   405  			inputFormatter: [null, null]
   406  		}),
   407  		new web3._extend.Method({
   408  			name: 'traceBlockByHash',
   409  			call: 'debug_traceBlockByHash',
   410  			params: 2,
   411  			inputFormatter: [null, null]
   412  		}),
   413  		new web3._extend.Method({
   414  			name: 'traceTransaction',
   415  			call: 'debug_traceTransaction',
   416  			params: 2,
   417  			inputFormatter: [null, null]
   418  		}),
   419  		new web3._extend.Method({
   420  			name: 'preimage',
   421  			call: 'debug_preimage',
   422  			params: 1,
   423  			inputFormatter: [null]
   424  		}),
   425  		new web3._extend.Method({
   426  			name: 'getBadBlocks',
   427  			call: 'debug_getBadBlocks',
   428  			params: 0,
   429  		}),
   430  		new web3._extend.Method({
   431  			name: 'storageRangeAt',
   432  			call: 'debug_storageRangeAt',
   433  			params: 5,
   434  		}),
   435  		new web3._extend.Method({
   436  			name: 'getModifiedAccountsByNumber',
   437  			call: 'debug_getModifiedAccountsByNumber',
   438  			params: 2,
   439  			inputFormatter: [null, null],
   440  		}),
   441  		new web3._extend.Method({
   442  			name: 'getModifiedAccountsByHash',
   443  			call: 'debug_getModifiedAccountsByHash',
   444  			params: 2,
   445  			inputFormatter:[null, null],
   446  		}),
   447  	],
   448  	properties: []
   449  });
   450  `
   451  
   452  const EthJs = `
   453  web3._extend({
   454  	property: 'eth',
   455  	methods: [
   456  		new web3._extend.Method({
   457  			name: 'chainId',
   458  			call: 'eth_chainId',
   459  			params: 0
   460  		}),
   461  		new web3._extend.Method({
   462  			name: 'sign',
   463  			call: 'eth_sign',
   464  			params: 2,
   465  			inputFormatter: [web3._extend.formatters.inputAddressFormatter, null]
   466  		}),
   467  		new web3._extend.Method({
   468  			name: 'resend',
   469  			call: 'eth_resend',
   470  			params: 3,
   471  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
   472  		}),
   473  		new web3._extend.Method({
   474  			name: 'signTransaction',
   475  			call: 'eth_signTransaction',
   476  			params: 1,
   477  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   478  		}),
   479  		new web3._extend.Method({
   480  			name: 'submitTransaction',
   481  			call: 'eth_submitTransaction',
   482  			params: 1,
   483  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   484  		}),
   485  		new web3._extend.Method({
   486  			name: 'getRawTransaction',
   487  			call: 'eth_getRawTransactionByHash',
   488  			params: 1
   489  		}),
   490  		new web3._extend.Method({
   491  			name: 'getRawTransactionFromBlock',
   492  			call: function(args) {
   493  				return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex';
   494  			},
   495  			params: 2,
   496  			inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex]
   497  		}),
   498  		new web3._extend.Method({
   499  			name: 'getProof',
   500  			call: 'eth_getProof',
   501  			params: 3,
   502  			inputFormatter: [web3._extend.formatters.inputAddressFormatter, null, web3._extend.formatters.inputBlockNumberFormatter]
   503  		}),
   504  	],
   505  	properties: [
   506  		new web3._extend.Property({
   507  			name: 'pendingTransactions',
   508  			getter: 'eth_pendingTransactions',
   509  			outputFormatter: function(txs) {
   510  				var formatted = [];
   511  				for (var i = 0; i < txs.length; i++) {
   512  					formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i]));
   513  					formatted[i].blockHash = null;
   514  				}
   515  				return formatted;
   516  			}
   517  		}),
   518  	]
   519  });
   520  `
   521  
   522  const MinerJs = `
   523  web3._extend({
   524  	property: 'miner',
   525  	methods: [
   526  		new web3._extend.Method({
   527  			name: 'start',
   528  			call: 'miner_start',
   529  			params: 1,
   530  			inputFormatter: [null]
   531  		}),
   532  		new web3._extend.Method({
   533  			name: 'stop',
   534  			call: 'miner_stop'
   535  		}),
   536  		new web3._extend.Method({
   537  			name: 'setEtherbase',
   538  			call: 'miner_setEtherbase',
   539  			params: 1,
   540  			inputFormatter: [web3._extend.formatters.inputAddressFormatter]
   541  		}),
   542  		new web3._extend.Method({
   543  			name: 'setExtra',
   544  			call: 'miner_setExtra',
   545  			params: 1
   546  		}),
   547  		new web3._extend.Method({
   548  			name: 'setGasPrice',
   549  			call: 'miner_setGasPrice',
   550  			params: 1,
   551  			inputFormatter: [web3._extend.utils.fromDecimal]
   552  		}),
   553  		new web3._extend.Method({
   554  			name: 'setRecommitInterval',
   555  			call: 'miner_setRecommitInterval',
   556  			params: 1,
   557  		}),
   558  		new web3._extend.Method({
   559  			name: 'getHashrate',
   560  			call: 'miner_getHashrate'
   561  		}),
   562  	],
   563  	properties: []
   564  });
   565  `
   566  
   567  const NetJs = `
   568  web3._extend({
   569  	property: 'net',
   570  	methods: [],
   571  	properties: [
   572  		new web3._extend.Property({
   573  			name: 'version',
   574  			getter: 'net_version'
   575  		}),
   576  	]
   577  });
   578  `
   579  
   580  const PersonalJs = `
   581  web3._extend({
   582  	property: 'personal',
   583  	methods: [
   584  		new web3._extend.Method({
   585  			name: 'importRawKey',
   586  			call: 'personal_importRawKey',
   587  			params: 2
   588  		}),
   589  		new web3._extend.Method({
   590  			name: 'sign',
   591  			call: 'personal_sign',
   592  			params: 3,
   593  			inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null]
   594  		}),
   595  		new web3._extend.Method({
   596  			name: 'ecRecover',
   597  			call: 'personal_ecRecover',
   598  			params: 2
   599  		}),
   600  		new web3._extend.Method({
   601  			name: 'openWallet',
   602  			call: 'personal_openWallet',
   603  			params: 2
   604  		}),
   605  		new web3._extend.Method({
   606  			name: 'deriveAccount',
   607  			call: 'personal_deriveAccount',
   608  			params: 3
   609  		}),
   610  		new web3._extend.Method({
   611  			name: 'signTransaction',
   612  			call: 'personal_signTransaction',
   613  			params: 2,
   614  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null]
   615  		}),
   616  		new web3._extend.Method({
   617  			name: 'unpair',
   618  			call: 'personal_unpair',
   619  			params: 2
   620  		}),
   621  		new web3._extend.Method({
   622  			name: 'initializeWallet',
   623  			call: 'personal_initializeWallet',
   624  			params: 1
   625  		})
   626  	],
   627  	properties: [
   628  		new web3._extend.Property({
   629  			name: 'listWallets',
   630  			getter: 'personal_listWallets'
   631  		}),
   632  	]
   633  })
   634  `
   635  
   636  const RpcJs = `
   637  web3._extend({
   638  	property: 'rpc',
   639  	methods: [],
   640  	properties: [
   641  		new web3._extend.Property({
   642  			name: 'modules',
   643  			getter: 'rpc_modules'
   644  		}),
   645  	]
   646  });
   647  `
   648  
   649  const ShhJs = `
   650  web3._extend({
   651  	property: 'shh',
   652  	methods: [
   653  	],
   654  	properties:
   655  	[
   656  		new web3._extend.Property({
   657  			name: 'version',
   658  			getter: 'shh_version',
   659  			outputFormatter: web3._extend.utils.toDecimal
   660  		}),
   661  		new web3._extend.Property({
   662  			name: 'info',
   663  			getter: 'shh_info'
   664  		}),
   665  	]
   666  });
   667  `
   668  
   669  const SwarmfsJs = `
   670  web3._extend({
   671  	property: 'swarmfs',
   672  	methods:
   673  	[
   674  		new web3._extend.Method({
   675  			name: 'mount',
   676  			call: 'swarmfs_mount',
   677  			params: 2
   678  		}),
   679  		new web3._extend.Method({
   680  			name: 'unmount',
   681  			call: 'swarmfs_unmount',
   682  			params: 1
   683  		}),
   684  		new web3._extend.Method({
   685  			name: 'listmounts',
   686  			call: 'swarmfs_listmounts',
   687  			params: 0
   688  		}),
   689  	]
   690  });
   691  `
   692  
   693  const TxpoolJs = `
   694  web3._extend({
   695  	property: 'txpool',
   696  	methods: [],
   697  	properties:
   698  	[
   699  		new web3._extend.Property({
   700  			name: 'content',
   701  			getter: 'txpool_content'
   702  		}),
   703  		new web3._extend.Property({
   704  			name: 'inspect',
   705  			getter: 'txpool_inspect'
   706  		}),
   707  		new web3._extend.Property({
   708  			name: 'status',
   709  			getter: 'txpool_status',
   710  			outputFormatter: function(status) {
   711  				status.pending = web3._extend.utils.toDecimal(status.pending);
   712  				status.queued = web3._extend.utils.toDecimal(status.queued);
   713  				return status;
   714  			}
   715  		}),
   716  	]
   717  });
   718  `
   719  
   720  const AccountingJs = `
   721  web3._extend({
   722  	property: 'accounting',
   723  	methods: [
   724  		new web3._extend.Property({
   725  			name: 'balance',
   726  			getter: 'account_balance'
   727  		}),
   728  		new web3._extend.Property({
   729  			name: 'balanceCredit',
   730  			getter: 'account_balanceCredit'
   731  		}),
   732  		new web3._extend.Property({
   733  			name: 'balanceDebit',
   734  			getter: 'account_balanceDebit'
   735  		}),
   736  		new web3._extend.Property({
   737  			name: 'bytesCredit',
   738  			getter: 'account_bytesCredit'
   739  		}),
   740  		new web3._extend.Property({
   741  			name: 'bytesDebit',
   742  			getter: 'account_bytesDebit'
   743  		}),
   744  		new web3._extend.Property({
   745  			name: 'msgCredit',
   746  			getter: 'account_msgCredit'
   747  		}),
   748  		new web3._extend.Property({
   749  			name: 'msgDebit',
   750  			getter: 'account_msgDebit'
   751  		}),
   752  		new web3._extend.Property({
   753  			name: 'peerDrops',
   754  			getter: 'account_peerDrops'
   755  		}),
   756  		new web3._extend.Property({
   757  			name: 'selfDrops',
   758  			getter: 'account_selfDrops'
   759  		}),
   760  	]
   761  });
   762  `