This commit is contained in:
Changhoon Lee 2016-05-12 08:22:57 +00:00
commit 35bba66f7c
8 changed files with 149 additions and 131 deletions

View file

@ -1,6 +1,8 @@
language: go language: go
go: go:
- 1.4.2 - 1.4.2
- 1.5.4
- 1.6.2
install: install:
# - go get code.google.com/p/go.tools/cmd/goimports # - go get code.google.com/p/go.tools/cmd/goimports
# - go get github.com/golang/lint/golint # - go get github.com/golang/lint/golint

View file

@ -58,14 +58,14 @@ anyone on the internet, and are grateful for even the smallest of fixes!
If you'd like to contribute to go-ethereum, please fork, fix, commit and send a pull request If you'd like to contribute to go-ethereum, please fork, fix, commit and send a pull request
for the maintainers to review and merge into the main code base. If you wish to submit more for the maintainers to review and merge into the main code base. If you wish to submit more
complex changes though, please check up with the core devs first on [our gitter channel](https://gitter.im/ethereum/go-ethereum) complex changes though, please check up with the core devs first on [our gitter channel](https://gitter.im/ethereum/go-ethereum)
to ensure those changes are in line with the general philosopy of the project and/or get some to ensure those changes are in line with the general philosophy of the project and/or get some
early feedback which can make both your efforts much lighter as well as our review and merge early feedback which can make both your efforts much lighter as well as our review and merge
procedures quick and simple. procedures quick and simple.
Please make sure your contributions adhere to our coding guidlines: Please make sure your contributions adhere to our coding guidelines:
* Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)). * Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)).
* Code must be documented adherign to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines. * Code must be documented adhering to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines.
* Pull requests need to be based on and opened against the `develop` branch. * Pull requests need to be based on and opened against the `develop` branch.
* Commit messages should be prefixed with the package(s) they modify. * Commit messages should be prefixed with the package(s) they modify.
* E.g. "eth, rpc: make trace configs optional" * E.g. "eth, rpc: make trace configs optional"

View file

@ -199,7 +199,7 @@ func (js *jsre) apiBindings() error {
// load only supported API's in javascript runtime // load only supported API's in javascript runtime
shortcuts := "var eth = web3.eth; var personal = web3.personal; " shortcuts := "var eth = web3.eth; var personal = web3.personal; "
for _, apiName := range apiNames { for _, apiName := range apiNames {
if apiName == "web3" || apiName == "rpc" { if apiName == "web3" {
continue // manually mapped or ignore continue // manually mapped or ignore
} }

View file

@ -20,7 +20,6 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"fmt" "fmt"
"html/template"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
@ -28,6 +27,7 @@ import (
"regexp" "regexp"
"sync" "sync"
"testing" "testing"
"text/template"
"time" "time"
) )

View file

@ -18,44 +18,17 @@
package web3ext package web3ext
var Modules = map[string]string{ var Modules = map[string]string{
"txpool": TxPool_JS,
"admin": Admin_JS, "admin": Admin_JS,
"personal": Personal_JS, "debug": Debug_JS,
"eth": Eth_JS, "eth": Eth_JS,
"miner": Miner_JS, "miner": Miner_JS,
"debug": Debug_JS,
"net": Net_JS, "net": Net_JS,
"personal": Personal_JS,
"rpc": RPC_JS,
"shh": Shh_JS,
"txpool": TxPool_JS,
} }
const TxPool_JS = `
web3._extend({
property: 'txpool',
methods:
[
],
properties:
[
new web3._extend.Property({
name: 'content',
getter: 'txpool_content'
}),
new web3._extend.Property({
name: 'inspect',
getter: 'txpool_inspect'
}),
new web3._extend.Property({
name: 'status',
getter: 'txpool_status',
outputFormatter: function(status) {
status.pending = web3._extend.utils.toDecimal(status.pending);
status.queued = web3._extend.utils.toDecimal(status.queued);
return status;
}
})
]
});
`
const Admin_JS = ` const Admin_JS = `
web3._extend({ web3._extend({
property: 'admin', property: 'admin',
@ -176,88 +149,6 @@ web3._extend({
}); });
` `
const Personal_JS = `
web3._extend({
property: 'personal',
methods:
[
new web3._extend.Method({
name: 'importRawKey',
call: 'personal_importRawKey',
params: 2
})
]
});
`
const Eth_JS = `
web3._extend({
property: 'eth',
methods:
[
new web3._extend.Method({
name: 'sign',
call: 'eth_sign',
params: 2,
inputFormatter: [web3._extend.formatters.inputAddressFormatter, null]
}),
new web3._extend.Method({
name: 'resend',
call: 'eth_resend',
params: 3,
inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
}),
new web3._extend.Method({
name: 'getNatSpec',
call: 'eth_getNatSpec',
params: 1,
inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
}),
new web3._extend.Method({
name: 'signTransaction',
call: 'eth_signTransaction',
params: 1,
inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
}),
new web3._extend.Method({
name: 'submitTransaction',
call: 'eth_submitTransaction',
params: 1,
inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
})
],
properties:
[
new web3._extend.Property({
name: 'pendingTransactions',
getter: 'eth_pendingTransactions',
outputFormatter: function(txs) {
var formatted = [];
for (var i = 0; i < txs.length; i++) {
formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i]));
formatted[i].blockHash = null;
}
return formatted;
}
})
]
});
`
const Net_JS = `
web3._extend({
property: 'net',
methods: [],
properties:
[
new web3._extend.Property({
name: 'version',
getter: 'net_version'
})
]
});
`
const Debug_JS = ` const Debug_JS = `
web3._extend({ web3._extend({
property: 'debug', property: 'debug',
@ -410,6 +301,60 @@ web3._extend({
}); });
` `
const Eth_JS = `
web3._extend({
property: 'eth',
methods:
[
new web3._extend.Method({
name: 'sign',
call: 'eth_sign',
params: 2,
inputFormatter: [web3._extend.formatters.inputAddressFormatter, null]
}),
new web3._extend.Method({
name: 'resend',
call: 'eth_resend',
params: 3,
inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
}),
new web3._extend.Method({
name: 'getNatSpec',
call: 'eth_getNatSpec',
params: 1,
inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
}),
new web3._extend.Method({
name: 'signTransaction',
call: 'eth_signTransaction',
params: 1,
inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
}),
new web3._extend.Method({
name: 'submitTransaction',
call: 'eth_submitTransaction',
params: 1,
inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
})
],
properties:
[
new web3._extend.Property({
name: 'pendingTransactions',
getter: 'eth_pendingTransactions',
outputFormatter: function(txs) {
var formatted = [];
for (var i = 0; i < txs.length; i++) {
formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i]));
formatted[i].blockHash = null;
}
return formatted;
}
})
]
});
`
const Miner_JS = ` const Miner_JS = `
web3._extend({ web3._extend({
property: 'miner', property: 'miner',
@ -440,7 +385,7 @@ web3._extend({
name: 'setGasPrice', name: 'setGasPrice',
call: 'miner_setGasPrice', call: 'miner_setGasPrice',
params: 1, params: 1,
inputFormatter: [web3._extend.utils.fromDecial] inputFormatter: [web3._extend.utils.fromDecimal]
}), }),
new web3._extend.Method({ new web3._extend.Method({
name: 'startAutoDAG', name: 'startAutoDAG',
@ -463,6 +408,48 @@ web3._extend({
}); });
` `
const Net_JS = `
web3._extend({
property: 'net',
methods: [],
properties:
[
new web3._extend.Property({
name: 'version',
getter: 'net_version'
})
]
});
`
const Personal_JS = `
web3._extend({
property: 'personal',
methods:
[
new web3._extend.Method({
name: 'importRawKey',
call: 'personal_importRawKey',
params: 2
})
]
});
`
const RPC_JS = `
web3._extend({
property: 'rpc',
methods: [],
properties:
[
new web3._extend.Property({
name: 'modules',
getter: 'rpc_modules'
})
]
});
`
const Shh_JS = ` const Shh_JS = `
web3._extend({ web3._extend({
property: 'shh', property: 'shh',
@ -471,7 +458,35 @@ web3._extend({
[ [
new web3._extend.Property({ new web3._extend.Property({
name: 'version', name: 'version',
getter: 'shh_version' getter: 'shh_version',
outputFormatter: web3._extend.utils.toDecimal
})
]
});
`
const TxPool_JS = `
web3._extend({
property: 'txpool',
methods: [],
properties:
[
new web3._extend.Property({
name: 'content',
getter: 'txpool_content'
}),
new web3._extend.Property({
name: 'inspect',
getter: 'txpool_inspect'
}),
new web3._extend.Property({
name: 'status',
getter: 'txpool_status',
outputFormatter: function(status) {
status.pending = web3._extend.utils.toDecimal(status.pending);
status.queued = web3._extend.utils.toDecimal(status.queued);
return status;
}
}) })
] ]
}); });

View file

@ -34,7 +34,8 @@ const (
notificationBufferSize = 10000 // max buffered notifications before codec is closed notificationBufferSize = 10000 // max buffered notifications before codec is closed
DefaultIPCApis = "admin,eth,debug,miner,net,shh,txpool,personal,web3" MetadataApi = "rpc"
DefaultIPCApis = "admin,debug,eth,miner,net,personal,shh,txpool,web3"
DefaultHTTPApis = "eth,net,web3" DefaultHTTPApis = "eth,net,web3"
) )
@ -61,7 +62,7 @@ func NewServer() *Server {
// register a default service which will provide meta information about the RPC service such as the services and // register a default service which will provide meta information about the RPC service such as the services and
// methods it offers. // methods it offers.
rpcService := &RPCService{server} rpcService := &RPCService{server}
server.RegisterName("rpc", rpcService) server.RegisterName(MetadataApi, rpcService)
return server return server
} }

View file

@ -234,7 +234,7 @@ func SupportedModules(client Client) (map[string]string, error) {
req := JSONRequest{ req := JSONRequest{
Id: []byte("1"), Id: []byte("1"),
Version: "2.0", Version: "2.0",
Method: "rpc_modules", Method: MetadataApi + "_modules",
} }
if err := client.Send(req); err != nil { if err := client.Send(req); err != nil {
return nil, err return nil, err

View file

@ -61,22 +61,22 @@ func wsHandshakeValidator(allowedOrigins []string) func(*websocket.Config, *http
allowAllOrigins = true allowAllOrigins = true
} }
if origin != "" { if origin != "" {
origins.Add(origin) origins.Add(strings.ToLower(origin))
} }
} }
// allow localhost if no allowedOrigins are specified // allow localhost if no allowedOrigins are specified.
if len(origins.List()) == 0 { if len(origins.List()) == 0 {
origins.Add("http://localhost") origins.Add("http://localhost")
if hostname, err := os.Hostname(); err == nil { if hostname, err := os.Hostname(); err == nil {
origins.Add("http://" + hostname) origins.Add("http://" + strings.ToLower(hostname))
} }
} }
glog.V(logger.Debug).Infof("Allowed origin(s) for WS RPC interface %v\n", origins.List()) glog.V(logger.Debug).Infof("Allowed origin(s) for WS RPC interface %v\n", origins.List())
f := func(cfg *websocket.Config, req *http.Request) error { f := func(cfg *websocket.Config, req *http.Request) error {
origin := req.Header.Get("Origin") origin := strings.ToLower(req.Header.Get("Origin"))
if allowAllOrigins || origins.Has(origin) { if allowAllOrigins || origins.Has(origin) {
return nil return nil
} }