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