Skip to content

Commit

Permalink
Merge pull request expanse-org#1 from ldcc/master
Browse files Browse the repository at this point in the history
require webu instead web3
  • Loading branch information
ldcc committed Apr 9, 2018
2 parents d362a98 + 234c581 commit 0d6fd78
Show file tree
Hide file tree
Showing 21 changed files with 16,813 additions and 187 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ This command will:
download more data in exchange for avoiding processing the entire history of the HappyUC network,
which is very CPU intensive.
* Start up Ghuc's built-in interactive [JavaScript console](https://github.com/happyuc-project/happyuc-go/wiki/JavaScript-Console),
(via the trailing `console` subcommand) through which you can invoke all official [`web3` methods](https://github.com/happyuc-project/wiki/wiki/JavaScript-API)
(via the trailing `console` subcommand) through which you can invoke all official [`webu` methods](https://github.com/happyuc-project/wiki/wiki/JavaScript-API)
as well as Ghuc's own [management APIs](https://github.com/happyuc-project/happyuc-go/wiki/Management-APIs).
This too is optional and if you leave it out you can always attach to an already running Ghuc instance
with `ghuc attach`.
Expand Down Expand Up @@ -156,15 +156,15 @@ HTTP based JSON-RPC API options:
* `--rpc` Enable the HTTP-RPC server
* `--rpcaddr` HTTP-RPC server listening interface (default: "localhost")
* `--rpcport` HTTP-RPC server listening port (default: 8545)
* `--rpcapi` API's offered over the HTTP-RPC interface (default: "eth,net,web3")
* `--rpcapi` API's offered over the HTTP-RPC interface (default: "eth,net,webu")
* `--rpccorsdomain` Comma separated list of domains from which to accept cross origin requests (browser enforced)
* `--ws` Enable the WS-RPC server
* `--wsaddr` WS-RPC server listening interface (default: "localhost")
* `--wsport` WS-RPC server listening port (default: 8546)
* `--wsapi` API's offered over the WS-RPC interface (default: "eth,net,web3")
* `--wsapi` API's offered over the WS-RPC interface (default: "eth,net,webu")
* `--wsorigins` Origins from which to accept websockets requests
* `--ipcdisable` Disable the IPC-RPC server
* `--ipcapi` API's offered over the IPC-RPC interface (default: "admin,debug,eth,miner,net,personal,shh,txpool,web3")
* `--ipcapi` API's offered over the IPC-RPC interface (default: "admin,debug,eth,miner,net,personal,shh,txpool,webu")
* `--ipcpath` Filename for IPC socket/pipe within the datadir (explicit paths escape it)

You'll need to use your own programming environments' capabilities (libraries, tools, etc) to connect
Expand Down
8 changes: 4 additions & 4 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ This command will:
download more data in exchange for avoiding processing the entire history of the HappyUC network,
which is very CPU intensive.
* Start up Ghuc's built-in interactive [JavaScript console](https://github.com/happyuc-project/happyuc-go/wiki/JavaScript-Console),
(via the trailing `console` subcommand) through which you can invoke all official [`web3` methods](https://github.com/happyuc-project/wiki/wiki/JavaScript-API)
(via the trailing `console` subcommand) through which you can invoke all official [`webu` methods](https://github.com/happyuc-project/wiki/wiki/JavaScript-API)
as well as Ghuc's own [management APIs](https://github.com/happyuc-project/happyuc-go/wiki/Management-APIs).
This too is optional and if you leave it out you can always attach to an already running Ghuc instance
with `ghuc attach`.
Expand Down Expand Up @@ -156,15 +156,15 @@ HTTP based JSON-RPC API options:
* `--rpc` Enable the HTTP-RPC server
* `--rpcaddr` HTTP-RPC server listening interface (default: "localhost")
* `--rpcport` HTTP-RPC server listening port (default: 8545)
* `--rpcapi` API's offered over the HTTP-RPC interface (default: "eth,net,web3")
* `--rpcapi` API's offered over the HTTP-RPC interface (default: "eth,net,webu")
* `--rpccorsdomain` Comma separated list of domains from which to accept cross origin requests (browser enforced)
* `--ws` Enable the WS-RPC server
* `--wsaddr` WS-RPC server listening interface (default: "localhost")
* `--wsport` WS-RPC server listening port (default: 8546)
* `--wsapi` API's offered over the WS-RPC interface (default: "eth,net,web3")
* `--wsapi` API's offered over the WS-RPC interface (default: "eth,net,webu")
* `--wsorigins` Origins from which to accept websockets requests
* `--ipcdisable` Disable the IPC-RPC server
* `--ipcapi` API's offered over the IPC-RPC interface (default: "admin,debug,eth,miner,net,personal,shh,txpool,web3")
* `--ipcapi` API's offered over the IPC-RPC interface (default: "admin,debug,eth,miner,net,personal,shh,txpool,webu")
* `--ipcpath` Filename for IPC socket/pipe within the datadir (explicit paths escape it)

You'll need to use your own programming environments' capabilities (libraries, tools, etc) to connect
Expand Down
4 changes: 2 additions & 2 deletions accounts/keystore/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

// Package keystore implements encrypted storage of secp256k1 private keys.
//
// Keys are stored as encrypted JSON files according to the Web3 Secret Storage specification.
// See https://github.com/happyuc-project/wiki/wiki/Web3-Secret-Storage-Definition for more information.
// Keys are stored as encrypted JSON files according to the webu Secret Storage specification.
// See https://github.com/happyuc-project/wiki/wiki/webu-Secret-Storage-Definition for more information.
package keystore

import (
Expand Down
2 changes: 1 addition & 1 deletion accounts/keystore/keystore_passphrase.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
This key store behaves as KeyStorePlain with the difference that
the private key is encrypted and on disk uses another JSON encoding.
The crypto is documented at https://github.com/happyuc-project/wiki/wiki/Web3-Secret-Storage-Definition
The crypto is documented at https://github.com/happyuc-project/wiki/wiki/webu-Secret-Storage-Definition
*/

Expand Down
1 change: 0 additions & 1 deletion cmd/ghuc/consolecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ func localConsole(ctx *cli.Context) error {
Client: client,
Preload: utils.MakeConsolePreloads(ctx),
}

console, err := console.New(config)
if err != nil {
utils.Fatalf("Failed to start the JavaScript console: %v", err)
Expand Down
5 changes: 2 additions & 3 deletions cmd/ghuc/consolecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ import (
"strings"
"testing"
"time"

"github.com/happyuc-project/happyuc-go/params"
)

const (
ipcAPIs = "admin:1.0 debug:1.0 huc:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 shh:1.0 txpool:1.0 web3:1.0"
httpAPIs = "huc:1.0 net:1.0 rpc:1.0 web3:1.0"
ipcAPIs = "admin:1.0 debug:1.0 huc:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 shh:1.0 txpool:1.0 webu:1.0"
httpAPIs = "huc:1.0 net:1.0 rpc:1.0 webu:1.0"
)

// Tests that a node embedded within a console can be started up properly and
Expand Down
2 changes: 1 addition & 1 deletion cmd/pupphuc/module_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ var dashboardContent = `
<div class="clearfix"></div>
</div>
<div class="x_content">
<p>The Mist browser is an <a href="https://electron.atom.io/" target="about:blank">Electron</a> based desktop application to load and interact with HappyUC enabled third party web DApps. Beside all the functionality provided by the HappyUC Wallet, Mist is an extended web-browser where loaded pages have access to the HappyUC network via a web3.js provider, and may also interact with users' own accounts (given proper authorization and confirmation of course).</p>
<p>The Mist browser is an <a href="https://electron.atom.io/" target="about:blank">Electron</a> based desktop application to load and interact with HappyUC enabled third party web DApps. Beside all the functionality provided by the HappyUC Wallet, Mist is an extended web-browser where loaded pages have access to the HappyUC network via a webu.js provider, and may also interact with users' own accounts (given proper authorization and confirmation of course).</p>
<p>Under the hood the browser is backed by a happyuc-go full node, meaning that a mid range machine is assumed. Similarly, synchronization is based on <strong>fast-sync</strong>, which will download all blockchain data from the network and make it available to the wallet. Light nodes cannot currently fully back the wallet, but it's a target actively pursued.</p>
<br/>
<p>To connect with the Mist browser, you'll need to initialize your private network first via Ghuc as Mist does not currently support calling Ghuc directly. To initialize your local chain, download <a href="/{{.GhucGenesis}}"><code>{{.GhucGenesis}}</code></a> and run:
Expand Down
4 changes: 2 additions & 2 deletions console/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (b *bridge) SleepBlocks(call otto.FunctionCall) (response otto.Value) {
throwJSException("expected number as second argument")
}
}
// go through the console, this will allow web3 to call the appropriate
// go through the console, this will allow webu to call the appropriate
// callbacks if a delayed response or notification is received.
blockNumber := func() int64 {
result, err := call.Otto.Run("eth.blockNumber")
Expand Down Expand Up @@ -276,7 +276,7 @@ type jsonrpcCall struct {
Params []interface{}
}

// Send implements the web3 provider "send" method.
// Send implements the webu provider "send" method.
func (b *bridge) Send(call otto.FunctionCall) (response otto.Value) {
// Remarshal the request into a Go value.
JSON, _ := call.Otto.Object("JSON")
Expand Down
45 changes: 26 additions & 19 deletions console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"syscall"

"github.com/happyuc-project/happyuc-go/internal/jsre"
"github.com/happyuc-project/happyuc-go/internal/web3ext"
"github.com/happyuc-project/happyuc-go/internal/webuext"
"github.com/happyuc-project/happyuc-go/rpc"
"github.com/mattn/go-colorable"
"github.com/peterh/liner"
Expand Down Expand Up @@ -99,6 +99,7 @@ func New(config Config) (*Console, error) {
if err := console.init(config.Preload); err != nil {
return nil, err
}

return console, nil
}

Expand All @@ -121,34 +122,40 @@ func (c *Console) init(preload []string) error {
if err := c.jsre.Compile("bignumber.js", jsre.BigNumber_JS); err != nil {
return fmt.Errorf("bignumber.js: %v", err)
}
if err := c.jsre.Compile("web3.js", jsre.Web3_JS); err != nil {
return fmt.Errorf("web3.js: %v", err)

if err := c.jsre.Compile("webu.js", jsre.Webu_JS); err != nil {
return fmt.Errorf("webu.js: %v", err)
}
if _, err := c.jsre.Run("var Web3 = require('web3');"); err != nil {
return fmt.Errorf("web3 require: %v", err)

// TODO do require webu
if _, err := c.jsre.Run("var Webu = require('web3');"); err != nil {
return fmt.Errorf("webu require: %v", err)
}
if _, err := c.jsre.Run("var web3 = new Web3(jeth);"); err != nil {
return fmt.Errorf("web3 provider: %v", err)

if _, err := c.jsre.Run("var webu = new Webu(jeth);"); err != nil {
return fmt.Errorf("webu provider: %v", err)
}

// Load the supported APIs into the JavaScript runtime environment
apis, err := c.client.SupportedModules()
if err != nil {
return fmt.Errorf("api modules: %v", err)
}
flatten := "var eth = web3.eth; var personal = web3.personal; "

flatten := "var huc = webu.huc; var personal = webu.personal; "
for api := range apis {
if api == "web3" {
if api == "webu" {
continue // manually mapped or ignore
}
if file, ok := web3ext.Modules[api]; ok {
if file, ok := webuext.Modules[api]; ok {
// Load our extension for the module.
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)
} 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)
flatten += fmt.Sprintf("var %s = webu.%s; ", api, api)
} else if obj, err := c.jsre.Run("webu." + api); err == nil && obj.IsObject() {
// Enable webu.js built-in extension if available.
flatten += fmt.Sprintf("var %s = webu.%s; ", api, api)
}
}
if _, err = c.jsre.Run(flatten); err != nil {
Expand All @@ -166,8 +173,8 @@ func (c *Console) init(preload []string) error {
}
// Override the openWallet, unlockAccount, newAccount and sign methods since
// these require user interaction. Assign these method in the Console the
// original web3 callbacks. These will be called by the jeth.* methods after
// they got the password from the user and send the original web3 request to
// original webu callbacks. These will be called by the jeth.* methods after
// they got the password from the user and send the original webu request to
// the backend.
if obj := personal.Object(); obj != nil { // make sure the personal api is enabled over the interface
if _, err = c.jsre.Run(`jeth.openWallet = personal.openWallet;`); err != nil {
Expand Down Expand Up @@ -257,8 +264,8 @@ func (c *Console) AutoCompleteInput(line string, pos int) (string, []string, str
if line[start] == '.' || (line[start] >= 'a' && line[start] <= 'z') || (line[start] >= 'A' && line[start] <= 'Z') {
continue
}
// Handle web3 in a special way (i.e. other numbers aren't auto completed)
if start >= 3 && line[start-3:start] == "web3" {
// Handle webu in a special way (i.e. other numbers aren't auto completed)
if start >= 3 && line[start-3:start] == "webu" {
start -= 3
continue
}
Expand All @@ -275,7 +282,7 @@ func (c *Console) Welcome() {
// Print some generic Ghuc metadata
fmt.Fprint(c.printer, "Welcome to the Ghuc JavaScript console!\n\n")
c.jsre.Run(`
console.log("instance: " + web3.version.node);
console.log("instance: " + webu.version.node);
console.log("coinbase: " + eth.coinbase);
console.log("at block: " + eth.blockNumber + " (" + new Date(1000 * eth.getBlock(eth.blockNumber).timestamp) + ")");
console.log(" datadir: " + admin.datadir);
Expand Down
4 changes: 2 additions & 2 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ func (tx *Transaction) DecodeRLP(s *rlp.Stream) error {
return err
}

// MarshalJSON encodes the web3 RPC transaction format.
// MarshalJSON encodes the webu RPC transaction format.
func (tx *Transaction) MarshalJSON() ([]byte, error) {
hash := tx.Hash()
data := tx.data
data.Hash = &hash
return data.MarshalJSON()
}

// UnmarshalJSON decodes the web3 RPC transaction format.
// UnmarshalJSON decodes the webu RPC transaction format.
func (tx *Transaction) UnmarshalJSON(input []byte) error {
var dec txdata
if err := dec.UnmarshalJSON(input); err != nil {
Expand Down
21 changes: 10 additions & 11 deletions internal/jsre/deps/bindata.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/jsre/deps/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
// Package deps contains the console JavaScript dependencies Go embedded.
package deps

//go:generate go-bindata -nometadata -pkg deps -o bindata.go bignumber.js web3.js
//go:generate go-bindata -nometadata -pkg deps -o bindata.go bignumber.js webu.js
//go:generate gofmt -w -s bindata.go
2 changes: 1 addition & 1 deletion internal/jsre/deps/web3.js
Original file line number Diff line number Diff line change
Expand Up @@ -4055,7 +4055,7 @@ require = (function e(t, n, r) {
outputBigNumberFormatter: outputBigNumberFormatter,
outputTransactionFormatter: outputTransactionFormatter,
outputTransactionReceiptFormatter: outputTransactionReceiptFormatter,
outputBlockFormatter: outputBlockFormatter,
outputBlockFormatter: outputBlockFormatter,
outputLogFormatter: outputLogFormatter,
outputPostFormatter: outputPostFormatter,
outputSyncingFormatter: outputSyncingFormatter
Expand Down
Loading

0 comments on commit 0d6fd78

Please sign in to comment.