github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/internal/web3ext/web3ext.go (about)

     1  
     2  //此源码被清华学神尹成大魔王专业翻译分析并修改
     3  //尹成QQ77025077
     4  //尹成微信18510341407
     5  //尹成所在QQ群721929980
     6  //尹成邮箱 yinc13@mails.tsinghua.edu.cn
     7  //尹成毕业于清华大学,微软区块链领域全球最有价值专家
     8  //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620
     9  //版权所有2015 Go Ethereum作者
    10  //此文件是Go以太坊库的一部分。
    11  //
    12  //Go-Ethereum库是免费软件:您可以重新分发它和/或修改
    13  //根据GNU发布的较低通用公共许可证的条款
    14  //自由软件基金会,或者许可证的第3版,或者
    15  //(由您选择)任何更高版本。
    16  //
    17  //Go以太坊图书馆的发行目的是希望它会有用,
    18  //但没有任何保证;甚至没有
    19  //适销性或特定用途的适用性。见
    20  //GNU较低的通用公共许可证,了解更多详细信息。
    21  //
    22  //你应该收到一份GNU较低级别的公共许可证副本
    23  //以及Go以太坊图书馆。如果没有,请参见<http://www.gnu.org/licenses/>。
    24  
    25  //包web3ext包含geth特定的web3.js扩展。
    26  package web3ext
    27  
    28  var Modules = map[string]string{
    29  	"admin":      Admin_JS,
    30  	"chequebook": Chequebook_JS,
    31  	"clique":     Clique_JS,
    32  	"ethash":     Ethash_JS,
    33  	"debug":      Debug_JS,
    34  	"eth":        Eth_JS,
    35  	"miner":      Miner_JS,
    36  	"net":        Net_JS,
    37  	"personal":   Personal_JS,
    38  	"rpc":        RPC_JS,
    39  	"shh":        Shh_JS,
    40  	"swarmfs":    SWARMFS_JS,
    41  	"txpool":     TxPool_JS,
    42  	"dpos":       Dpos_JS,
    43  }
    44  
    45  const Chequebook_JS = `
    46  web3._extend({
    47  	property: 'chequebook',
    48  	methods: [
    49  		new web3._extend.Method({
    50  			name: 'deposit',
    51  			call: 'chequebook_deposit',
    52  			params: 1,
    53  			inputFormatter: [null]
    54  		}),
    55  		new web3._extend.Property({
    56  			name: 'balance',
    57  			getter: 'chequebook_balance',
    58  			outputFormatter: web3._extend.utils.toDecimal
    59  		}),
    60  		new web3._extend.Method({
    61  			name: 'cash',
    62  			call: 'chequebook_cash',
    63  			params: 1,
    64  			inputFormatter: [null]
    65  		}),
    66  		new web3._extend.Method({
    67  			name: 'issue',
    68  			call: 'chequebook_issue',
    69  			params: 2,
    70  			inputFormatter: [null, null]
    71  		}),
    72  	]
    73  });
    74  `
    75  
    76  const Dpos_JS = `
    77  web3._extend({
    78  	property: 'dpos',
    79  	methods: [
    80  		new web3._extend.Method({
    81  			name: 'getValidators',
    82  			call: 'dpos_getValidators',
    83  			params: 1,
    84  			inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter]
    85  		}),
    86  		new web3._extend.Method({
    87  			name: 'getConfirmedBlockNumber',
    88  			call: 'dpos_getConfirmedBlockNumber',
    89  			params: 0,
    90  			outputFormatter: web3._extend.utils.toBigNumber
    91  		}),
    92  	]
    93  });
    94  `
    95  
    96  const Clique_JS = `
    97  web3._extend({
    98  	property: 'clique',
    99  	methods: [
   100  		new web3._extend.Method({
   101  			name: 'getSnapshot',
   102  			call: 'clique_getSnapshot',
   103  			params: 1,
   104  			inputFormatter: [null]
   105  		}),
   106  		new web3._extend.Method({
   107  			name: 'getSnapshotAtHash',
   108  			call: 'clique_getSnapshotAtHash',
   109  			params: 1
   110  		}),
   111  		new web3._extend.Method({
   112  			name: 'getSigners',
   113  			call: 'clique_getSigners',
   114  			params: 1,
   115  			inputFormatter: [null]
   116  		}),
   117  		new web3._extend.Method({
   118  			name: 'getSignersAtHash',
   119  			call: 'clique_getSignersAtHash',
   120  			params: 1
   121  		}),
   122  		new web3._extend.Method({
   123  			name: 'propose',
   124  			call: 'clique_propose',
   125  			params: 2
   126  		}),
   127  		new web3._extend.Method({
   128  			name: 'discard',
   129  			call: 'clique_discard',
   130  			params: 1
   131  		}),
   132  	],
   133  	properties: [
   134  		new web3._extend.Property({
   135  			name: 'proposals',
   136  			getter: 'clique_proposals'
   137  		}),
   138  	]
   139  });
   140  `
   141  
   142  const Ethash_JS = `
   143  web3._extend({
   144  	property: 'ethash',
   145  	methods: [
   146  		new web3._extend.Method({
   147  			name: 'getWork',
   148  			call: 'ethash_getWork',
   149  			params: 0
   150  		}),
   151  		new web3._extend.Method({
   152  			name: 'getHashrate',
   153  			call: 'ethash_getHashrate',
   154  			params: 0
   155  		}),
   156  		new web3._extend.Method({
   157  			name: 'submitWork',
   158  			call: 'ethash_submitWork',
   159  			params: 3,
   160  		}),
   161  		new web3._extend.Method({
   162  			name: 'submitHashRate',
   163  			call: 'ethash_submitHashRate',
   164  			params: 2,
   165  		}),
   166  	]
   167  });
   168  `
   169  
   170  const Admin_JS = `
   171  web3._extend({
   172  	property: 'admin',
   173  	methods: [
   174  		new web3._extend.Method({
   175  			name: 'addPeer',
   176  			call: 'admin_addPeer',
   177  			params: 1
   178  		}),
   179  		new web3._extend.Method({
   180  			name: 'removePeer',
   181  			call: 'admin_removePeer',
   182  			params: 1
   183  		}),
   184  		new web3._extend.Method({
   185  			name: 'addTrustedPeer',
   186  			call: 'admin_addTrustedPeer',
   187  			params: 1
   188  		}),
   189  		new web3._extend.Method({
   190  			name: 'removeTrustedPeer',
   191  			call: 'admin_removeTrustedPeer',
   192  			params: 1
   193  		}),
   194  		new web3._extend.Method({
   195  			name: 'exportChain',
   196  			call: 'admin_exportChain',
   197  			params: 1,
   198  			inputFormatter: [null]
   199  		}),
   200  		new web3._extend.Method({
   201  			name: 'importChain',
   202  			call: 'admin_importChain',
   203  			params: 1
   204  		}),
   205  		new web3._extend.Method({
   206  			name: 'sleepBlocks',
   207  			call: 'admin_sleepBlocks',
   208  			params: 2
   209  		}),
   210  		new web3._extend.Method({
   211  			name: 'startRPC',
   212  			call: 'admin_startRPC',
   213  			params: 4,
   214  			inputFormatter: [null, null, null, null]
   215  		}),
   216  		new web3._extend.Method({
   217  			name: 'stopRPC',
   218  			call: 'admin_stopRPC'
   219  		}),
   220  		new web3._extend.Method({
   221  			name: 'startWS',
   222  			call: 'admin_startWS',
   223  			params: 4,
   224  			inputFormatter: [null, null, null, null]
   225  		}),
   226  		new web3._extend.Method({
   227  			name: 'stopWS',
   228  			call: 'admin_stopWS'
   229  		}),
   230  	],
   231  	properties: [
   232  		new web3._extend.Property({
   233  			name: 'nodeInfo',
   234  			getter: 'admin_nodeInfo'
   235  		}),
   236  		new web3._extend.Property({
   237  			name: 'peers',
   238  			getter: 'admin_peers'
   239  		}),
   240  		new web3._extend.Property({
   241  			name: 'datadir',
   242  			getter: 'admin_datadir'
   243  		}),
   244  	]
   245  });
   246  `
   247  
   248  const Debug_JS = `
   249  web3._extend({
   250  	property: 'debug',
   251  	methods: [
   252  		new web3._extend.Method({
   253  			name: 'printBlock',
   254  			call: 'debug_printBlock',
   255  			params: 1
   256  		}),
   257  		new web3._extend.Method({
   258  			name: 'getBlockRlp',
   259  			call: 'debug_getBlockRlp',
   260  			params: 1
   261  		}),
   262  		new web3._extend.Method({
   263  			name: 'setHead',
   264  			call: 'debug_setHead',
   265  			params: 1
   266  		}),
   267  		new web3._extend.Method({
   268  			name: 'seedHash',
   269  			call: 'debug_seedHash',
   270  			params: 1
   271  		}),
   272  		new web3._extend.Method({
   273  			name: 'dumpBlock',
   274  			call: 'debug_dumpBlock',
   275  			params: 1
   276  		}),
   277  		new web3._extend.Method({
   278  			name: 'chaindbProperty',
   279  			call: 'debug_chaindbProperty',
   280  			params: 1,
   281  			outputFormatter: console.log
   282  		}),
   283  		new web3._extend.Method({
   284  			name: 'chaindbCompact',
   285  			call: 'debug_chaindbCompact',
   286  		}),
   287  		new web3._extend.Method({
   288  			name: 'metrics',
   289  			call: 'debug_metrics',
   290  			params: 1
   291  		}),
   292  		new web3._extend.Method({
   293  			name: 'verbosity',
   294  			call: 'debug_verbosity',
   295  			params: 1
   296  		}),
   297  		new web3._extend.Method({
   298  			name: 'vmodule',
   299  			call: 'debug_vmodule',
   300  			params: 1
   301  		}),
   302  		new web3._extend.Method({
   303  			name: 'backtraceAt',
   304  			call: 'debug_backtraceAt',
   305  			params: 1,
   306  		}),
   307  		new web3._extend.Method({
   308  			name: 'stacks',
   309  			call: 'debug_stacks',
   310  			params: 0,
   311  			outputFormatter: console.log
   312  		}),
   313  		new web3._extend.Method({
   314  			name: 'freeOSMemory',
   315  			call: 'debug_freeOSMemory',
   316  			params: 0,
   317  		}),
   318  		new web3._extend.Method({
   319  			name: 'setGCPercent',
   320  			call: 'debug_setGCPercent',
   321  			params: 1,
   322  		}),
   323  		new web3._extend.Method({
   324  			name: 'memStats',
   325  			call: 'debug_memStats',
   326  			params: 0,
   327  		}),
   328  		new web3._extend.Method({
   329  			name: 'gcStats',
   330  			call: 'debug_gcStats',
   331  			params: 0,
   332  		}),
   333  		new web3._extend.Method({
   334  			name: 'cpuProfile',
   335  			call: 'debug_cpuProfile',
   336  			params: 2
   337  		}),
   338  		new web3._extend.Method({
   339  			name: 'startCPUProfile',
   340  			call: 'debug_startCPUProfile',
   341  			params: 1
   342  		}),
   343  		new web3._extend.Method({
   344  			name: 'stopCPUProfile',
   345  			call: 'debug_stopCPUProfile',
   346  			params: 0
   347  		}),
   348  		new web3._extend.Method({
   349  			name: 'goTrace',
   350  			call: 'debug_goTrace',
   351  			params: 2
   352  		}),
   353  		new web3._extend.Method({
   354  			name: 'startGoTrace',
   355  			call: 'debug_startGoTrace',
   356  			params: 1
   357  		}),
   358  		new web3._extend.Method({
   359  			name: 'stopGoTrace',
   360  			call: 'debug_stopGoTrace',
   361  			params: 0
   362  		}),
   363  		new web3._extend.Method({
   364  			name: 'blockProfile',
   365  			call: 'debug_blockProfile',
   366  			params: 2
   367  		}),
   368  		new web3._extend.Method({
   369  			name: 'setBlockProfileRate',
   370  			call: 'debug_setBlockProfileRate',
   371  			params: 1
   372  		}),
   373  		new web3._extend.Method({
   374  			name: 'writeBlockProfile',
   375  			call: 'debug_writeBlockProfile',
   376  			params: 1
   377  		}),
   378  		new web3._extend.Method({
   379  			name: 'mutexProfile',
   380  			call: 'debug_mutexProfile',
   381  			params: 2
   382  		}),
   383  		new web3._extend.Method({
   384  			name: 'setMutexProfileFraction',
   385  			call: 'debug_setMutexProfileFraction',
   386  			params: 1
   387  		}),
   388  		new web3._extend.Method({
   389  			name: 'writeMutexProfile',
   390  			call: 'debug_writeMutexProfile',
   391  			params: 1
   392  		}),
   393  		new web3._extend.Method({
   394  			name: 'writeMemProfile',
   395  			call: 'debug_writeMemProfile',
   396  			params: 1
   397  		}),
   398  		new web3._extend.Method({
   399  			name: 'traceBlock',
   400  			call: 'debug_traceBlock',
   401  			params: 2,
   402  			inputFormatter: [null, null]
   403  		}),
   404  		new web3._extend.Method({
   405  			name: 'traceBlockFromFile',
   406  			call: 'debug_traceBlockFromFile',
   407  			params: 2,
   408  			inputFormatter: [null, null]
   409  		}),
   410  		new web3._extend.Method({
   411  			name: 'traceBlockByNumber',
   412  			call: 'debug_traceBlockByNumber',
   413  			params: 2,
   414  			inputFormatter: [null, null]
   415  		}),
   416  		new web3._extend.Method({
   417  			name: 'traceBlockByHash',
   418  			call: 'debug_traceBlockByHash',
   419  			params: 2,
   420  			inputFormatter: [null, null]
   421  		}),
   422  		new web3._extend.Method({
   423  			name: 'traceTransaction',
   424  			call: 'debug_traceTransaction',
   425  			params: 2,
   426  			inputFormatter: [null, null]
   427  		}),
   428  		new web3._extend.Method({
   429  			name: 'preimage',
   430  			call: 'debug_preimage',
   431  			params: 1,
   432  			inputFormatter: [null]
   433  		}),
   434  		new web3._extend.Method({
   435  			name: 'getBadBlocks',
   436  			call: 'debug_getBadBlocks',
   437  			params: 0,
   438  		}),
   439  		new web3._extend.Method({
   440  			name: 'storageRangeAt',
   441  			call: 'debug_storageRangeAt',
   442  			params: 5,
   443  		}),
   444  		new web3._extend.Method({
   445  			name: 'getModifiedAccountsByNumber',
   446  			call: 'debug_getModifiedAccountsByNumber',
   447  			params: 2,
   448  			inputFormatter: [null, null],
   449  		}),
   450  		new web3._extend.Method({
   451  			name: 'getModifiedAccountsByHash',
   452  			call: 'debug_getModifiedAccountsByHash',
   453  			params: 2,
   454  			inputFormatter:[null, null],
   455  		}),
   456  	],
   457  	properties: []
   458  });
   459  `
   460  
   461  const Eth_JS = `
   462  web3._extend({
   463  	property: 'eth',
   464  	methods: [
   465  		new web3._extend.Method({
   466  			name: 'sign',
   467  			call: 'eth_sign',
   468  			params: 2,
   469  			inputFormatter: [web3._extend.formatters.inputAddressFormatter, null]
   470  		}),
   471  		new web3._extend.Method({
   472  			name: 'resend',
   473  			call: 'eth_resend',
   474  			params: 3,
   475  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
   476  		}),
   477  		new web3._extend.Method({
   478  			name: 'signTransaction',
   479  			call: 'eth_signTransaction',
   480  			params: 1,
   481  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   482  		}),
   483  		new web3._extend.Method({
   484  			name: 'submitTransaction',
   485  			call: 'eth_submitTransaction',
   486  			params: 1,
   487  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   488  		}),
   489  		new web3._extend.Method({
   490  			name: 'getRawTransaction',
   491  			call: 'eth_getRawTransactionByHash',
   492  			params: 1
   493  		}),
   494  		new web3._extend.Method({
   495  			name: 'getRawTransactionFromBlock',
   496  			call: function(args) {
   497  				return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex';
   498  			},
   499  			params: 2,
   500  			inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex]
   501  		}),
   502  	],
   503  	properties: [
   504  		new web3._extend.Property({
   505  			name: 'pendingTransactions',
   506  			getter: 'eth_pendingTransactions',
   507  			outputFormatter: function(txs) {
   508  				var formatted = [];
   509  				for (var i = 0; i < txs.length; i++) {
   510  					formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i]));
   511  					formatted[i].blockHash = null;
   512  				}
   513  				return formatted;
   514  			}
   515  		}),
   516  	]
   517  });
   518  `
   519  
   520  const Miner_JS = `
   521  web3._extend({
   522  	property: 'miner',
   523  	methods: [
   524  		new web3._extend.Method({
   525  			name: 'start',
   526  			call: 'miner_start',
   527  			params: 1,
   528  			inputFormatter: [null]
   529  		}),
   530  		new web3._extend.Method({
   531  			name: 'stop',
   532  			call: 'miner_stop'
   533  		}),
   534  		new web3._extend.Method({
   535  			name: 'setValidator',
   536  			call: 'miner_setValidator',
   537  			params: 1,
   538  			inputFormatter: [web3._extend.formatters.inputAddressFormatter]
   539  		}),
   540  		new web3._extend.Method({
   541  			name: 'setCoinbase',
   542  			call: 'miner_setCoinbase',
   543  			params: 1,
   544  			inputFormatter: [web3._extend.formatters.inputAddressFormatter]
   545  		}),
   546  		new web3._extend.Method({
   547  			name: 'setExtra',
   548  			call: 'miner_setExtra',
   549  			params: 1
   550  		}),
   551  		new web3._extend.Method({
   552  			name: 'setGasPrice',
   553  			call: 'miner_setGasPrice',
   554  			params: 1,
   555  			inputFormatter: [web3._extend.utils.fromDecimal]
   556  		}),
   557  		new web3._extend.Method({
   558  			name: 'setRecommitInterval',
   559  			call: 'miner_setRecommitInterval',
   560  			params: 1,
   561  		}),
   562  		new web3._extend.Method({
   563  			name: 'getHashrate',
   564  			call: 'miner_getHashrate'
   565  		}),
   566  	],
   567  	properties: []
   568  });
   569  `
   570  
   571  const Net_JS = `
   572  web3._extend({
   573  	property: 'net',
   574  	methods: [],
   575  	properties: [
   576  		new web3._extend.Property({
   577  			name: 'version',
   578  			getter: 'net_version'
   579  		}),
   580  	]
   581  });
   582  `
   583  
   584  const Personal_JS = `
   585  web3._extend({
   586  	property: 'personal',
   587  	methods: [
   588  		new web3._extend.Method({
   589  			name: 'importRawKey',
   590  			call: 'personal_importRawKey',
   591  			params: 2
   592  		}),
   593  		new web3._extend.Method({
   594  			name: 'sign',
   595  			call: 'personal_sign',
   596  			params: 3,
   597  			inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null]
   598  		}),
   599  		new web3._extend.Method({
   600  			name: 'ecRecover',
   601  			call: 'personal_ecRecover',
   602  			params: 2
   603  		}),
   604  		new web3._extend.Method({
   605  			name: 'openWallet',
   606  			call: 'personal_openWallet',
   607  			params: 2
   608  		}),
   609  		new web3._extend.Method({
   610  			name: 'deriveAccount',
   611  			call: 'personal_deriveAccount',
   612  			params: 3
   613  		}),
   614  		new web3._extend.Method({
   615  			name: 'signTransaction',
   616  			call: 'personal_signTransaction',
   617  			params: 2,
   618  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null]
   619  		}),
   620  	],
   621  	properties: [
   622  		new web3._extend.Property({
   623  			name: 'listWallets',
   624  			getter: 'personal_listWallets'
   625  		}),
   626  	]
   627  })
   628  `
   629  
   630  const RPC_JS = `
   631  web3._extend({
   632  	property: 'rpc',
   633  	methods: [],
   634  	properties: [
   635  		new web3._extend.Property({
   636  			name: 'modules',
   637  			getter: 'rpc_modules'
   638  		}),
   639  	]
   640  });
   641  `
   642  
   643  const Shh_JS = `
   644  web3._extend({
   645  	property: 'shh',
   646  	methods: [
   647  	],
   648  	properties:
   649  	[
   650  		new web3._extend.Property({
   651  			name: 'version',
   652  			getter: 'shh_version',
   653  			outputFormatter: web3._extend.utils.toDecimal
   654  		}),
   655  		new web3._extend.Property({
   656  			name: 'info',
   657  			getter: 'shh_info'
   658  		}),
   659  	]
   660  });
   661  `
   662  
   663  const SWARMFS_JS = `
   664  web3._extend({
   665  	property: 'swarmfs',
   666  	methods:
   667  	[
   668  		new web3._extend.Method({
   669  			name: 'mount',
   670  			call: 'swarmfs_mount',
   671  			params: 2
   672  		}),
   673  		new web3._extend.Method({
   674  			name: 'unmount',
   675  			call: 'swarmfs_unmount',
   676  			params: 1
   677  		}),
   678  		new web3._extend.Method({
   679  			name: 'listmounts',
   680  			call: 'swarmfs_listmounts',
   681  			params: 0
   682  		}),
   683  	]
   684  });
   685  `
   686  
   687  const TxPool_JS = `
   688  web3._extend({
   689  	property: 'txpool',
   690  	methods: [],
   691  	properties:
   692  	[
   693  		new web3._extend.Property({
   694  			name: 'content',
   695  			getter: 'txpool_content'
   696  		}),
   697  		new web3._extend.Property({
   698  			name: 'inspect',
   699  			getter: 'txpool_inspect'
   700  		}),
   701  		new web3._extend.Property({
   702  			name: 'status',
   703  			getter: 'txpool_status',
   704  			outputFormatter: function(status) {
   705  				status.pending = web3._extend.utils.toDecimal(status.pending);
   706  				status.queued = web3._extend.utils.toDecimal(status.queued);
   707  				return status;
   708  			}
   709  		}),
   710  	]
   711  });
   712  `