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