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