From ebf9c4aebaa96174a09b386e95384fa487c8eb8f Mon Sep 17 00:00:00 2001 From: Alan Chen Date: Thu, 28 Sep 2017 16:31:22 +0800 Subject: [PATCH] container, k8s: change Account() interface --- container/blockchain.go | 7 ++++++- container/ethereum.go | 7 +++---- container/options.go | 4 ++-- k8s/ethereum.go | 9 ++++++--- tests/quorum/functional/private_transaction_test.go | 8 ++++---- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/container/blockchain.go b/container/blockchain.go index 01c8673d..2eba1d85 100644 --- a/container/blockchain.go +++ b/container/blockchain.go @@ -504,8 +504,13 @@ func (bc *blockchain) setupValidators(ips []net.IP, keys []*ecdsa.PrivateKey, of opts = append(opts, HostWebSocketPort(freeport.GetPort())) opts = append(opts, Key(keys[i])) opts = append(opts, HostIP(ips[i])) + accounts := bc.accounts[i+offset : i+offset+1] - opts = append(opts, Accounts(accounts)) + var addrs []common.Address + for _, acc := range accounts { + addrs = append(addrs, acc.Address) + } + opts = append(opts, Accounts(addrs)) // Add PRIVATE_CONFIG for quorum if bc.isQuorum { diff --git a/container/ethereum.go b/container/ethereum.go index dfc04053..a4695990 100644 --- a/container/ethereum.go +++ b/container/ethereum.go @@ -36,7 +36,6 @@ import ( "github.com/docker/docker/api/types/network" docker "github.com/docker/docker/client" "github.com/docker/go-connections/nat" - "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" @@ -86,7 +85,7 @@ type Ethereum interface { StartMining() error StopMining() error - Accounts() []accounts.Account + Accounts() []common.Address DockerEnv() []string DockerBinds() []string @@ -135,7 +134,7 @@ type ethereum struct { hostName string containerID string node *discover.Node - accounts []accounts.Account + accounts []common.Address password string //Quorum only @@ -672,7 +671,7 @@ func (eth *ethereum) StopMining() error { return client.StopMining(context.Background()) } -func (eth *ethereum) Accounts() []accounts.Account { +func (eth *ethereum) Accounts() []common.Address { return eth.accounts } diff --git a/container/options.go b/container/options.go index f93ed1cc..b0741d4a 100644 --- a/container/options.go +++ b/container/options.go @@ -22,8 +22,8 @@ import ( "net" "path/filepath" - "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/cmd/utils" + "github.com/ethereum/go-ethereum/common" ) type Option func(*ethereum) @@ -293,7 +293,7 @@ func NoUSB() Option { } } -func Accounts(accounts []accounts.Account) Option { +func Accounts(accounts []common.Address) Option { return func(eth *ethereum) { eth.accounts = accounts } diff --git a/k8s/ethereum.go b/k8s/ethereum.go index 1d43a9df..ad6a1627 100644 --- a/k8s/ethereum.go +++ b/k8s/ethereum.go @@ -28,7 +28,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" - "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" @@ -66,6 +65,7 @@ type ethereum struct { nodekey string key *ecdsa.PrivateKey + accounts []*ecdsa.PrivateKey k8sClient *kubernetes.Clientset } @@ -351,8 +351,11 @@ func (eth *ethereum) StopMining() error { return nil } -func (eth *ethereum) Accounts() []accounts.Account { - return nil +func (eth *ethereum) Accounts() (addrs []common.Address) { + for _, acc := range eth.accounts { + addrs = append(addrs, crypto.PubkeyToAddress(acc.PublicKey)) + } + return addrs } // ---------------------------------------------------------------------------- diff --git a/tests/quorum/functional/private_transaction_test.go b/tests/quorum/functional/private_transaction_test.go index 4c532382..6961fdc0 100644 --- a/tests/quorum/functional/private_transaction_test.go +++ b/tests/quorum/functional/private_transaction_test.go @@ -72,7 +72,7 @@ var _ = Describe("QFS-08: Private transaction", func() { acc := geth0.Accounts()[0] client0 := geth0.NewClient() byteCode := genByteCodeWithValue(storedValue) - hash, err := client0.CreateContract(context.Background(), acc.Address, byteCode, big.NewInt(300000)) + hash, err := client0.CreateContract(context.Background(), acc, byteCode, big.NewInt(300000)) Expect(err).To(BeNil()) txHash = common.HexToHash(hash) }) @@ -105,7 +105,7 @@ var _ = Describe("QFS-08: Private transaction", func() { ct1 := constellationNetwork.GetConstellation(1) pubKey1 := ct1.PublicKeys() byteCode := genByteCodeWithValue(storedValue) - hash, err := client0.CreatePrivateContract(context.Background(), acc.Address, byteCode, big.NewInt(300000), pubKey1) + hash, err := client0.CreatePrivateContract(context.Background(), acc, byteCode, big.NewInt(300000), pubKey1) Expect(err).To(BeNil()) txHash = common.HexToHash(hash) }) @@ -136,7 +136,7 @@ var _ = Describe("QFS-08: Private transaction", func() { ct3 := constellationNetwork.GetConstellation(3) pubKey3 := ct3.PublicKeys() byteCode := genByteCodeWithValue(storedValue) - hash, err := client2.CreatePrivateContract(context.Background(), acc.Address, byteCode, big.NewInt(300000), pubKey3) + hash, err := client2.CreatePrivateContract(context.Background(), acc, byteCode, big.NewInt(300000), pubKey3) Expect(err).To(BeNil()) txHash = common.HexToHash(hash) }) @@ -165,7 +165,7 @@ var _ = Describe("QFS-08: Private transaction", func() { acc := geth0.Accounts()[0] client0 := geth0.NewClient() byteCode := genByteCodeWithValue(storedValue) - hash, err := client0.CreateContract(context.Background(), acc.Address, byteCode, big.NewInt(300000)) + hash, err := client0.CreateContract(context.Background(), acc, byteCode, big.NewInt(300000)) Expect(err).To(BeNil()) txHash = common.HexToHash(hash) })