From accd5b4735fddc64515c09aec149df469bb5d492 Mon Sep 17 00:00:00 2001 From: Said Syakin Date: Thu, 1 Feb 2018 02:00:52 +0400 Subject: [PATCH] Changed eth to food in command line interface. Added new commands to console for sending transaction with additional data in Json format: sendTransactionWithData and getTransactionFormatted --- console/console.go | 8 +++++-- internal/web3ext/web3ext.go | 42 +++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/console/console.go b/console/console.go index 3cd2ad34b7..cd588f59d9 100644 --- a/console/console.go +++ b/console/console.go @@ -131,7 +131,7 @@ func (c *Console) init(preload []string) error { if err != nil { return fmt.Errorf("api modules: %v", err) } - flatten := "var eth = web3.eth; var personal = web3.personal; " + flatten := "var food = web3.eth; var personal = web3.personal; " for api := range apis { if api == "web3" { continue // manually mapped or ignore @@ -141,7 +141,11 @@ func (c *Console) init(preload []string) error { if err = c.jsre.Compile(fmt.Sprintf("%s.js", api), file); err != nil { return fmt.Errorf("%s.js: %v", api, err) } - flatten += fmt.Sprintf("var %s = web3.%s; ", api, api) + if api == "eth" { + flatten += fmt.Sprintf("var food = web3.%s; ", api) + } else { + flatten += fmt.Sprintf("var %s = web3.%s; ", api, api) + } } else if obj, err := c.jsre.Run("web3." + api); err == nil && obj.IsObject() { // Enable web3.js built-in extension if available. flatten += fmt.Sprintf("var %s = web3.%s; ", api, api) diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index ef0d2b4e6e..384e7164e4 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -22,7 +22,7 @@ var Modules = map[string]string{ "chequebook": Chequebook_JS, "clique": Clique_JS, "debug": Debug_JS, - "eth": Eth_JS, + "eth": Eth_JS, "miner": Miner_JS, "net": Net_JS, "personal": Personal_JS, @@ -412,7 +412,45 @@ web3._extend({ params: 2, inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex] }), - ], + new web3._extend.Method({ + name: 'sendTransactionWithData', + call: function(args) { + if (args[1]) { + if (!web3._extend.utils.isObject(args[1])) { + args[1] = "{\"description\":\"" + args[1] + "\"}" + } else { + args[1] = JSON.stringify(args[1]) + } + args[0].data = web3.toHex(args[1]) + } + return 'eth_sendTransaction' + }, + params: 1, + inputFormatter: [web3._extend.formatters.inputTransactionFormatter] + }), + new web3._extend.Method({ + name: 'getTransactionFormatted', + call: 'eth_getTransactionByHash', + params: 1, + outputFormatter: function (tx) { + if(tx.blockNumber !== null) + tx.blockNumber = web3.toDecimal(tx.blockNumber); + if(tx.transactionIndex !== null) + tx.transactionIndex = web3.toDecimal(tx.transactionIndex); + tx.nonce = web3.toDecimal(tx.nonce); + tx.gas = web3.toDecimal(tx.gas); + tx.gasPrice = web3.toBigNumber(tx.gasPrice); + tx.value = web3.toBigNumber(tx.value); + inputStr = web3.toUtf8(tx.input); + if (web3._extend.utils.isJson(inputStr)) { + tx.input = JSON.parse(inputStr); + } else { + tx.input = inputStr; + } + return tx; + } + }), + ], properties: [ new web3._extend.Property({ name: 'pendingTransactions',