github.com/FinTechToken/go-ethereum@v1.8.4-0.20190621030324-0b02bfba9171/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": Accounting_JS,
    22  	"admin":      Admin_JS,
    23  	"chequebook": Chequebook_JS,
    24  	"clique":     Clique_JS,
    25  	"ethash":     Ethash_JS,
    26  	"debug":      Debug_JS,
    27  	"eth":        Eth_JS,
    28  	"miner":      Miner_JS,
    29  	"net":        Net_JS,
    30  	"personal":   Personal_JS,
    31  	"rpc":        RPC_JS,
    32  	"shh":        Shh_JS,
    33  	"swarmfs":    SWARMFS_JS,
    34  	"txpool":     TxPool_JS,
    35  }
    36  
    37  const Chequebook_JS = `
    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 Clique_JS = `
    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 Ethash_JS = `
   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 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: '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  		new web3._extend.Method({
   203  			name: 'exec',
   204  			call: 'admin_exec',
   205  			params: 1
   206  		})
   207  	],
   208  	properties: [
   209  		new web3._extend.Property({
   210  			name: 'nodeInfo',
   211  			getter: 'admin_nodeInfo'
   212  		}),
   213  		new web3._extend.Property({
   214  			name: 'peers',
   215  			getter: 'admin_peers'
   216  		}),
   217  		new web3._extend.Property({
   218  			name: 'datadir',
   219  			getter: 'admin_datadir'
   220  		}),
   221  	]
   222  });
   223  `
   224  
   225  const Debug_JS = `
   226  web3._extend({
   227  	property: 'debug',
   228  	methods: [
   229  		new web3._extend.Method({
   230  			name: 'printBlock',
   231  			call: 'debug_printBlock',
   232  			params: 1
   233  		}),
   234  		new web3._extend.Method({
   235  			name: 'getBlockRlp',
   236  			call: 'debug_getBlockRlp',
   237  			params: 1
   238  		}),
   239  		new web3._extend.Method({
   240  			name: 'setHead',
   241  			call: 'debug_setHead',
   242  			params: 1
   243  		}),
   244  		new web3._extend.Method({
   245  			name: 'seedHash',
   246  			call: 'debug_seedHash',
   247  			params: 1
   248  		}),
   249  		new web3._extend.Method({
   250  			name: 'dumpBlock',
   251  			call: 'debug_dumpBlock',
   252  			params: 1
   253  		}),
   254  		new web3._extend.Method({
   255  			name: 'chaindbProperty',
   256  			call: 'debug_chaindbProperty',
   257  			params: 1,
   258  			outputFormatter: console.log
   259  		}),
   260  		new web3._extend.Method({
   261  			name: 'chaindbCompact',
   262  			call: 'debug_chaindbCompact',
   263  		}),
   264  		new web3._extend.Method({
   265  			name: 'metrics',
   266  			call: 'debug_metrics',
   267  			params: 1
   268  		}),
   269  		new web3._extend.Method({
   270  			name: 'verbosity',
   271  			call: 'debug_verbosity',
   272  			params: 1
   273  		}),
   274  		new web3._extend.Method({
   275  			name: 'vmodule',
   276  			call: 'debug_vmodule',
   277  			params: 1
   278  		}),
   279  		new web3._extend.Method({
   280  			name: 'backtraceAt',
   281  			call: 'debug_backtraceAt',
   282  			params: 1,
   283  		}),
   284  		new web3._extend.Method({
   285  			name: 'stacks',
   286  			call: 'debug_stacks',
   287  			params: 0,
   288  			outputFormatter: console.log
   289  		}),
   290  		new web3._extend.Method({
   291  			name: 'freeOSMemory',
   292  			call: 'debug_freeOSMemory',
   293  			params: 0,
   294  		}),
   295  		new web3._extend.Method({
   296  			name: 'setGCPercent',
   297  			call: 'debug_setGCPercent',
   298  			params: 1,
   299  		}),
   300  		new web3._extend.Method({
   301  			name: 'memStats',
   302  			call: 'debug_memStats',
   303  			params: 0,
   304  		}),
   305  		new web3._extend.Method({
   306  			name: 'gcStats',
   307  			call: 'debug_gcStats',
   308  			params: 0,
   309  		}),
   310  		new web3._extend.Method({
   311  			name: 'cpuProfile',
   312  			call: 'debug_cpuProfile',
   313  			params: 2
   314  		}),
   315  		new web3._extend.Method({
   316  			name: 'startCPUProfile',
   317  			call: 'debug_startCPUProfile',
   318  			params: 1
   319  		}),
   320  		new web3._extend.Method({
   321  			name: 'stopCPUProfile',
   322  			call: 'debug_stopCPUProfile',
   323  			params: 0
   324  		}),
   325  		new web3._extend.Method({
   326  			name: 'goTrace',
   327  			call: 'debug_goTrace',
   328  			params: 2
   329  		}),
   330  		new web3._extend.Method({
   331  			name: 'startGoTrace',
   332  			call: 'debug_startGoTrace',
   333  			params: 1
   334  		}),
   335  		new web3._extend.Method({
   336  			name: 'stopGoTrace',
   337  			call: 'debug_stopGoTrace',
   338  			params: 0
   339  		}),
   340  		new web3._extend.Method({
   341  			name: 'blockProfile',
   342  			call: 'debug_blockProfile',
   343  			params: 2
   344  		}),
   345  		new web3._extend.Method({
   346  			name: 'setBlockProfileRate',
   347  			call: 'debug_setBlockProfileRate',
   348  			params: 1
   349  		}),
   350  		new web3._extend.Method({
   351  			name: 'writeBlockProfile',
   352  			call: 'debug_writeBlockProfile',
   353  			params: 1
   354  		}),
   355  		new web3._extend.Method({
   356  			name: 'mutexProfile',
   357  			call: 'debug_mutexProfile',
   358  			params: 2
   359  		}),
   360  		new web3._extend.Method({
   361  			name: 'setMutexProfileFraction',
   362  			call: 'debug_setMutexProfileFraction',
   363  			params: 1
   364  		}),
   365  		new web3._extend.Method({
   366  			name: 'writeMutexProfile',
   367  			call: 'debug_writeMutexProfile',
   368  			params: 1
   369  		}),
   370  		new web3._extend.Method({
   371  			name: 'writeMemProfile',
   372  			call: 'debug_writeMemProfile',
   373  			params: 1
   374  		}),
   375  		new web3._extend.Method({
   376  			name: 'traceBlock',
   377  			call: 'debug_traceBlock',
   378  			params: 2,
   379  			inputFormatter: [null, null]
   380  		}),
   381  		new web3._extend.Method({
   382  			name: 'traceBlockFromFile',
   383  			call: 'debug_traceBlockFromFile',
   384  			params: 2,
   385  			inputFormatter: [null, null]
   386  		}),
   387  		new web3._extend.Method({
   388  			name: 'traceBadBlock',
   389  			call: 'debug_traceBadBlock',
   390  			params: 1,
   391  			inputFormatter: [null]
   392  		}),
   393  		new web3._extend.Method({
   394  			name: 'standardTraceBadBlockToFile',
   395  			call: 'debug_standardTraceBadBlockToFile',
   396  			params: 2,
   397  			inputFormatter: [null, null]
   398  		}),
   399  		new web3._extend.Method({
   400  			name: 'standardTraceBlockToFile',
   401  			call: 'debug_standardTraceBlockToFile',
   402  			params: 2,
   403  			inputFormatter: [null, null]
   404  		}),
   405  		new web3._extend.Method({
   406  			name: 'traceBlockByNumber',
   407  			call: 'debug_traceBlockByNumber',
   408  			params: 2,
   409  			inputFormatter: [null, null]
   410  		}),
   411  		new web3._extend.Method({
   412  			name: 'traceBlockByHash',
   413  			call: 'debug_traceBlockByHash',
   414  			params: 2,
   415  			inputFormatter: [null, null]
   416  		}),
   417  		new web3._extend.Method({
   418  			name: 'traceTransaction',
   419  			call: 'debug_traceTransaction',
   420  			params: 2,
   421  			inputFormatter: [null, null]
   422  		}),
   423  		new web3._extend.Method({
   424  			name: 'preimage',
   425  			call: 'debug_preimage',
   426  			params: 1,
   427  			inputFormatter: [null]
   428  		}),
   429  		new web3._extend.Method({
   430  			name: 'getBadBlocks',
   431  			call: 'debug_getBadBlocks',
   432  			params: 0,
   433  		}),
   434  		new web3._extend.Method({
   435  			name: 'storageRangeAt',
   436  			call: 'debug_storageRangeAt',
   437  			params: 5,
   438  		}),
   439  		new web3._extend.Method({
   440  			name: 'getModifiedAccountsByNumber',
   441  			call: 'debug_getModifiedAccountsByNumber',
   442  			params: 2,
   443  			inputFormatter: [null, null],
   444  		}),
   445  		new web3._extend.Method({
   446  			name: 'getModifiedAccountsByHash',
   447  			call: 'debug_getModifiedAccountsByHash',
   448  			params: 2,
   449  			inputFormatter:[null, null],
   450  		}),
   451  	],
   452  	properties: []
   453  });
   454  `
   455  
   456  const Eth_JS = `
   457  web3._extend({
   458  	property: 'eth',
   459  	methods: [
   460  		new web3._extend.Method({
   461  			name: 'chainId',
   462  			call: 'eth_chainId',
   463  			params: 0
   464  		}),
   465  		new web3._extend.Method({
   466  			name: 'sign',
   467  			call: 'eth_sign',
   468  			params: 2,
   469  			inputFormatter: [web3._extend.formatters.inputAddressFormatter, null]
   470  		}),
   471  		new web3._extend.Method({
   472  			name: 'resend',
   473  			call: 'eth_resend',
   474  			params: 3,
   475  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
   476  		}),
   477  		new web3._extend.Method({
   478  			name: 'signTransaction',
   479  			call: 'eth_signTransaction',
   480  			params: 1,
   481  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   482  		}),
   483  		new web3._extend.Method({
   484  			name: 'submitTransaction',
   485  			call: 'eth_submitTransaction',
   486  			params: 1,
   487  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   488  		}),
   489  		new web3._extend.Method({
   490  			name: 'getRawTransaction',
   491  			call: 'eth_getRawTransactionByHash',
   492  			params: 1
   493  		}),
   494  		new web3._extend.Method({
   495  			name: 'getRawTransactionFromBlock',
   496  			call: function(args) {
   497  				return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex';
   498  			},
   499  			params: 2,
   500  			inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex]
   501  		}),
   502  		new web3._extend.Method({
   503  			name: 'getProof',
   504  			call: 'eth_getProof',
   505  			params: 3,
   506  			inputFormatter: [web3._extend.formatters.inputAddressFormatter, null, web3._extend.formatters.inputBlockNumberFormatter]
   507  		}),
   508  	],
   509  	properties: [
   510  		new web3._extend.Property({
   511  			name: 'pendingTransactions',
   512  			getter: 'eth_pendingTransactions',
   513  			outputFormatter: function(txs) {
   514  				var formatted = [];
   515  				for (var i = 0; i < txs.length; i++) {
   516  					formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i]));
   517  					formatted[i].blockHash = null;
   518  				}
   519  				return formatted;
   520  			}
   521  		}),
   522  	]
   523  });
   524  `
   525  
   526  const Miner_JS = `
   527  web3._extend({
   528  	property: 'miner',
   529  	methods: [
   530  		new web3._extend.Method({
   531  			name: 'start',
   532  			call: 'miner_start',
   533  			params: 1,
   534  			inputFormatter: [null]
   535  		}),
   536  		new web3._extend.Method({
   537  			name: 'stop',
   538  			call: 'miner_stop'
   539  		}),
   540  		new web3._extend.Method({
   541  			name: 'setEtherbase',
   542  			call: 'miner_setEtherbase',
   543  			params: 1,
   544  			inputFormatter: [web3._extend.formatters.inputAddressFormatter]
   545  		}),
   546  		new web3._extend.Method({
   547  			name: 'setExtra',
   548  			call: 'miner_setExtra',
   549  			params: 1
   550  		}),
   551  		new web3._extend.Method({
   552  			name: 'setGasPrice',
   553  			call: 'miner_setGasPrice',
   554  			params: 1,
   555  			inputFormatter: [web3._extend.utils.fromDecimal]
   556  		}),
   557  		new web3._extend.Method({
   558  			name: 'setRecommitInterval',
   559  			call: 'miner_setRecommitInterval',
   560  			params: 1,
   561  		}),
   562  		new web3._extend.Method({
   563  			name: 'getHashrate',
   564  			call: 'miner_getHashrate'
   565  		}),
   566  	],
   567  	properties: []
   568  });
   569  `
   570  
   571  const Net_JS = `
   572  web3._extend({
   573  	property: 'net',
   574  	methods: [],
   575  	properties: [
   576  		new web3._extend.Property({
   577  			name: 'version',
   578  			getter: 'net_version'
   579  		}),
   580  	]
   581  });
   582  `
   583  
   584  const Personal_JS = `
   585  web3._extend({
   586  	property: 'personal',
   587  	methods: [
   588  		new web3._extend.Method({
   589  			name: 'importRawKey',
   590  			call: 'personal_importRawKey',
   591  			params: 2
   592  		}),
   593  		new web3._extend.Method({
   594  			name: 'sign',
   595  			call: 'personal_sign',
   596  			params: 3,
   597  			inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null]
   598  		}),
   599  		new web3._extend.Method({
   600  			name: 'ecRecover',
   601  			call: 'personal_ecRecover',
   602  			params: 2
   603  		}),
   604  		new web3._extend.Method({
   605  			name: 'openWallet',
   606  			call: 'personal_openWallet',
   607  			params: 2
   608  		}),
   609  		new web3._extend.Method({
   610  			name: 'deriveAccount',
   611  			call: 'personal_deriveAccount',
   612  			params: 3
   613  		}),
   614  		new web3._extend.Method({
   615  			name: 'signTransaction',
   616  			call: 'personal_signTransaction',
   617  			params: 2,
   618  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null]
   619  		}),
   620  	],
   621  	properties: [
   622  		new web3._extend.Property({
   623  			name: 'listWallets',
   624  			getter: 'personal_listWallets'
   625  		}),
   626  	]
   627  })
   628  `
   629  
   630  const RPC_JS = `
   631  web3._extend({
   632  	property: 'rpc',
   633  	methods: [],
   634  	properties: [
   635  		new web3._extend.Property({
   636  			name: 'modules',
   637  			getter: 'rpc_modules'
   638  		}),
   639  	]
   640  });
   641  `
   642  
   643  const Shh_JS = `
   644  web3._extend({
   645  	property: 'shh',
   646  	methods: [
   647  	],
   648  	properties:
   649  	[
   650  		new web3._extend.Property({
   651  			name: 'version',
   652  			getter: 'shh_version',
   653  			outputFormatter: web3._extend.utils.toDecimal
   654  		}),
   655  		new web3._extend.Property({
   656  			name: 'info',
   657  			getter: 'shh_info'
   658  		}),
   659  	]
   660  });
   661  `
   662  
   663  const SWARMFS_JS = `
   664  web3._extend({
   665  	property: 'swarmfs',
   666  	methods:
   667  	[
   668  		new web3._extend.Method({
   669  			name: 'mount',
   670  			call: 'swarmfs_mount',
   671  			params: 2
   672  		}),
   673  		new web3._extend.Method({
   674  			name: 'unmount',
   675  			call: 'swarmfs_unmount',
   676  			params: 1
   677  		}),
   678  		new web3._extend.Method({
   679  			name: 'listmounts',
   680  			call: 'swarmfs_listmounts',
   681  			params: 0
   682  		}),
   683  	]
   684  });
   685  `
   686  
   687  const TxPool_JS = `
   688  web3._extend({
   689  	property: 'txpool',
   690  	methods: [],
   691  	properties:
   692  	[
   693  		new web3._extend.Property({
   694  			name: 'content',
   695  			getter: 'txpool_content'
   696  		}),
   697  		new web3._extend.Property({
   698  			name: 'inspect',
   699  			getter: 'txpool_inspect'
   700  		}),
   701  		new web3._extend.Property({
   702  			name: 'status',
   703  			getter: 'txpool_status',
   704  			outputFormatter: function(status) {
   705  				status.pending = web3._extend.utils.toDecimal(status.pending);
   706  				status.queued = web3._extend.utils.toDecimal(status.queued);
   707  				return status;
   708  			}
   709  		}),
   710  	]
   711  });
   712  `
   713  
   714  const Accounting_JS = `
   715  web3._extend({
   716  	property: 'accounting',
   717  	methods: [
   718  		new web3._extend.Property({
   719  			name: 'balance',
   720  			getter: 'account_balance'
   721  		}),
   722  		new web3._extend.Property({
   723  			name: 'balanceCredit',
   724  			getter: 'account_balanceCredit'
   725  		}),
   726  		new web3._extend.Property({
   727  			name: 'balanceDebit',
   728  			getter: 'account_balanceDebit'
   729  		}),
   730  		new web3._extend.Property({
   731  			name: 'bytesCredit',
   732  			getter: 'account_bytesCredit'
   733  		}),
   734  		new web3._extend.Property({
   735  			name: 'bytesDebit',
   736  			getter: 'account_bytesDebit'
   737  		}),
   738  		new web3._extend.Property({
   739  			name: 'msgCredit',
   740  			getter: 'account_msgCredit'
   741  		}),
   742  		new web3._extend.Property({
   743  			name: 'msgDebit',
   744  			getter: 'account_msgDebit'
   745  		}),
   746  		new web3._extend.Property({
   747  			name: 'peerDrops',
   748  			getter: 'account_peerDrops'
   749  		}),
   750  		new web3._extend.Property({
   751  			name: 'selfDrops',
   752  			getter: 'account_selfDrops'
   753  		}),
   754  	]
   755  });
   756  `