github.com/avence12/go-ethereum@v1.5.10-0.20170320123548-1dfd65f6d047/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  	"debug":      Debug_JS,
    24  	"eth":        Eth_JS,
    25  	"miner":      Miner_JS,
    26  	"net":        Net_JS,
    27  	"personal":   Personal_JS,
    28  	"rpc":        RPC_JS,
    29  	"shh":        Shh_JS,
    30  	"txpool":     TxPool_JS,
    31  }
    32  
    33  const Chequebook_JS = `
    34  web3._extend({
    35    property: 'chequebook',
    36    methods:
    37    [
    38      new web3._extend.Method({
    39        name: 'deposit',
    40        call: 'chequebook_deposit',
    41        params: 1,
    42        inputFormatter: [null]
    43      }),
    44      new web3._extend.Property({
    45  			name: 'balance',
    46  			getter: 'chequebook_balance',
    47  				outputFormatter: web3._extend.utils.toDecimal
    48  		}),
    49      new web3._extend.Method({
    50        name: 'cash',
    51        call: 'chequebook_cash',
    52        params: 1,
    53        inputFormatter: [null]
    54      }),
    55      new web3._extend.Method({
    56        name: 'issue',
    57        call: 'chequebook_issue',
    58        params: 2,
    59        inputFormatter: [null, null]
    60      }),
    61    ]
    62  });
    63  `
    64  
    65  const Admin_JS = `
    66  web3._extend({
    67  	property: 'admin',
    68  	methods:
    69  	[
    70  		new web3._extend.Method({
    71  			name: 'addPeer',
    72  			call: 'admin_addPeer',
    73  			params: 1
    74  		}),
    75  		new web3._extend.Method({
    76  			name: 'removePeer',
    77  			call: 'admin_removePeer',
    78  			params: 1
    79  		}),
    80  		new web3._extend.Method({
    81  			name: 'exportChain',
    82  			call: 'admin_exportChain',
    83  			params: 1,
    84  			inputFormatter: [null]
    85  		}),
    86  		new web3._extend.Method({
    87  			name: 'importChain',
    88  			call: 'admin_importChain',
    89  			params: 1
    90  		}),
    91  		new web3._extend.Method({
    92  			name: 'sleepBlocks',
    93  			call: 'admin_sleepBlocks',
    94  			params: 2
    95  		}),
    96  		new web3._extend.Method({
    97  			name: 'setSolc',
    98  			call: 'admin_setSolc',
    99  			params: 1
   100  		}),
   101  		new web3._extend.Method({
   102  			name: 'startRPC',
   103  			call: 'admin_startRPC',
   104  			params: 4,
   105  			inputFormatter: [null, null, null, null]
   106  		}),
   107  		new web3._extend.Method({
   108  			name: 'stopRPC',
   109  			call: 'admin_stopRPC'
   110  		}),
   111  		new web3._extend.Method({
   112  			name: 'startWS',
   113  			call: 'admin_startWS',
   114  			params: 4,
   115  			inputFormatter: [null, null, null, null]
   116  		}),
   117  		new web3._extend.Method({
   118  			name: 'stopWS',
   119  			call: 'admin_stopWS'
   120  		})
   121  	],
   122  	properties:
   123  	[
   124  		new web3._extend.Property({
   125  			name: 'nodeInfo',
   126  			getter: 'admin_nodeInfo'
   127  		}),
   128  		new web3._extend.Property({
   129  			name: 'peers',
   130  			getter: 'admin_peers'
   131  		}),
   132  		new web3._extend.Property({
   133  			name: 'datadir',
   134  			getter: 'admin_datadir'
   135  		})
   136  	]
   137  });
   138  `
   139  
   140  const Debug_JS = `
   141  web3._extend({
   142  	property: 'debug',
   143  	methods:
   144  	[
   145  		new web3._extend.Method({
   146  			name: 'printBlock',
   147  			call: 'debug_printBlock',
   148  			params: 1
   149  		}),
   150  		new web3._extend.Method({
   151  			name: 'getBlockRlp',
   152  			call: 'debug_getBlockRlp',
   153  			params: 1
   154  		}),
   155  		new web3._extend.Method({
   156  			name: 'setHead',
   157  			call: 'debug_setHead',
   158  			params: 1
   159  		}),
   160  		new web3._extend.Method({
   161  			name: 'traceBlock',
   162  			call: 'debug_traceBlock',
   163  			params: 1
   164  		}),
   165  		new web3._extend.Method({
   166  			name: 'traceBlockByFile',
   167  			call: 'debug_traceBlockByFile',
   168  			params: 1
   169  		}),
   170  		new web3._extend.Method({
   171  			name: 'traceBlockByNumber',
   172  			call: 'debug_traceBlockByNumber',
   173  			params: 1
   174  		}),
   175  		new web3._extend.Method({
   176  			name: 'traceBlockByHash',
   177  			call: 'debug_traceBlockByHash',
   178  			params: 1
   179  		}),
   180  		new web3._extend.Method({
   181  			name: 'seedHash',
   182  			call: 'debug_seedHash',
   183  			params: 1
   184  		}),
   185  		new web3._extend.Method({
   186  			name: 'dumpBlock',
   187  			call: 'debug_dumpBlock',
   188  			params: 1
   189  		}),
   190  		new web3._extend.Method({
   191  			name: 'chaindbProperty',
   192  			call: 'debug_chaindbProperty',
   193  			params: 1,
   194  			outputFormatter: console.log
   195  		}),
   196  		new web3._extend.Method({
   197  			name: 'chaindbCompact',
   198  			call: 'debug_chaindbCompact',
   199  		}),
   200  		new web3._extend.Method({
   201  			name: 'metrics',
   202  			call: 'debug_metrics',
   203  			params: 1
   204  		}),
   205  		new web3._extend.Method({
   206  			name: 'verbosity',
   207  			call: 'debug_verbosity',
   208  			params: 1
   209  		}),
   210  		new web3._extend.Method({
   211  			name: 'vmodule',
   212  			call: 'debug_vmodule',
   213  			params: 1
   214  		}),
   215  		new web3._extend.Method({
   216  			name: 'backtraceAt',
   217  			call: 'debug_backtraceAt',
   218  			params: 1,
   219  		}),
   220  		new web3._extend.Method({
   221  			name: 'stacks',
   222  			call: 'debug_stacks',
   223  			params: 0,
   224  			outputFormatter: console.log
   225  		}),
   226  		new web3._extend.Method({
   227  			name: 'memStats',
   228  			call: 'debug_memStats',
   229  			params: 0,
   230  		}),
   231  		new web3._extend.Method({
   232  			name: 'gcStats',
   233  			call: 'debug_gcStats',
   234  			params: 0,
   235  		}),
   236  		new web3._extend.Method({
   237  			name: 'cpuProfile',
   238  			call: 'debug_cpuProfile',
   239  			params: 2
   240  		}),
   241  		new web3._extend.Method({
   242  			name: 'startCPUProfile',
   243  			call: 'debug_startCPUProfile',
   244  			params: 1
   245  		}),
   246  		new web3._extend.Method({
   247  			name: 'stopCPUProfile',
   248  			call: 'debug_stopCPUProfile',
   249  			params: 0
   250  		}),
   251  		new web3._extend.Method({
   252  			name: 'goTrace',
   253  			call: 'debug_goTrace',
   254  			params: 2
   255  		}),
   256  		new web3._extend.Method({
   257  			name: 'startGoTrace',
   258  			call: 'debug_startGoTrace',
   259  			params: 1
   260  		}),
   261  		new web3._extend.Method({
   262  			name: 'stopGoTrace',
   263  			call: 'debug_stopGoTrace',
   264  			params: 0
   265  		}),
   266  		new web3._extend.Method({
   267  			name: 'blockProfile',
   268  			call: 'debug_blockProfile',
   269  			params: 2
   270  		}),
   271  		new web3._extend.Method({
   272  			name: 'setBlockProfileRate',
   273  			call: 'debug_setBlockProfileRate',
   274  			params: 1
   275  		}),
   276  		new web3._extend.Method({
   277  			name: 'writeBlockProfile',
   278  			call: 'debug_writeBlockProfile',
   279  			params: 1
   280  		}),
   281  		new web3._extend.Method({
   282  			name: 'writeMemProfile',
   283  			call: 'debug_writeMemProfile',
   284  			params: 1
   285  		}),
   286  		new web3._extend.Method({
   287  			name: 'traceTransaction',
   288  			call: 'debug_traceTransaction',
   289  			params: 2,
   290  			inputFormatter: [null, null]
   291  		}),
   292  		new web3._extend.Method({
   293  			name: 'preimage',
   294  			call: 'debug_preimage',
   295  			params: 1,
   296  			inputFormatter: [null]
   297  		}),
   298  		new web3._extend.Method({
   299  			name: 'getBadBlocks',
   300  			call: 'debug_getBadBlocks',
   301  			params: 0,
   302  		}),
   303  	],
   304  	properties: []
   305  });
   306  `
   307  
   308  const Eth_JS = `
   309  web3._extend({
   310  	property: 'eth',
   311  	methods:
   312  	[
   313  		new web3._extend.Method({
   314  			name: 'sign',
   315  			call: 'eth_sign',
   316  			params: 2,
   317  			inputFormatter: [web3._extend.formatters.inputAddressFormatter, null]
   318  		}),
   319  		new web3._extend.Method({
   320  			name: 'resend',
   321  			call: 'eth_resend',
   322  			params: 3,
   323  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
   324  		}),
   325  		new web3._extend.Method({
   326  			name: 'signTransaction',
   327  			call: 'eth_signTransaction',
   328  			params: 1,
   329  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   330  		}),
   331  		new web3._extend.Method({
   332  			name: 'submitTransaction',
   333  			call: 'eth_submitTransaction',
   334  			params: 1,
   335  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   336  		}),
   337  		new web3._extend.Method({
   338  			name: 'getRawTransaction',
   339  			call: 'eth_getRawTransactionByHash',
   340  			params: 1
   341  		}),
   342  		new web3._extend.Method({
   343  			name: 'getRawTransactionFromBlock',
   344  			call: function(args) {
   345  				return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex';
   346  			},
   347  			params: 2,
   348  			inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex]
   349  		})
   350  	],
   351  	properties:
   352  	[
   353  		new web3._extend.Property({
   354  			name: 'pendingTransactions',
   355  			getter: 'eth_pendingTransactions',
   356  			outputFormatter: function(txs) {
   357  				var formatted = [];
   358  				for (var i = 0; i < txs.length; i++) {
   359  					formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i]));
   360  					formatted[i].blockHash = null;
   361  				}
   362  				return formatted;
   363  			}
   364  		})
   365  	]
   366  });
   367  `
   368  
   369  const Miner_JS = `
   370  web3._extend({
   371  	property: 'miner',
   372  	methods:
   373  	[
   374  		new web3._extend.Method({
   375  			name: 'start',
   376  			call: 'miner_start',
   377  			params: 1,
   378  			inputFormatter: [null]
   379  		}),
   380  		new web3._extend.Method({
   381  			name: 'stop',
   382  			call: 'miner_stop'
   383  		}),
   384  		new web3._extend.Method({
   385  			name: 'setEtherbase',
   386  			call: 'miner_setEtherbase',
   387  			params: 1,
   388  			inputFormatter: [web3._extend.formatters.inputAddressFormatter]
   389  		}),
   390  		new web3._extend.Method({
   391  			name: 'setExtra',
   392  			call: 'miner_setExtra',
   393  			params: 1
   394  		}),
   395  		new web3._extend.Method({
   396  			name: 'setGasPrice',
   397  			call: 'miner_setGasPrice',
   398  			params: 1,
   399  			inputFormatter: [web3._extend.utils.fromDecimal]
   400  		}),
   401  		new web3._extend.Method({
   402  			name: 'getHashrate',
   403  			call: 'miner_getHashrate'
   404  		})
   405  	],
   406  	properties: []
   407  });
   408  `
   409  
   410  const Net_JS = `
   411  web3._extend({
   412  	property: 'net',
   413  	methods: [],
   414  	properties:
   415  	[
   416  		new web3._extend.Property({
   417  			name: 'version',
   418  			getter: 'net_version'
   419  		})
   420  	]
   421  });
   422  `
   423  
   424  const Personal_JS = `
   425  web3._extend({
   426  	property: 'personal',
   427  	methods:
   428  	[
   429  		new web3._extend.Method({
   430  			name: 'importRawKey',
   431  			call: 'personal_importRawKey',
   432  			params: 2
   433  		}),
   434  		new web3._extend.Method({
   435  			name: 'sign',
   436  			call: 'personal_sign',
   437  			params: 3,
   438  			inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null]
   439  		}),
   440  		new web3._extend.Method({
   441  			name: 'ecRecover',
   442  			call: 'personal_ecRecover',
   443  			params: 2
   444  		}),
   445  		new web3._extend.Method({
   446  			name: 'deriveAccount',
   447  			call: 'personal_deriveAccount',
   448  			params: 3
   449  		})
   450  	],
   451  	properties:
   452  	[
   453  		new web3._extend.Property({
   454  			name: 'listWallets',
   455  			getter: 'personal_listWallets'
   456  		})
   457  	]
   458  })
   459  `
   460  
   461  const RPC_JS = `
   462  web3._extend({
   463  	property: 'rpc',
   464  	methods: [],
   465  	properties:
   466  	[
   467  		new web3._extend.Property({
   468  			name: 'modules',
   469  			getter: 'rpc_modules'
   470  		})
   471  	]
   472  });
   473  `
   474  
   475  const Shh_JS = `
   476  web3._extend({
   477  	property: 'shh',
   478  	methods: [],
   479  	properties:
   480  	[
   481  		new web3._extend.Property({
   482  			name: 'version',
   483  			getter: 'shh_version',
   484  			outputFormatter: web3._extend.utils.toDecimal
   485  		})
   486  	]
   487  });
   488  `
   489  
   490  const TxPool_JS = `
   491  web3._extend({
   492  	property: 'txpool',
   493  	methods: [],
   494  	properties:
   495  	[
   496  		new web3._extend.Property({
   497  			name: 'content',
   498  			getter: 'txpool_content'
   499  		}),
   500  		new web3._extend.Property({
   501  			name: 'inspect',
   502  			getter: 'txpool_inspect'
   503  		}),
   504  		new web3._extend.Property({
   505  			name: 'status',
   506  			getter: 'txpool_status',
   507  			outputFormatter: function(status) {
   508  				status.pending = web3._extend.utils.toDecimal(status.pending);
   509  				status.queued = web3._extend.utils.toDecimal(status.queued);
   510  				return status;
   511  			}
   512  		})
   513  	]
   514  });
   515  `