aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--accounts/abi/bind/base.go5
-rw-r--r--accounts/abi/bind/bind_test.go39
-rw-r--r--internal/ethapi/backend.go4
-rw-r--r--internal/ethapi/solc.go82
-rw-r--r--rpc/http.go1
-rw-r--r--swarm/api/http/server.go1
-rw-r--r--swarm/network/kademlia/kademlia.go2
7 files changed, 46 insertions, 88 deletions
diff --git a/accounts/abi/bind/base.go b/accounts/abi/bind/base.go
index 1f11827dd..93362d9e9 100644
--- a/accounts/abi/bind/base.go
+++ b/accounts/abi/bind/base.go
@@ -35,7 +35,8 @@ type SignerFn func(types.Signer, common.Address, *types.Transaction) (*types.Tra
// CallOpts is the collection of options to fine tune a contract call request.
type CallOpts struct {
- Pending bool // Whether to operate on the pending state or the last known one
+ Pending bool // Whether to operate on the pending state or the last known one
+ From common.Address // Optional the sender address, otherwise the first account is used
Context context.Context // Network context to support cancellation and timeouts (nil = no timeout)
}
@@ -108,7 +109,7 @@ func (c *BoundContract) Call(opts *CallOpts, result interface{}, method string,
return err
}
var (
- msg = ethereum.CallMsg{To: &c.address, Data: input}
+ msg = ethereum.CallMsg{From: opts.From, To: &c.address, Data: input}
ctx = ensureContext(opts.Context)
code []byte
output []byte
diff --git a/accounts/abi/bind/bind_test.go b/accounts/abi/bind/bind_test.go
index eb46bc081..8ac4aa44e 100644
--- a/accounts/abi/bind/bind_test.go
+++ b/accounts/abi/bind/bind_test.go
@@ -408,6 +408,45 @@ var bindTests = []struct {
}
`,
},
+ // Test that constant functions can be called from an (optional) specified address
+ {
+ `CallFrom`,
+ `
+ contract CallFrom {
+ function callFrom() constant returns(address) {
+ return msg.sender;
+ }
+ }
+ `, `6060604052346000575b6086806100176000396000f300606060405263ffffffff60e060020a60003504166349f8e98281146022575b6000565b34600057602c6055565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b335b905600a165627a7a72305820aef6b7685c0fa24ba6027e4870404a57df701473fe4107741805c19f5138417c0029`,
+ `[{"constant":true,"inputs":[],"name":"callFrom","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"}]`,
+ `
+ // Generate a new random account and a funded simulator
+ key, _ := crypto.GenerateKey()
+ auth := bind.NewKeyedTransactor(key)
+ sim := backends.NewSimulatedBackend(core.GenesisAccount{Address: auth.From, Balance: big.NewInt(10000000000)})
+
+ // Deploy a sender tester contract and execute a structured call on it
+ _, _, callfrom, err := DeployCallFrom(auth, sim)
+ if err != nil {
+ t.Fatalf("Failed to deploy sender contract: %v", err)
+ }
+ sim.Commit()
+
+ if res, err := callfrom.CallFrom(nil); err != nil {
+ t.Errorf("Failed to call constant function: %v", err)
+ } else if res != (common.Address{}) {
+ t.Errorf("Invalid address returned, want: %x, got: %x", (common.Address{}), res)
+ }
+
+ for _, addr := range []common.Address{common.Address{}, common.Address{1}, common.Address{2}} {
+ if res, err := callfrom.CallFrom(&bind.CallOpts{From: addr}); err != nil {
+ t.Fatalf("Failed to call constant function: %v", err)
+ } else if res != addr {
+ t.Fatalf("Invalid address returned, want: %x, got: %x", addr, res)
+ }
+ }
+ `,
+ },
}
// Tests that packages generated by the binder can be successfully compiled and
diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go
index 214214f51..e10fb14ff 100644
--- a/internal/ethapi/backend.go
+++ b/internal/ethapi/backend.go
@@ -73,8 +73,7 @@ type State interface {
}
func GetAPIs(apiBackend Backend, solcPath string) []rpc.API {
- compiler := makeCompilerAPIs(solcPath)
- all := []rpc.API{
+ return []rpc.API{
{
Namespace: "eth",
Version: "1.0",
@@ -116,5 +115,4 @@ func GetAPIs(apiBackend Backend, solcPath string) []rpc.API {
Public: false,
},
}
- return append(compiler, all...)
}
diff --git a/internal/ethapi/solc.go b/internal/ethapi/solc.go
deleted file mode 100644
index b9acc518b..000000000
--- a/internal/ethapi/solc.go
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package ethapi
-
-import (
- "sync"
-
- "github.com/ethereum/go-ethereum/common/compiler"
- "github.com/ethereum/go-ethereum/rpc"
-)
-
-func makeCompilerAPIs(solcPath string) []rpc.API {
- c := &compilerAPI{solc: solcPath}
- return []rpc.API{
- {
- Namespace: "eth",
- Version: "1.0",
- Service: (*PublicCompilerAPI)(c),
- Public: true,
- },
- {
- Namespace: "admin",
- Version: "1.0",
- Service: (*CompilerAdminAPI)(c),
- Public: true,
- },
- }
-}
-
-type compilerAPI struct {
- // This lock guards the solc path set through the API.
- // It also ensures that only one solc process is used at
- // any time.
- mu sync.Mutex
- solc string
-}
-
-type CompilerAdminAPI compilerAPI
-
-// SetSolc sets the Solidity compiler path to be used by the node.
-func (api *CompilerAdminAPI) SetSolc(path string) (string, error) {
- api.mu.Lock()
- defer api.mu.Unlock()
- info, err := compiler.SolidityVersion(path)
- if err != nil {
- return "", err
- }
- api.solc = path
- return info.FullVersion, nil
-}
-
-type PublicCompilerAPI compilerAPI
-
-// CompileSolidity compiles the given solidity source.
-func (api *PublicCompilerAPI) CompileSolidity(source string) (map[string]*compiler.Contract, error) {
- api.mu.Lock()
- defer api.mu.Unlock()
- return compiler.CompileSolidityString(api.solc, source)
-}
-
-func (api *PublicCompilerAPI) GetCompilers() ([]string, error) {
- api.mu.Lock()
- defer api.mu.Unlock()
- if _, err := compiler.SolidityVersion(api.solc); err == nil {
- return []string{"Solidity"}, nil
- }
- return []string{}, nil
-}
diff --git a/rpc/http.go b/rpc/http.go
index 7d4fe5d47..5a0770231 100644
--- a/rpc/http.go
+++ b/rpc/http.go
@@ -171,6 +171,7 @@ func newCorsHandler(srv *Server, corsString string) http.Handler {
AllowedOrigins: allowedOrigins,
AllowedMethods: []string{"POST", "GET"},
MaxAge: 600,
+ AllowedHeaders: []string{"*"},
})
return c.Handler(srv)
}
diff --git a/swarm/api/http/server.go b/swarm/api/http/server.go
index a61696678..ae113750f 100644
--- a/swarm/api/http/server.go
+++ b/swarm/api/http/server.go
@@ -82,6 +82,7 @@ func StartHttpServer(api *api.Api, server *Server) {
AllowedOrigins: allowedOrigins,
AllowedMethods: []string{"POST", "GET", "DELETE", "PATCH", "PUT"},
MaxAge: 600,
+ AllowedHeaders: []string{"*"},
})
hdlr := c.Handler(serveMux)
diff --git a/swarm/network/kademlia/kademlia.go b/swarm/network/kademlia/kademlia.go
index 8d731c038..bf976a3e1 100644
--- a/swarm/network/kademlia/kademlia.go
+++ b/swarm/network/kademlia/kademlia.go
@@ -116,7 +116,7 @@ func (self *Kademlia) DBCount() int {
// On is the entry point called when a new nodes is added
// unsafe in that node is not checked to be already active node (to be called once)
func (self *Kademlia) On(node Node, cb func(*NodeRecord, Node) error) (err error) {
- log.Warn(fmt.Sprintf("%v", self))
+ log.Debug(fmt.Sprintf("%v", self))
defer self.lock.Unlock()
self.lock.Lock()