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