container, k8s: change Account() interface

This commit is contained in:
Alan Chen 2017-09-28 16:31:22 +08:00
parent 7490ed12e8
commit ebf9c4aeba
5 changed files with 21 additions and 14 deletions

View File

@ -504,8 +504,13 @@ func (bc *blockchain) setupValidators(ips []net.IP, keys []*ecdsa.PrivateKey, of
opts = append(opts, HostWebSocketPort(freeport.GetPort())) opts = append(opts, HostWebSocketPort(freeport.GetPort()))
opts = append(opts, Key(keys[i])) opts = append(opts, Key(keys[i]))
opts = append(opts, HostIP(ips[i])) opts = append(opts, HostIP(ips[i]))
accounts := bc.accounts[i+offset : i+offset+1] 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 // Add PRIVATE_CONFIG for quorum
if bc.isQuorum { if bc.isQuorum {

View File

@ -36,7 +36,6 @@ import (
"github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/network"
docker "github.com/docker/docker/client" docker "github.com/docker/docker/client"
"github.com/docker/go-connections/nat" "github.com/docker/go-connections/nat"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types"
@ -86,7 +85,7 @@ type Ethereum interface {
StartMining() error StartMining() error
StopMining() error StopMining() error
Accounts() []accounts.Account Accounts() []common.Address
DockerEnv() []string DockerEnv() []string
DockerBinds() []string DockerBinds() []string
@ -135,7 +134,7 @@ type ethereum struct {
hostName string hostName string
containerID string containerID string
node *discover.Node node *discover.Node
accounts []accounts.Account accounts []common.Address
password string password string
//Quorum only //Quorum only
@ -672,7 +671,7 @@ func (eth *ethereum) StopMining() error {
return client.StopMining(context.Background()) return client.StopMining(context.Background())
} }
func (eth *ethereum) Accounts() []accounts.Account { func (eth *ethereum) Accounts() []common.Address {
return eth.accounts return eth.accounts
} }

View File

@ -22,8 +22,8 @@ import (
"net" "net"
"path/filepath" "path/filepath"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
) )
type Option func(*ethereum) 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) { return func(eth *ethereum) {
eth.accounts = accounts eth.accounts = accounts
} }

View File

@ -28,7 +28,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types"
@ -66,6 +65,7 @@ type ethereum struct {
nodekey string nodekey string
key *ecdsa.PrivateKey key *ecdsa.PrivateKey
accounts []*ecdsa.PrivateKey
k8sClient *kubernetes.Clientset k8sClient *kubernetes.Clientset
} }
@ -351,8 +351,11 @@ func (eth *ethereum) StopMining() error {
return nil return nil
} }
func (eth *ethereum) Accounts() []accounts.Account { func (eth *ethereum) Accounts() (addrs []common.Address) {
return nil for _, acc := range eth.accounts {
addrs = append(addrs, crypto.PubkeyToAddress(acc.PublicKey))
}
return addrs
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -72,7 +72,7 @@ var _ = Describe("QFS-08: Private transaction", func() {
acc := geth0.Accounts()[0] acc := geth0.Accounts()[0]
client0 := geth0.NewClient() client0 := geth0.NewClient()
byteCode := genByteCodeWithValue(storedValue) 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()) Expect(err).To(BeNil())
txHash = common.HexToHash(hash) txHash = common.HexToHash(hash)
}) })
@ -105,7 +105,7 @@ var _ = Describe("QFS-08: Private transaction", func() {
ct1 := constellationNetwork.GetConstellation(1) ct1 := constellationNetwork.GetConstellation(1)
pubKey1 := ct1.PublicKeys() pubKey1 := ct1.PublicKeys()
byteCode := genByteCodeWithValue(storedValue) 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()) Expect(err).To(BeNil())
txHash = common.HexToHash(hash) txHash = common.HexToHash(hash)
}) })
@ -136,7 +136,7 @@ var _ = Describe("QFS-08: Private transaction", func() {
ct3 := constellationNetwork.GetConstellation(3) ct3 := constellationNetwork.GetConstellation(3)
pubKey3 := ct3.PublicKeys() pubKey3 := ct3.PublicKeys()
byteCode := genByteCodeWithValue(storedValue) 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()) Expect(err).To(BeNil())
txHash = common.HexToHash(hash) txHash = common.HexToHash(hash)
}) })
@ -165,7 +165,7 @@ var _ = Describe("QFS-08: Private transaction", func() {
acc := geth0.Accounts()[0] acc := geth0.Accounts()[0]
client0 := geth0.NewClient() client0 := geth0.NewClient()
byteCode := genByteCodeWithValue(storedValue) 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()) Expect(err).To(BeNil())
txHash = common.HexToHash(hash) txHash = common.HexToHash(hash)
}) })