github.com/oskarth/go-ethereum@v1.6.8-0.20191013093314-dac24a9d3494/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: 'traceBadBlock',
   383  			call: 'debug_traceBadBlock',
   384  			params: 1,
   385  			inputFormatter: [null]
   386  		}),
   387  		new web3._extend.Method({
   388  			name: 'traceBlockByNumber',
   389  			call: 'debug_traceBlockByNumber',
   390  			params: 2,
   391  			inputFormatter: [null, null]
   392  		}),
   393  		new web3._extend.Method({
   394  			name: 'traceBlockByHash',
   395  			call: 'debug_traceBlockByHash',
   396  			params: 2,
   397  			inputFormatter: [null, null]
   398  		}),
   399  		new web3._extend.Method({
   400  			name: 'traceTransaction',
   401  			call: 'debug_traceTransaction',
   402  			params: 2,
   403  			inputFormatter: [null, null]
   404  		}),
   405  		new web3._extend.Method({
   406  			name: 'preimage',
   407  			call: 'debug_preimage',
   408  			params: 1,
   409  			inputFormatter: [null]
   410  		}),
   411  		new web3._extend.Method({
   412  			name: 'getBadBlocks',
   413  			call: 'debug_getBadBlocks',
   414  			params: 0,
   415  		}),
   416  		new web3._extend.Method({
   417  			name: 'storageRangeAt',
   418  			call: 'debug_storageRangeAt',
   419  			params: 5,
   420  		}),
   421  		new web3._extend.Method({
   422  			name: 'getModifiedAccountsByNumber',
   423  			call: 'debug_getModifiedAccountsByNumber',
   424  			params: 2,
   425  			inputFormatter: [null, null],
   426  		}),
   427  		new web3._extend.Method({
   428  			name: 'getModifiedAccountsByHash',
   429  			call: 'debug_getModifiedAccountsByHash',
   430  			params: 2,
   431  			inputFormatter:[null, null],
   432  		}),
   433  	],
   434  	properties: []
   435  });
   436  `
   437  
   438  const Eth_JS = `
   439  web3._extend({
   440  	property: 'eth',
   441  	methods: [
   442  		new web3._extend.Method({
   443  			name: 'chainId',
   444  			call: 'eth_chainId',
   445  			params: 0
   446  		}),
   447  		new web3._extend.Method({
   448  			name: 'sign',
   449  			call: 'eth_sign',
   450  			params: 2,
   451  			inputFormatter: [web3._extend.formatters.inputAddressFormatter, null]
   452  		}),
   453  		new web3._extend.Method({
   454  			name: 'resend',
   455  			call: 'eth_resend',
   456  			params: 3,
   457  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
   458  		}),
   459  		new web3._extend.Method({
   460  			name: 'signTransaction',
   461  			call: 'eth_signTransaction',
   462  			params: 1,
   463  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   464  		}),
   465  		new web3._extend.Method({
   466  			name: 'submitTransaction',
   467  			call: 'eth_submitTransaction',
   468  			params: 1,
   469  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   470  		}),
   471  		new web3._extend.Method({
   472  			name: 'getRawTransaction',
   473  			call: 'eth_getRawTransactionByHash',
   474  			params: 1
   475  		}),
   476  		new web3._extend.Method({
   477  			name: 'getRawTransactionFromBlock',
   478  			call: function(args) {
   479  				return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex';
   480  			},
   481  			params: 2,
   482  			inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex]
   483  		}),
   484  	],
   485  	properties: [
   486  		new web3._extend.Property({
   487  			name: 'pendingTransactions',
   488  			getter: 'eth_pendingTransactions',
   489  			outputFormatter: function(txs) {
   490  				var formatted = [];
   491  				for (var i = 0; i < txs.length; i++) {
   492  					formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i]));
   493  					formatted[i].blockHash = null;
   494  				}
   495  				return formatted;
   496  			}
   497  		}),
   498  	]
   499  });
   500  `
   501  
   502  const Miner_JS = `
   503  web3._extend({
   504  	property: 'miner',
   505  	methods: [
   506  		new web3._extend.Method({
   507  			name: 'start',
   508  			call: 'miner_start',
   509  			params: 1,
   510  			inputFormatter: [null]
   511  		}),
   512  		new web3._extend.Method({
   513  			name: 'stop',
   514  			call: 'miner_stop'
   515  		}),
   516  		new web3._extend.Method({
   517  			name: 'setEtherbase',
   518  			call: 'miner_setEtherbase',
   519  			params: 1,
   520  			inputFormatter: [web3._extend.formatters.inputAddressFormatter]
   521  		}),
   522  		new web3._extend.Method({
   523  			name: 'setExtra',
   524  			call: 'miner_setExtra',
   525  			params: 1
   526  		}),
   527  		new web3._extend.Method({
   528  			name: 'setGasPrice',
   529  			call: 'miner_setGasPrice',
   530  			params: 1,
   531  			inputFormatter: [web3._extend.utils.fromDecimal]
   532  		}),
   533  		new web3._extend.Method({
   534  			name: 'setRecommitInterval',
   535  			call: 'miner_setRecommitInterval',
   536  			params: 1,
   537  		}),
   538  		new web3._extend.Method({
   539  			name: 'getHashrate',
   540  			call: 'miner_getHashrate'
   541  		}),
   542  	],
   543  	properties: []
   544  });
   545  `
   546  
   547  const Net_JS = `
   548  web3._extend({
   549  	property: 'net',
   550  	methods: [],
   551  	properties: [
   552  		new web3._extend.Property({
   553  			name: 'version',
   554  			getter: 'net_version'
   555  		}),
   556  	]
   557  });
   558  `
   559  
   560  const Personal_JS = `
   561  web3._extend({
   562  	property: 'personal',
   563  	methods: [
   564  		new web3._extend.Method({
   565  			name: 'importRawKey',
   566  			call: 'personal_importRawKey',
   567  			params: 2
   568  		}),
   569  		new web3._extend.Method({
   570  			name: 'sign',
   571  			call: 'personal_sign',
   572  			params: 3,
   573  			inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null]
   574  		}),
   575  		new web3._extend.Method({
   576  			name: 'ecRecover',
   577  			call: 'personal_ecRecover',
   578  			params: 2
   579  		}),
   580  		new web3._extend.Method({
   581  			name: 'openWallet',
   582  			call: 'personal_openWallet',
   583  			params: 2
   584  		}),
   585  		new web3._extend.Method({
   586  			name: 'deriveAccount',
   587  			call: 'personal_deriveAccount',
   588  			params: 3
   589  		}),
   590  		new web3._extend.Method({
   591  			name: 'signTransaction',
   592  			call: 'personal_signTransaction',
   593  			params: 2,
   594  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null]
   595  		}),
   596  	],
   597  	properties: [
   598  		new web3._extend.Property({
   599  			name: 'listWallets',
   600  			getter: 'personal_listWallets'
   601  		}),
   602  	]
   603  })
   604  `
   605  
   606  const RPC_JS = `
   607  web3._extend({
   608  	property: 'rpc',
   609  	methods: [],
   610  	properties: [
   611  		new web3._extend.Property({
   612  			name: 'modules',
   613  			getter: 'rpc_modules'
   614  		}),
   615  	]
   616  });
   617  `
   618  
   619  const Shh_JS = `
   620  web3._extend({
   621  	property: 'shh',
   622  	methods: [
   623  	],
   624  	properties:
   625  	[
   626  		new web3._extend.Property({
   627  			name: 'version',
   628  			getter: 'shh_version',
   629  			outputFormatter: web3._extend.utils.toDecimal
   630  		}),
   631  		new web3._extend.Property({
   632  			name: 'info',
   633  			getter: 'shh_info'
   634  		}),
   635  	]
   636  });
   637  `
   638  
   639  const SWARMFS_JS = `
   640  web3._extend({
   641  	property: 'swarmfs',
   642  	methods:
   643  	[
   644  		new web3._extend.Method({
   645  			name: 'mount',
   646  			call: 'swarmfs_mount',
   647  			params: 2
   648  		}),
   649  		new web3._extend.Method({
   650  			name: 'unmount',
   651  			call: 'swarmfs_unmount',
   652  			params: 1
   653  		}),
   654  		new web3._extend.Method({
   655  			name: 'listmounts',
   656  			call: 'swarmfs_listmounts',
   657  			params: 0
   658  		}),
   659  	]
   660  });
   661  `
   662  
   663  const TxPool_JS = `
   664  web3._extend({
   665  	property: 'txpool',
   666  	methods: [],
   667  	properties:
   668  	[
   669  		new web3._extend.Property({
   670  			name: 'content',
   671  			getter: 'txpool_content'
   672  		}),
   673  		new web3._extend.Property({
   674  			name: 'inspect',
   675  			getter: 'txpool_inspect'
   676  		}),
   677  		new web3._extend.Property({
   678  			name: 'status',
   679  			getter: 'txpool_status',
   680  			outputFormatter: function(status) {
   681  				status.pending = web3._extend.utils.toDecimal(status.pending);
   682  				status.queued = web3._extend.utils.toDecimal(status.queued);
   683  				return status;
   684  			}
   685  		}),
   686  	]
   687  });
   688  `