github.com/ur-technology/go-ur@v1.5.5/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  	"bzz":        Bzz_JS,
    23  	"chequebook": Chequebook_JS,
    24  	"debug":      Debug_JS,
    25  	"ens":        ENS_JS,
    26  	"eth":        Eth_JS,
    27  	"miner":      Miner_JS,
    28  	"net":        Net_JS,
    29  	"personal":   Personal_JS,
    30  	"rpc":        RPC_JS,
    31  	"shh":        Shh_JS,
    32  	"txpool":     TxPool_JS,
    33  }
    34  
    35  const Bzz_JS = `
    36  web3._extend({
    37  	property: 'bzz',
    38  	methods:
    39  	[
    40  		new web3._extend.Method({
    41  			name: 'syncEnabled',
    42  			call: 'bzz_syncEnabled',
    43  			params: 1,
    44  			inputFormatter: [null]
    45  		}),
    46  		new web3._extend.Method({
    47  			name: 'swapEnabled',
    48  			call: 'bzz_swapEnabled',
    49  			params: 1,
    50  			inputFormatter: [null]
    51  		}),
    52  		new web3._extend.Method({
    53  			name: 'download',
    54  			call: 'bzz_download',
    55  			params: 2,
    56  			inputFormatter: [null, null]
    57  		}),
    58  		new web3._extend.Method({
    59  			name: 'upload',
    60  			call: 'bzz_upload',
    61  			params: 2,
    62  			inputFormatter: [null, null]
    63  		}),
    64  		new web3._extend.Method({
    65  			name: 'resolve',
    66  			call: 'bzz_resolve',
    67  			params: 1,
    68  			inputFormatter: [null]
    69  		}),
    70  		new web3._extend.Method({
    71  			name: 'get',
    72  			call: 'bzz_get',
    73  			params: 1,
    74  			inputFormatter: [null]
    75  		}),
    76  		new web3._extend.Method({
    77  			name: 'put',
    78  			call: 'bzz_put',
    79  			params: 2,
    80  			inputFormatter: [null, null]
    81  		}),
    82  		new web3._extend.Method({
    83  			name: 'modify',
    84  			call: 'bzz_modify',
    85  			params: 4,
    86  			inputFormatter: [null, null, null, null]
    87  		})
    88  	],
    89  	properties:
    90  	[
    91  		new web3._extend.Property({
    92  			name: 'hive',
    93  			getter: 'bzz_hive'
    94  		}),
    95  		new web3._extend.Property({
    96  			name: 'info',
    97  			getter: 'bzz_info',
    98  		}),
    99  	]
   100  });
   101  `
   102  
   103  const ENS_JS = `
   104  web3._extend({
   105    property: 'ens',
   106    methods:
   107    [
   108      new web3._extend.Method({
   109  			name: 'register',
   110  			call: 'ens_register',
   111  			params: 1,
   112  			inputFormatter: [null]
   113  		}),
   114  	new web3._extend.Method({
   115  			name: 'setContentHash',
   116  			call: 'ens_setContentHash',
   117  			params: 2,
   118  			inputFormatter: [null, null]
   119  		}),
   120  	new web3._extend.Method({
   121  			name: 'resolve',
   122  			call: 'ens_resolve',
   123  			params: 1,
   124  			inputFormatter: [null]
   125  		}),
   126  	]
   127  })
   128  `
   129  
   130  const Chequebook_JS = `
   131  web3._extend({
   132    property: 'chequebook',
   133    methods:
   134    [
   135      new web3._extend.Method({
   136        name: 'deposit',
   137        call: 'chequebook_deposit',
   138        params: 1,
   139        inputFormatter: [null]
   140      }),
   141      new web3._extend.Property({
   142  			name: 'balance',
   143  			getter: 'chequebook_balance',
   144  				outputFormatter: web3._extend.utils.toDecimal
   145  		}),
   146      new web3._extend.Method({
   147        name: 'cash',
   148        call: 'chequebook_cash',
   149        params: 1,
   150        inputFormatter: [null]
   151      }),
   152      new web3._extend.Method({
   153        name: 'issue',
   154        call: 'chequebook_issue',
   155        params: 2,
   156        inputFormatter: [null, null]
   157      }),
   158    ]
   159  });
   160  `
   161  
   162  const Admin_JS = `
   163  web3._extend({
   164  	property: 'admin',
   165  	methods:
   166  	[
   167  		new web3._extend.Method({
   168  			name: 'addPeer',
   169  			call: 'admin_addPeer',
   170  			params: 1
   171  		}),
   172  		new web3._extend.Method({
   173  			name: 'removePeer',
   174  			call: 'admin_removePeer',
   175  			params: 1
   176  		}),
   177  		new web3._extend.Method({
   178  			name: 'exportChain',
   179  			call: 'admin_exportChain',
   180  			params: 1,
   181  			inputFormatter: [null]
   182  		}),
   183  		new web3._extend.Method({
   184  			name: 'importChain',
   185  			call: 'admin_importChain',
   186  			params: 1
   187  		}),
   188  		new web3._extend.Method({
   189  			name: 'sleepBlocks',
   190  			call: 'admin_sleepBlocks',
   191  			params: 2
   192  		}),
   193  		new web3._extend.Method({
   194  			name: 'setSolc',
   195  			call: 'admin_setSolc',
   196  			params: 1
   197  		}),
   198  		new web3._extend.Method({
   199  			name: 'startRPC',
   200  			call: 'admin_startRPC',
   201  			params: 4,
   202  			inputFormatter: [null, null, null, null]
   203  		}),
   204  		new web3._extend.Method({
   205  			name: 'stopRPC',
   206  			call: 'admin_stopRPC'
   207  		}),
   208  		new web3._extend.Method({
   209  			name: 'startWS',
   210  			call: 'admin_startWS',
   211  			params: 4,
   212  			inputFormatter: [null, null, null, null]
   213  		}),
   214  		new web3._extend.Method({
   215  			name: 'stopWS',
   216  			call: 'admin_stopWS'
   217  		})
   218  	],
   219  	properties:
   220  	[
   221  		new web3._extend.Property({
   222  			name: 'nodeInfo',
   223  			getter: 'admin_nodeInfo'
   224  		}),
   225  		new web3._extend.Property({
   226  			name: 'peers',
   227  			getter: 'admin_peers'
   228  		}),
   229  		new web3._extend.Property({
   230  			name: 'datadir',
   231  			getter: 'admin_datadir'
   232  		})
   233  	]
   234  });
   235  `
   236  
   237  const Debug_JS = `
   238  web3._extend({
   239  	property: 'debug',
   240  	methods:
   241  	[
   242  		new web3._extend.Method({
   243  			name: 'printBlock',
   244  			call: 'debug_printBlock',
   245  			params: 1
   246  		}),
   247  		new web3._extend.Method({
   248  			name: 'getBlockRlp',
   249  			call: 'debug_getBlockRlp',
   250  			params: 1
   251  		}),
   252  		new web3._extend.Method({
   253  			name: 'setHead',
   254  			call: 'debug_setHead',
   255  			params: 1
   256  		}),
   257  		new web3._extend.Method({
   258  			name: 'traceBlock',
   259  			call: 'debug_traceBlock',
   260  			params: 1
   261  		}),
   262  		new web3._extend.Method({
   263  			name: 'traceBlockByFile',
   264  			call: 'debug_traceBlockByFile',
   265  			params: 1
   266  		}),
   267  		new web3._extend.Method({
   268  			name: 'traceBlockByNumber',
   269  			call: 'debug_traceBlockByNumber',
   270  			params: 1
   271  		}),
   272  		new web3._extend.Method({
   273  			name: 'traceBlockByHash',
   274  			call: 'debug_traceBlockByHash',
   275  			params: 1
   276  		}),
   277  		new web3._extend.Method({
   278  			name: 'seedHash',
   279  			call: 'debug_seedHash',
   280  			params: 1
   281  		}),
   282  		new web3._extend.Method({
   283  			name: 'dumpBlock',
   284  			call: 'debug_dumpBlock',
   285  			params: 1
   286  		}),
   287  		new web3._extend.Method({
   288  			name: 'chaindbProperty',
   289  			call: 'debug_chaindbProperty',
   290  			params: 1,
   291  			outputFormatter: console.log
   292  		}),
   293  		new web3._extend.Method({
   294  			name: 'chaindbCompact',
   295  			call: 'debug_chaindbCompact',
   296  		}),
   297  		new web3._extend.Method({
   298  			name: 'metrics',
   299  			call: 'debug_metrics',
   300  			params: 1
   301  		}),
   302  		new web3._extend.Method({
   303  			name: 'verbosity',
   304  			call: 'debug_verbosity',
   305  			params: 1
   306  		}),
   307  		new web3._extend.Method({
   308  			name: 'vmodule',
   309  			call: 'debug_vmodule',
   310  			params: 1
   311  		}),
   312  		new web3._extend.Method({
   313  			name: 'backtraceAt',
   314  			call: 'debug_backtraceAt',
   315  			params: 1,
   316  		}),
   317  		new web3._extend.Method({
   318  			name: 'stacks',
   319  			call: 'debug_stacks',
   320  			params: 0,
   321  			outputFormatter: console.log
   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: 'writeMemProfile',
   380  			call: 'debug_writeMemProfile',
   381  			params: 1
   382  		}),
   383  		new web3._extend.Method({
   384  			name: 'traceTransaction',
   385  			call: 'debug_traceTransaction',
   386  			params: 2,
   387  			inputFormatter: [null, null]
   388  		})
   389  	],
   390  	properties: []
   391  });
   392  `
   393  
   394  const Eth_JS = `
   395  web3._extend({
   396  	property: 'eth',
   397  	methods:
   398  	[
   399  		new web3._extend.Method({
   400  			name: 'sign',
   401  			call: 'eth_sign',
   402  			params: 2,
   403  			inputFormatter: [web3._extend.formatters.inputAddressFormatter, null]
   404  		}),
   405  		new web3._extend.Method({
   406  			name: 'resend',
   407  			call: 'eth_resend',
   408  			params: 3,
   409  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
   410  		}),
   411  		new web3._extend.Method({
   412  			name: 'getNatSpec',
   413  			call: 'eth_getNatSpec',
   414  			params: 1,
   415  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   416  		}),
   417  		new web3._extend.Method({
   418  			name: 'signTransaction',
   419  			call: 'eth_signTransaction',
   420  			params: 1,
   421  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   422  		}),
   423  		new web3._extend.Method({
   424  			name: 'submitTransaction',
   425  			call: 'eth_submitTransaction',
   426  			params: 1,
   427  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
   428  		}),
   429  		new web3._extend.Method({
   430  			name: 'getRawTransaction',
   431  			call: 'eth_getRawTransactionByHash',
   432  			params: 1
   433  		}),
   434  		new web3._extend.Method({
   435  			name: 'getRawTransactionFromBlock',
   436  			call: function(args) {
   437  				return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex';
   438  			},
   439  			params: 2,
   440  			inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex]
   441  		})
   442  	],
   443  	properties:
   444  	[
   445  		new web3._extend.Property({
   446  			name: 'pendingTransactions',
   447  			getter: 'eth_pendingTransactions',
   448  			outputFormatter: function(txs) {
   449  				var formatted = [];
   450  				for (var i = 0; i < txs.length; i++) {
   451  					formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i]));
   452  					formatted[i].blockHash = null;
   453  				}
   454  				return formatted;
   455  			}
   456  		})
   457  	]
   458  });
   459  `
   460  
   461  const Miner_JS = `
   462  web3._extend({
   463  	property: 'miner',
   464  	methods:
   465  	[
   466  		new web3._extend.Method({
   467  			name: 'start',
   468  			call: 'miner_start',
   469  			params: 1,
   470  			inputFormatter: [null]
   471  		}),
   472  		new web3._extend.Method({
   473  			name: 'stop',
   474  			call: 'miner_stop'
   475  		}),
   476  		new web3._extend.Method({
   477  			name: 'setEtherbase',
   478  			call: 'miner_setEtherbase',
   479  			params: 1,
   480  			inputFormatter: [web3._extend.formatters.inputAddressFormatter]
   481  		}),
   482  		new web3._extend.Method({
   483  			name: 'setExtra',
   484  			call: 'miner_setExtra',
   485  			params: 1
   486  		}),
   487  		new web3._extend.Method({
   488  			name: 'setGasPrice',
   489  			call: 'miner_setGasPrice',
   490  			params: 1,
   491  			inputFormatter: [web3._extend.utils.fromDecimal]
   492  		}),
   493  		new web3._extend.Method({
   494  			name: 'startAutoDAG',
   495  			call: 'miner_startAutoDAG',
   496  			params: 0
   497  		}),
   498  		new web3._extend.Method({
   499  			name: 'stopAutoDAG',
   500  			call: 'miner_stopAutoDAG',
   501  			params: 0
   502  		}),
   503  		new web3._extend.Method({
   504  			name: 'makeDAG',
   505  			call: 'miner_makeDAG',
   506  			params: 1,
   507  			inputFormatter: [web3._extend.formatters.inputDefaultBlockNumberFormatter]
   508  		})
   509  	],
   510  	properties: []
   511  });
   512  `
   513  
   514  const Net_JS = `
   515  web3._extend({
   516  	property: 'net',
   517  	methods: [],
   518  	properties:
   519  	[
   520  		new web3._extend.Property({
   521  			name: 'version',
   522  			getter: 'net_version'
   523  		})
   524  	]
   525  });
   526  `
   527  
   528  const Personal_JS = `
   529  web3._extend({
   530  	property: 'personal',
   531  	methods:
   532  	[
   533  		new web3._extend.Method({
   534  			name: 'importRawKey',
   535  			call: 'personal_importRawKey',
   536  			params: 2
   537  		}),
   538  		new web3._extend.Method({
   539  			name: 'sendTransaction',
   540  			call: 'personal_sendTransaction',
   541  			params: 2,
   542  			inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null]
   543  		}),
   544  		new web3._extend.Method({
   545  			name: 'sign',
   546  			call: 'personal_sign',
   547  			params: 3,
   548  			inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null]
   549  		}),
   550  		new web3._extend.Method({
   551  			name: 'ecRecover',
   552  			call: 'personal_ecRecover',
   553  			params: 2
   554  		})
   555  	]
   556  })
   557  `
   558  
   559  const RPC_JS = `
   560  web3._extend({
   561  	property: 'rpc',
   562  	methods: [],
   563  	properties:
   564  	[
   565  		new web3._extend.Property({
   566  			name: 'modules',
   567  			getter: 'rpc_modules'
   568  		})
   569  	]
   570  });
   571  `
   572  
   573  const Shh_JS = `
   574  web3._extend({
   575  	property: 'shh',
   576  	methods: [],
   577  	properties:
   578  	[
   579  		new web3._extend.Property({
   580  			name: 'version',
   581  			getter: 'shh_version',
   582  			outputFormatter: web3._extend.utils.toDecimal
   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  `