github.com/digdeepmining/go-atheios@v1.5.13-0.20180902133602-d5687a2e6f43/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 gath 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  	],
   299  	properties: []
   300  });
   301  `
   302  
   303  const Eth_JS = `
   304  web3._extend({
   305  	property: 'eth',
   306  	methods:
   307  	[
   308  		new web3._extend.Method({
   309  			name: 'sign',
   310  			call: 'eth_sign',
   311  			params: 2,
   312  			inputFormatter: [web3._extend.formatters.inputAddressFormatter, null]
   313  		}),
   314  		new web3._extend.Method({
   315  			name: 'resend',
   316  			call: 'eth_resend',
   317  			params: 3,
   318  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
   319  		}),
   320  		new web3._extend.Method({
   321  			name: 'signTransaction',
   322  			call: 'eth_signTransaction',
   323  			params: 1,
   324  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   325  		}),
   326  		new web3._extend.Method({
   327  			name: 'submitTransaction',
   328  			call: 'eth_submitTransaction',
   329  			params: 1,
   330  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   331  		}),
   332  		new web3._extend.Method({
   333  			name: 'getRawTransaction',
   334  			call: 'eth_getRawTransactionByHash',
   335  			params: 1
   336  		}),
   337  		new web3._extend.Method({
   338  			name: 'getRawTransactionFromBlock',
   339  			call: function(args) {
   340  				return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex';
   341  			},
   342  			params: 2,
   343  			inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex]
   344  		})
   345  	],
   346  	properties:
   347  	[
   348  		new web3._extend.Property({
   349  			name: 'pendingTransactions',
   350  			getter: 'eth_pendingTransactions',
   351  			outputFormatter: function(txs) {
   352  				var formatted = [];
   353  				for (var i = 0; i < txs.length; i++) {
   354  					formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i]));
   355  					formatted[i].blockHash = null;
   356  				}
   357  				return formatted;
   358  			}
   359  		})
   360  	]
   361  });
   362  `
   363  
   364  const Miner_JS = `
   365  web3._extend({
   366  	property: 'miner',
   367  	methods:
   368  	[
   369  		new web3._extend.Method({
   370  			name: 'start',
   371  			call: 'miner_start',
   372  			params: 1,
   373  			inputFormatter: [null]
   374  		}),
   375  		new web3._extend.Method({
   376  			name: 'stop',
   377  			call: 'miner_stop'
   378  		}),
   379  		new web3._extend.Method({
   380  			name: 'setEtherbase',
   381  			call: 'miner_setEtherbase',
   382  			params: 1,
   383  			inputFormatter: [web3._extend.formatters.inputAddressFormatter]
   384  		}),
   385  		new web3._extend.Method({
   386  			name: 'setExtra',
   387  			call: 'miner_setExtra',
   388  			params: 1
   389  		}),
   390  		new web3._extend.Method({
   391  			name: 'setGasPrice',
   392  			call: 'miner_setGasPrice',
   393  			params: 1,
   394  			inputFormatter: [web3._extend.utils.fromDecimal]
   395  		}),
   396  		new web3._extend.Method({
   397  			name: 'startAutoDAG',
   398  			call: 'miner_startAutoDAG',
   399  			params: 0
   400  		}),
   401  		new web3._extend.Method({
   402  			name: 'stopAutoDAG',
   403  			call: 'miner_stopAutoDAG',
   404  			params: 0
   405  		}),
   406  		new web3._extend.Method({
   407  			name: 'makeDAG',
   408  			call: 'miner_makeDAG',
   409  			params: 1,
   410  			inputFormatter: [web3._extend.formatters.inputDefaultBlockNumberFormatter]
   411  		})
   412  	],
   413  	properties: []
   414  });
   415  `
   416  
   417  const Net_JS = `
   418  web3._extend({
   419  	property: 'net',
   420  	methods: [],
   421  	properties:
   422  	[
   423  		new web3._extend.Property({
   424  			name: 'version',
   425  			getter: 'net_version'
   426  		})
   427  	]
   428  });
   429  `
   430  
   431  const Personal_JS = `
   432  web3._extend({
   433  	property: 'personal',
   434  	methods:
   435  	[
   436  		new web3._extend.Method({
   437  			name: 'importRawKey',
   438  			call: 'personal_importRawKey',
   439  			params: 2
   440  		}),
   441  		new web3._extend.Method({
   442  			name: 'sign',
   443  			call: 'personal_sign',
   444  			params: 3,
   445  			inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null]
   446  		}),
   447  		new web3._extend.Method({
   448  			name: 'ecRecover',
   449  			call: 'personal_ecRecover',
   450  			params: 2
   451  		}),
   452  		new web3._extend.Method({
   453  			name: 'deriveAccount',
   454  			call: 'personal_deriveAccount',
   455  			params: 3
   456  		})
   457  	],
   458  	properties:
   459  	[
   460  		new web3._extend.Property({
   461  			name: 'listWallets',
   462  			getter: 'personal_listWallets'
   463  		})
   464  	]
   465  })
   466  `
   467  
   468  const RPC_JS = `
   469  web3._extend({
   470  	property: 'rpc',
   471  	methods: [],
   472  	properties:
   473  	[
   474  		new web3._extend.Property({
   475  			name: 'modules',
   476  			getter: 'rpc_modules'
   477  		})
   478  	]
   479  });
   480  `
   481  
   482  const Shh_JS = `
   483  web3._extend({
   484  	property: 'shh',
   485  	methods: [],
   486  	properties:
   487  	[
   488  		new web3._extend.Property({
   489  			name: 'version',
   490  			getter: 'shh_version',
   491  			outputFormatter: web3._extend.utils.toDecimal
   492  		})
   493  	]
   494  });
   495  `
   496  
   497  const TxPool_JS = `
   498  web3._extend({
   499  	property: 'txpool',
   500  	methods: [],
   501  	properties:
   502  	[
   503  		new web3._extend.Property({
   504  			name: 'content',
   505  			getter: 'txpool_content'
   506  		}),
   507  		new web3._extend.Property({
   508  			name: 'inspect',
   509  			getter: 'txpool_inspect'
   510  		}),
   511  		new web3._extend.Property({
   512  			name: 'status',
   513  			getter: 'txpool_status',
   514  			outputFormatter: function(status) {
   515  				status.pending = web3._extend.utils.toDecimal(status.pending);
   516  				status.queued = web3._extend.utils.toDecimal(status.queued);
   517  				return status;
   518  			}
   519  		})
   520  	]
   521  });
   522  `