mirror of https://github.com/ethereum/go-ethereum
Merge with changes that implement config file PR #15548. Field *EnsApi string* in swarm/api.Config is replaced with *EnsAPIs []string*. A new field *EnsDisabled bool* is added to swarm/api.Config for easy way to disable ENS resolving with config file. Signature of function swarm.NewSwarm is changed and simplified.pull/15748/head
commit
19982f9467
@ -0,0 +1,9 @@ |
||||
# Lines starting with '#' are comments. |
||||
# Each line is a file pattern followed by one or more owners. |
||||
|
||||
accounts/usbwallet @karalabe |
||||
consensus @karalabe |
||||
core/ @karalabe @holiman |
||||
eth/ @karalabe |
||||
mobile/ @karalabe |
||||
p2p/ @fjl @zsfelfoldi |
@ -0,0 +1,102 @@ |
||||
// Copyright 2017 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 keystore |
||||
|
||||
import ( |
||||
"io/ioutil" |
||||
"os" |
||||
"path/filepath" |
||||
"strings" |
||||
"sync" |
||||
"time" |
||||
|
||||
"github.com/ethereum/go-ethereum/log" |
||||
set "gopkg.in/fatih/set.v0" |
||||
) |
||||
|
||||
// fileCache is a cache of files seen during scan of keystore.
|
||||
type fileCache struct { |
||||
all *set.SetNonTS // Set of all files from the keystore folder
|
||||
lastMod time.Time // Last time instance when a file was modified
|
||||
mu sync.RWMutex |
||||
} |
||||
|
||||
// scan performs a new scan on the given directory, compares against the already
|
||||
// cached filenames, and returns file sets: creates, deletes, updates.
|
||||
func (fc *fileCache) scan(keyDir string) (set.Interface, set.Interface, set.Interface, error) { |
||||
t0 := time.Now() |
||||
|
||||
// List all the failes from the keystore folder
|
||||
files, err := ioutil.ReadDir(keyDir) |
||||
if err != nil { |
||||
return nil, nil, nil, err |
||||
} |
||||
t1 := time.Now() |
||||
|
||||
fc.mu.Lock() |
||||
defer fc.mu.Unlock() |
||||
|
||||
// Iterate all the files and gather their metadata
|
||||
all := set.NewNonTS() |
||||
mods := set.NewNonTS() |
||||
|
||||
var newLastMod time.Time |
||||
for _, fi := range files { |
||||
// Skip any non-key files from the folder
|
||||
path := filepath.Join(keyDir, fi.Name()) |
||||
if skipKeyFile(fi) { |
||||
log.Trace("Ignoring file on account scan", "path", path) |
||||
continue |
||||
} |
||||
// Gather the set of all and fresly modified files
|
||||
all.Add(path) |
||||
|
||||
modified := fi.ModTime() |
||||
if modified.After(fc.lastMod) { |
||||
mods.Add(path) |
||||
} |
||||
if modified.After(newLastMod) { |
||||
newLastMod = modified |
||||
} |
||||
} |
||||
t2 := time.Now() |
||||
|
||||
// Update the tracked files and return the three sets
|
||||
deletes := set.Difference(fc.all, all) // Deletes = previous - current
|
||||
creates := set.Difference(all, fc.all) // Creates = current - previous
|
||||
updates := set.Difference(mods, creates) // Updates = modified - creates
|
||||
|
||||
fc.all, fc.lastMod = all, newLastMod |
||||
t3 := time.Now() |
||||
|
||||
// Report on the scanning stats and return
|
||||
log.Debug("FS scan times", "list", t1.Sub(t0), "set", t2.Sub(t1), "diff", t3.Sub(t2)) |
||||
return creates, deletes, updates, nil |
||||
} |
||||
|
||||
// skipKeyFile ignores editor backups, hidden files and folders/symlinks.
|
||||
func skipKeyFile(fi os.FileInfo) bool { |
||||
// Skip editor backups and UNIX-style hidden files.
|
||||
if strings.HasSuffix(fi.Name(), "~") || strings.HasPrefix(fi.Name(), ".") { |
||||
return true |
||||
} |
||||
// Skip misc special files, directories (yes, symlinks too).
|
||||
if fi.IsDir() || fi.Mode()&os.ModeType != 0 { |
||||
return true |
||||
} |
||||
return false |
||||
} |
File diff suppressed because one or more lines are too long
@ -0,0 +1,379 @@ |
||||
// Copyright 2017 The go-ethereum Authors
|
||||
// This file is part of go-ethereum.
|
||||
//
|
||||
// go-ethereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// go-ethereum 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 General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"encoding/binary" |
||||
"errors" |
||||
"math" |
||||
|
||||
"github.com/ethereum/go-ethereum/common" |
||||
"github.com/ethereum/go-ethereum/common/hexutil" |
||||
"github.com/ethereum/go-ethereum/consensus/ethash" |
||||
"github.com/ethereum/go-ethereum/core" |
||||
"github.com/ethereum/go-ethereum/params" |
||||
) |
||||
|
||||
// cppEthereumGenesisSpec represents the genesis specification format used by the
|
||||
// C++ Ethereum implementation.
|
||||
type cppEthereumGenesisSpec struct { |
||||
SealEngine string `json:"sealEngine"` |
||||
Params struct { |
||||
AccountStartNonce hexutil.Uint64 `json:"accountStartNonce"` |
||||
HomesteadForkBlock hexutil.Uint64 `json:"homesteadForkBlock"` |
||||
EIP150ForkBlock hexutil.Uint64 `json:"EIP150ForkBlock"` |
||||
EIP158ForkBlock hexutil.Uint64 `json:"EIP158ForkBlock"` |
||||
ByzantiumForkBlock hexutil.Uint64 `json:"byzantiumForkBlock"` |
||||
ConstantinopleForkBlock hexutil.Uint64 `json:"constantinopleForkBlock"` |
||||
NetworkID hexutil.Uint64 `json:"networkID"` |
||||
ChainID hexutil.Uint64 `json:"chainID"` |
||||
MaximumExtraDataSize hexutil.Uint64 `json:"maximumExtraDataSize"` |
||||
MinGasLimit hexutil.Uint64 `json:"minGasLimit"` |
||||
MaxGasLimit hexutil.Uint64 `json:"maxGasLimit"` |
||||
GasLimitBoundDivisor *hexutil.Big `json:"gasLimitBoundDivisor"` |
||||
MinimumDifficulty *hexutil.Big `json:"minimumDifficulty"` |
||||
DifficultyBoundDivisor *hexutil.Big `json:"difficultyBoundDivisor"` |
||||
DurationLimit *hexutil.Big `json:"durationLimit"` |
||||
BlockReward *hexutil.Big `json:"blockReward"` |
||||
} `json:"params"` |
||||
|
||||
Genesis struct { |
||||
Nonce hexutil.Bytes `json:"nonce"` |
||||
Difficulty *hexutil.Big `json:"difficulty"` |
||||
MixHash common.Hash `json:"mixHash"` |
||||
Author common.Address `json:"author"` |
||||
Timestamp hexutil.Uint64 `json:"timestamp"` |
||||
ParentHash common.Hash `json:"parentHash"` |
||||
ExtraData hexutil.Bytes `json:"extraData"` |
||||
GasLimit hexutil.Uint64 `json:"gasLimit"` |
||||
} `json:"genesis"` |
||||
|
||||
Accounts map[common.Address]*cppEthereumGenesisSpecAccount `json:"accounts"` |
||||
} |
||||
|
||||
// cppEthereumGenesisSpecAccount is the prefunded genesis account and/or precompiled
|
||||
// contract definition.
|
||||
type cppEthereumGenesisSpecAccount struct { |
||||
Balance *hexutil.Big `json:"balance"` |
||||
Nonce uint64 `json:"nonce,omitempty"` |
||||
Precompiled *cppEthereumGenesisSpecBuiltin `json:"precompiled,omitempty"` |
||||
} |
||||
|
||||
// cppEthereumGenesisSpecBuiltin is the precompiled contract definition.
|
||||
type cppEthereumGenesisSpecBuiltin struct { |
||||
Name string `json:"name,omitempty"` |
||||
StartingBlock hexutil.Uint64 `json:"startingBlock,omitempty"` |
||||
Linear *cppEthereumGenesisSpecLinearPricing `json:"linear,omitempty"` |
||||
} |
||||
|
||||
type cppEthereumGenesisSpecLinearPricing struct { |
||||
Base uint64 `json:"base"` |
||||
Word uint64 `json:"word"` |
||||
} |
||||
|
||||
// newCppEthereumGenesisSpec converts a go-ethereum genesis block into a Parity specific
|
||||
// chain specification format.
|
||||
func newCppEthereumGenesisSpec(network string, genesis *core.Genesis) (*cppEthereumGenesisSpec, error) { |
||||
// Only ethash is currently supported between go-ethereum and cpp-ethereum
|
||||
if genesis.Config.Ethash == nil { |
||||
return nil, errors.New("unsupported consensus engine") |
||||
} |
||||
// Reconstruct the chain spec in Parity's format
|
||||
spec := &cppEthereumGenesisSpec{ |
||||
SealEngine: "Ethash", |
||||
} |
||||
spec.Params.AccountStartNonce = 0 |
||||
spec.Params.HomesteadForkBlock = (hexutil.Uint64)(genesis.Config.HomesteadBlock.Uint64()) |
||||
spec.Params.EIP150ForkBlock = (hexutil.Uint64)(genesis.Config.EIP150Block.Uint64()) |
||||
spec.Params.EIP158ForkBlock = (hexutil.Uint64)(genesis.Config.EIP158Block.Uint64()) |
||||
spec.Params.ByzantiumForkBlock = (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64()) |
||||
spec.Params.ConstantinopleForkBlock = (hexutil.Uint64)(math.MaxUint64) |
||||
|
||||
spec.Params.NetworkID = (hexutil.Uint64)(genesis.Config.ChainId.Uint64()) |
||||
spec.Params.ChainID = (hexutil.Uint64)(genesis.Config.ChainId.Uint64()) |
||||
|
||||
spec.Params.MaximumExtraDataSize = (hexutil.Uint64)(params.MaximumExtraDataSize) |
||||
spec.Params.MinGasLimit = (hexutil.Uint64)(params.MinGasLimit.Uint64()) |
||||
spec.Params.MaxGasLimit = (hexutil.Uint64)(math.MaxUint64) |
||||
spec.Params.MinimumDifficulty = (*hexutil.Big)(params.MinimumDifficulty) |
||||
spec.Params.DifficultyBoundDivisor = (*hexutil.Big)(params.DifficultyBoundDivisor) |
||||
spec.Params.GasLimitBoundDivisor = (*hexutil.Big)(params.GasLimitBoundDivisor) |
||||
spec.Params.DurationLimit = (*hexutil.Big)(params.DurationLimit) |
||||
spec.Params.BlockReward = (*hexutil.Big)(ethash.FrontierBlockReward) |
||||
|
||||
spec.Genesis.Nonce = (hexutil.Bytes)(make([]byte, 8)) |
||||
binary.LittleEndian.PutUint64(spec.Genesis.Nonce[:], genesis.Nonce) |
||||
|
||||
spec.Genesis.MixHash = genesis.Mixhash |
||||
spec.Genesis.Difficulty = (*hexutil.Big)(genesis.Difficulty) |
||||
spec.Genesis.Author = genesis.Coinbase |
||||
spec.Genesis.Timestamp = (hexutil.Uint64)(genesis.Timestamp) |
||||
spec.Genesis.ParentHash = genesis.ParentHash |
||||
spec.Genesis.ExtraData = (hexutil.Bytes)(genesis.ExtraData) |
||||
spec.Genesis.GasLimit = (hexutil.Uint64)(genesis.GasLimit) |
||||
|
||||
spec.Accounts = make(map[common.Address]*cppEthereumGenesisSpecAccount) |
||||
for address, account := range genesis.Alloc { |
||||
spec.Accounts[address] = &cppEthereumGenesisSpecAccount{ |
||||
Balance: (*hexutil.Big)(account.Balance), |
||||
Nonce: account.Nonce, |
||||
} |
||||
} |
||||
spec.Accounts[common.BytesToAddress([]byte{1})].Precompiled = &cppEthereumGenesisSpecBuiltin{ |
||||
Name: "ecrecover", Linear: &cppEthereumGenesisSpecLinearPricing{Base: 3000}, |
||||
} |
||||
spec.Accounts[common.BytesToAddress([]byte{2})].Precompiled = &cppEthereumGenesisSpecBuiltin{ |
||||
Name: "sha256", Linear: &cppEthereumGenesisSpecLinearPricing{Base: 60, Word: 12}, |
||||
} |
||||
spec.Accounts[common.BytesToAddress([]byte{3})].Precompiled = &cppEthereumGenesisSpecBuiltin{ |
||||
Name: "ripemd160", Linear: &cppEthereumGenesisSpecLinearPricing{Base: 600, Word: 120}, |
||||
} |
||||
spec.Accounts[common.BytesToAddress([]byte{4})].Precompiled = &cppEthereumGenesisSpecBuiltin{ |
||||
Name: "identity", Linear: &cppEthereumGenesisSpecLinearPricing{Base: 15, Word: 3}, |
||||
} |
||||
if genesis.Config.ByzantiumBlock != nil { |
||||
spec.Accounts[common.BytesToAddress([]byte{5})].Precompiled = &cppEthereumGenesisSpecBuiltin{ |
||||
Name: "modexp", StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64()), |
||||
} |
||||
spec.Accounts[common.BytesToAddress([]byte{6})].Precompiled = &cppEthereumGenesisSpecBuiltin{ |
||||
Name: "alt_bn128_G1_add", StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64()), Linear: &cppEthereumGenesisSpecLinearPricing{Base: 500}, |
||||
} |
||||
spec.Accounts[common.BytesToAddress([]byte{7})].Precompiled = &cppEthereumGenesisSpecBuiltin{ |
||||
Name: "alt_bn128_G1_mul", StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64()), Linear: &cppEthereumGenesisSpecLinearPricing{Base: 40000}, |
||||
} |
||||
spec.Accounts[common.BytesToAddress([]byte{8})].Precompiled = &cppEthereumGenesisSpecBuiltin{ |
||||
Name: "alt_bn128_pairing_product", StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64()), |
||||
} |
||||
} |
||||
return spec, nil |
||||
} |
||||
|
||||
// parityChainSpec is the chain specification format used by Parity.
|
||||
type parityChainSpec struct { |
||||
Name string `json:"name"` |
||||
Engine struct { |
||||
Ethash struct { |
||||
Params struct { |
||||
MinimumDifficulty *hexutil.Big `json:"minimumDifficulty"` |
||||
DifficultyBoundDivisor *hexutil.Big `json:"difficultyBoundDivisor"` |
||||
GasLimitBoundDivisor *hexutil.Big `json:"gasLimitBoundDivisor"` |
||||
DurationLimit *hexutil.Big `json:"durationLimit"` |
||||
BlockReward *hexutil.Big `json:"blockReward"` |
||||
HomesteadTransition uint64 `json:"homesteadTransition"` |
||||
EIP150Transition uint64 `json:"eip150Transition"` |
||||
EIP160Transition uint64 `json:"eip160Transition"` |
||||
EIP161abcTransition uint64 `json:"eip161abcTransition"` |
||||
EIP161dTransition uint64 `json:"eip161dTransition"` |
||||
EIP649Reward *hexutil.Big `json:"eip649Reward"` |
||||
EIP100bTransition uint64 `json:"eip100bTransition"` |
||||
EIP649Transition uint64 `json:"eip649Transition"` |
||||
} `json:"params"` |
||||
} `json:"Ethash"` |
||||
} `json:"engine"` |
||||
|
||||
Params struct { |
||||
MaximumExtraDataSize hexutil.Uint64 `json:"maximumExtraDataSize"` |
||||
MinGasLimit *hexutil.Big `json:"minGasLimit"` |
||||
NetworkID hexutil.Uint64 `json:"networkID"` |
||||
MaxCodeSize uint64 `json:"maxCodeSize"` |
||||
EIP155Transition uint64 `json:"eip155Transition"` |
||||
EIP98Transition uint64 `json:"eip98Transition"` |
||||
EIP86Transition uint64 `json:"eip86Transition"` |
||||
EIP140Transition uint64 `json:"eip140Transition"` |
||||
EIP211Transition uint64 `json:"eip211Transition"` |
||||
EIP214Transition uint64 `json:"eip214Transition"` |
||||
EIP658Transition uint64 `json:"eip658Transition"` |
||||
} `json:"params"` |
||||
|
||||
Genesis struct { |
||||
Seal struct { |
||||
Ethereum struct { |
||||
Nonce hexutil.Bytes `json:"nonce"` |
||||
MixHash hexutil.Bytes `json:"mixHash"` |
||||
} `json:"ethereum"` |
||||
} `json:"seal"` |
||||
|
||||
Difficulty *hexutil.Big `json:"difficulty"` |
||||
Author common.Address `json:"author"` |
||||
Timestamp hexutil.Uint64 `json:"timestamp"` |
||||
ParentHash common.Hash `json:"parentHash"` |
||||
ExtraData hexutil.Bytes `json:"extraData"` |
||||
GasLimit hexutil.Uint64 `json:"gasLimit"` |
||||
} `json:"genesis"` |
||||
|
||||
Nodes []string `json:"nodes"` |
||||
Accounts map[common.Address]*parityChainSpecAccount `json:"accounts"` |
||||
} |
||||
|
||||
// parityChainSpecAccount is the prefunded genesis account and/or precompiled
|
||||
// contract definition.
|
||||
type parityChainSpecAccount struct { |
||||
Balance *hexutil.Big `json:"balance"` |
||||
Nonce uint64 `json:"nonce,omitempty"` |
||||
Builtin *parityChainSpecBuiltin `json:"builtin,omitempty"` |
||||
} |
||||
|
||||
// parityChainSpecBuiltin is the precompiled contract definition.
|
||||
type parityChainSpecBuiltin struct { |
||||
Name string `json:"name,omitempty"` |
||||
ActivateAt uint64 `json:"activate_at,omitempty"` |
||||
Pricing *parityChainSpecPricing `json:"pricing,omitempty"` |
||||
} |
||||
|
||||
// parityChainSpecPricing represents the different pricing models that builtin
|
||||
// contracts might advertise using.
|
||||
type parityChainSpecPricing struct { |
||||
Linear *parityChainSpecLinearPricing `json:"linear,omitempty"` |
||||
ModExp *parityChainSpecModExpPricing `json:"modexp,omitempty"` |
||||
AltBnPairing *parityChainSpecAltBnPairingPricing `json:"alt_bn128_pairing,omitempty"` |
||||
} |
||||
|
||||
type parityChainSpecLinearPricing struct { |
||||
Base uint64 `json:"base"` |
||||
Word uint64 `json:"word"` |
||||
} |
||||
|
||||
type parityChainSpecModExpPricing struct { |
||||
Divisor uint64 `json:"divisor"` |
||||
} |
||||
|
||||
type parityChainSpecAltBnPairingPricing struct { |
||||
Base uint64 `json:"base"` |
||||
Pair uint64 `json:"pair"` |
||||
} |
||||
|
||||
// newParityChainSpec converts a go-ethereum genesis block into a Parity specific
|
||||
// chain specification format.
|
||||
func newParityChainSpec(network string, genesis *core.Genesis, bootnodes []string) (*parityChainSpec, error) { |
||||
// Only ethash is currently supported between go-ethereum and Parity
|
||||
if genesis.Config.Ethash == nil { |
||||
return nil, errors.New("unsupported consensus engine") |
||||
} |
||||
// Reconstruct the chain spec in Parity's format
|
||||
spec := &parityChainSpec{ |
||||
Name: network, |
||||
Nodes: bootnodes, |
||||
} |
||||
spec.Engine.Ethash.Params.MinimumDifficulty = (*hexutil.Big)(params.MinimumDifficulty) |
||||
spec.Engine.Ethash.Params.DifficultyBoundDivisor = (*hexutil.Big)(params.DifficultyBoundDivisor) |
||||
spec.Engine.Ethash.Params.GasLimitBoundDivisor = (*hexutil.Big)(params.GasLimitBoundDivisor) |
||||
spec.Engine.Ethash.Params.DurationLimit = (*hexutil.Big)(params.DurationLimit) |
||||
spec.Engine.Ethash.Params.BlockReward = (*hexutil.Big)(ethash.FrontierBlockReward) |
||||
spec.Engine.Ethash.Params.HomesteadTransition = genesis.Config.HomesteadBlock.Uint64() |
||||
spec.Engine.Ethash.Params.EIP150Transition = genesis.Config.EIP150Block.Uint64() |
||||
spec.Engine.Ethash.Params.EIP160Transition = genesis.Config.EIP155Block.Uint64() |
||||
spec.Engine.Ethash.Params.EIP161abcTransition = genesis.Config.EIP158Block.Uint64() |
||||
spec.Engine.Ethash.Params.EIP161dTransition = genesis.Config.EIP158Block.Uint64() |
||||
spec.Engine.Ethash.Params.EIP649Reward = (*hexutil.Big)(ethash.ByzantiumBlockReward) |
||||
spec.Engine.Ethash.Params.EIP100bTransition = genesis.Config.ByzantiumBlock.Uint64() |
||||
spec.Engine.Ethash.Params.EIP649Transition = genesis.Config.ByzantiumBlock.Uint64() |
||||
|
||||
spec.Params.MaximumExtraDataSize = (hexutil.Uint64)(params.MaximumExtraDataSize) |
||||
spec.Params.MinGasLimit = (*hexutil.Big)(params.MinGasLimit) |
||||
spec.Params.NetworkID = (hexutil.Uint64)(genesis.Config.ChainId.Uint64()) |
||||
spec.Params.MaxCodeSize = params.MaxCodeSize |
||||
spec.Params.EIP155Transition = genesis.Config.EIP155Block.Uint64() |
||||
spec.Params.EIP98Transition = math.MaxUint64 |
||||
spec.Params.EIP86Transition = math.MaxUint64 |
||||
spec.Params.EIP140Transition = genesis.Config.ByzantiumBlock.Uint64() |
||||
spec.Params.EIP211Transition = genesis.Config.ByzantiumBlock.Uint64() |
||||
spec.Params.EIP214Transition = genesis.Config.ByzantiumBlock.Uint64() |
||||
spec.Params.EIP658Transition = genesis.Config.ByzantiumBlock.Uint64() |
||||
|
||||
spec.Genesis.Seal.Ethereum.Nonce = (hexutil.Bytes)(make([]byte, 8)) |
||||
binary.LittleEndian.PutUint64(spec.Genesis.Seal.Ethereum.Nonce[:], genesis.Nonce) |
||||
|
||||
spec.Genesis.Seal.Ethereum.MixHash = (hexutil.Bytes)(genesis.Mixhash[:]) |
||||
spec.Genesis.Difficulty = (*hexutil.Big)(genesis.Difficulty) |
||||
spec.Genesis.Author = genesis.Coinbase |
||||
spec.Genesis.Timestamp = (hexutil.Uint64)(genesis.Timestamp) |
||||
spec.Genesis.ParentHash = genesis.ParentHash |
||||
spec.Genesis.ExtraData = (hexutil.Bytes)(genesis.ExtraData) |
||||
spec.Genesis.GasLimit = (hexutil.Uint64)(genesis.GasLimit) |
||||
|
||||
spec.Accounts = make(map[common.Address]*parityChainSpecAccount) |
||||
for address, account := range genesis.Alloc { |
||||
spec.Accounts[address] = &parityChainSpecAccount{ |
||||
Balance: (*hexutil.Big)(account.Balance), |
||||
Nonce: account.Nonce, |
||||
} |
||||
} |
||||
spec.Accounts[common.BytesToAddress([]byte{1})].Builtin = &parityChainSpecBuiltin{ |
||||
Name: "ecrecover", Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 3000}}, |
||||
} |
||||
spec.Accounts[common.BytesToAddress([]byte{2})].Builtin = &parityChainSpecBuiltin{ |
||||
Name: "sha256", Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 60, Word: 12}}, |
||||
} |
||||
spec.Accounts[common.BytesToAddress([]byte{3})].Builtin = &parityChainSpecBuiltin{ |
||||
Name: "ripemd160", Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 600, Word: 120}}, |
||||
} |
||||
spec.Accounts[common.BytesToAddress([]byte{4})].Builtin = &parityChainSpecBuiltin{ |
||||
Name: "identity", Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 15, Word: 3}}, |
||||
} |
||||
if genesis.Config.ByzantiumBlock != nil { |
||||
spec.Accounts[common.BytesToAddress([]byte{5})].Builtin = &parityChainSpecBuiltin{ |
||||
Name: "modexp", ActivateAt: genesis.Config.ByzantiumBlock.Uint64(), Pricing: &parityChainSpecPricing{ModExp: &parityChainSpecModExpPricing{Divisor: 20}}, |
||||
} |
||||
spec.Accounts[common.BytesToAddress([]byte{6})].Builtin = &parityChainSpecBuiltin{ |
||||
Name: "alt_bn128_add", ActivateAt: genesis.Config.ByzantiumBlock.Uint64(), Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 500}}, |
||||
} |
||||
spec.Accounts[common.BytesToAddress([]byte{7})].Builtin = &parityChainSpecBuiltin{ |
||||
Name: "alt_bn128_mul", ActivateAt: genesis.Config.ByzantiumBlock.Uint64(), Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 40000}}, |
||||
} |
||||
spec.Accounts[common.BytesToAddress([]byte{8})].Builtin = &parityChainSpecBuiltin{ |
||||
Name: "alt_bn128_pairing", ActivateAt: genesis.Config.ByzantiumBlock.Uint64(), Pricing: &parityChainSpecPricing{AltBnPairing: &parityChainSpecAltBnPairingPricing{Base: 100000, Pair: 80000}}, |
||||
} |
||||
} |
||||
return spec, nil |
||||
} |
||||
|
||||
// pyEthereumGenesisSpec represents the genesis specification format used by the
|
||||
// Python Ethereum implementation.
|
||||
type pyEthereumGenesisSpec struct { |
||||
Nonce hexutil.Bytes `json:"nonce"` |
||||
Timestamp hexutil.Uint64 `json:"timestamp"` |
||||
ExtraData hexutil.Bytes `json:"extraData"` |
||||
GasLimit hexutil.Uint64 `json:"gasLimit"` |
||||
Difficulty *hexutil.Big `json:"difficulty"` |
||||
Mixhash common.Hash `json:"mixhash"` |
||||
Coinbase common.Address `json:"coinbase"` |
||||
Alloc core.GenesisAlloc `json:"alloc"` |
||||
ParentHash common.Hash `json:"parentHash"` |
||||
} |
||||
|
||||
// newPyEthereumGenesisSpec converts a go-ethereum genesis block into a Parity specific
|
||||
// chain specification format.
|
||||
func newPyEthereumGenesisSpec(network string, genesis *core.Genesis) (*pyEthereumGenesisSpec, error) { |
||||
// Only ethash is currently supported between go-ethereum and pyethereum
|
||||
if genesis.Config.Ethash == nil { |
||||
return nil, errors.New("unsupported consensus engine") |
||||
} |
||||
spec := &pyEthereumGenesisSpec{ |
||||
Timestamp: (hexutil.Uint64)(genesis.Timestamp), |
||||
ExtraData: genesis.ExtraData, |
||||
GasLimit: (hexutil.Uint64)(genesis.GasLimit), |
||||
Difficulty: (*hexutil.Big)(genesis.Difficulty), |
||||
Mixhash: genesis.Mixhash, |
||||
Coinbase: genesis.Coinbase, |
||||
Alloc: genesis.Alloc, |
||||
ParentHash: genesis.ParentHash, |
||||
} |
||||
spec.Nonce = (hexutil.Bytes)(make([]byte, 8)) |
||||
binary.LittleEndian.PutUint64(spec.Nonce[:], genesis.Nonce) |
||||
|
||||
return spec, nil |
||||
} |
@ -0,0 +1,211 @@ |
||||
// Copyright 2017 The go-ethereum Authors
|
||||
// This file is part of go-ethereum.
|
||||
//
|
||||
// go-ethereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// go-ethereum 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 General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"bytes" |
||||
"fmt" |
||||
"html/template" |
||||
"math/rand" |
||||
"path/filepath" |
||||
"strconv" |
||||
"strings" |
||||
|
||||
"github.com/ethereum/go-ethereum/log" |
||||
) |
||||
|
||||
// explorerDockerfile is the Dockerfile required to run a block explorer.
|
||||
var explorerDockerfile = ` |
||||
FROM puppeth/explorer:latest |
||||
|
||||
ADD ethstats.json /ethstats.json |
||||
ADD chain.json /chain.json |
||||
|
||||
RUN \
|
||||
echo '(cd ../eth-net-intelligence-api && pm2 start /ethstats.json)' > explorer.sh && \
|
||||
echo '(cd ../etherchain-light && npm start &)' >> explorer.sh && \
|
||||
echo '/parity/parity --chain=/chain.json --port={{.NodePort}} --tracing=on --fat-db=on --pruning=archive' >> explorer.sh |
||||
|
||||
ENTRYPOINT ["/bin/sh", "explorer.sh"] |
||||
` |
||||
|
||||
// explorerEthstats is the configuration file for the ethstats javascript client.
|
||||
var explorerEthstats = `[ |
||||
{ |
||||
"name" : "node-app", |
||||
"script" : "app.js", |
||||
"log_date_format" : "YYYY-MM-DD HH:mm Z", |
||||
"merge_logs" : false, |
||||
"watch" : false, |
||||
"max_restarts" : 10, |
||||
"exec_interpreter" : "node", |
||||
"exec_mode" : "fork_mode", |
||||
"env": |
||||
{ |
||||
"NODE_ENV" : "production", |
||||
"RPC_HOST" : "localhost", |
||||
"RPC_PORT" : "8545", |
||||
"LISTENING_PORT" : "{{.Port}}", |
||||
"INSTANCE_NAME" : "{{.Name}}", |
||||
"CONTACT_DETAILS" : "", |
||||
"WS_SERVER" : "{{.Host}}", |
||||
"WS_SECRET" : "{{.Secret}}", |
||||
"VERBOSITY" : 2 |
||||
} |
||||
} |
||||
]` |
||||
|
||||
// explorerComposefile is the docker-compose.yml file required to deploy and
|
||||
// maintain a block explorer.
|
||||
var explorerComposefile = ` |
||||
version: '2' |
||||
services: |
||||
explorer: |
||||
build: . |
||||
image: {{.Network}}/explorer |
||||
ports: |
||||
- "{{.NodePort}}:{{.NodePort}}" |
||||
- "{{.NodePort}}:{{.NodePort}}/udp"{{if not .VHost}} |
||||
- "{{.WebPort}}:3000"{{end}} |
||||
volumes: |
||||
- {{.Datadir}}:/root/.local/share/io.parity.ethereum |
||||
environment: |
||||
- NODE_PORT={{.NodePort}}/tcp |
||||
- STATS={{.Ethstats}}{{if .VHost}} |
||||
- VIRTUAL_HOST={{.VHost}} |
||||
- VIRTUAL_PORT=3000{{end}} |
||||
logging: |
||||
driver: "json-file" |
||||
options: |
||||
max-size: "1m" |
||||
max-file: "10" |
||||
restart: always |
||||
` |
||||
|
||||
// deployExplorer deploys a new block explorer container to a remote machine via
|
||||
// SSH, docker and docker-compose. If an instance with the specified network name
|
||||
// already exists there, it will be overwritten!
|
||||
func deployExplorer(client *sshClient, network string, chainspec []byte, config *explorerInfos, nocache bool) ([]byte, error) { |
||||
// Generate the content to upload to the server
|
||||
workdir := fmt.Sprintf("%d", rand.Int63()) |
||||
files := make(map[string][]byte) |
||||
|
||||
dockerfile := new(bytes.Buffer) |
||||
template.Must(template.New("").Parse(explorerDockerfile)).Execute(dockerfile, map[string]interface{}{ |
||||
"NodePort": config.nodePort, |
||||
}) |
||||
files[filepath.Join(workdir, "Dockerfile")] = dockerfile.Bytes() |
||||
|
||||
ethstats := new(bytes.Buffer) |
||||
template.Must(template.New("").Parse(explorerEthstats)).Execute(ethstats, map[string]interface{}{ |
||||
"Port": config.nodePort, |
||||
"Name": config.ethstats[:strings.Index(config.ethstats, ":")], |
||||
"Secret": config.ethstats[strings.Index(config.ethstats, ":")+1 : strings.Index(config.ethstats, "@")], |
||||
"Host": config.ethstats[strings.Index(config.ethstats, "@")+1:], |
||||
}) |
||||
files[filepath.Join(workdir, "ethstats.json")] = ethstats.Bytes() |
||||
|
||||
composefile := new(bytes.Buffer) |
||||
template.Must(template.New("").Parse(explorerComposefile)).Execute(composefile, map[string]interface{}{ |
||||
"Datadir": config.datadir, |
||||
"Network": network, |
||||
"NodePort": config.nodePort, |
||||
"VHost": config.webHost, |
||||
"WebPort": config.webPort, |
||||
"Ethstats": config.ethstats[:strings.Index(config.ethstats, ":")], |
||||
}) |
||||
files[filepath.Join(workdir, "docker-compose.yaml")] = composefile.Bytes() |
||||
|
||||
files[filepath.Join(workdir, "chain.json")] = chainspec |
||||
|
||||
// Upload the deployment files to the remote server (and clean up afterwards)
|
||||
if out, err := client.Upload(files); err != nil { |
||||
return out, err |
||||
} |
||||
defer client.Run("rm -rf " + workdir) |
||||
|
||||
// Build and deploy the boot or seal node service
|
||||
if nocache { |
||||
return nil, client.Stream(fmt.Sprintf("cd %s && docker-compose -p %s build --pull --no-cache && docker-compose -p %s up -d --force-recreate", workdir, network, network)) |
||||
} |
||||
return nil, client.Stream(fmt.Sprintf("cd %s && docker-compose -p %s up -d --build --force-recreate", workdir, network)) |
||||
} |
||||
|
||||
// explorerInfos is returned from a block explorer status check to allow reporting
|
||||
// various configuration parameters.
|
||||
type explorerInfos struct { |
||||
datadir string |
||||
ethstats string |
||||
nodePort int |
||||
webHost string |
||||
webPort int |
||||
} |
||||
|
||||
// Report converts the typed struct into a plain string->string map, containing
|
||||
// most - but not all - fields for reporting to the user.
|
||||
func (info *explorerInfos) Report() map[string]string { |
||||
report := map[string]string{ |
||||
"Data directory": info.datadir, |
||||
"Node listener port ": strconv.Itoa(info.nodePort), |
||||
"Ethstats username": info.ethstats, |
||||
"Website address ": info.webHost, |
||||
"Website listener port ": strconv.Itoa(info.webPort), |
||||
} |
||||
return report |
||||
} |
||||
|
||||
// checkExplorer does a health-check against an block explorer server to verify
|
||||
// whether it's running, and if yes, whether it's responsive.
|
||||
func checkExplorer(client *sshClient, network string) (*explorerInfos, error) { |
||||
// Inspect a possible block explorer container on the host
|
||||
infos, err := inspectContainer(client, fmt.Sprintf("%s_explorer_1", network)) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
if !infos.running { |
||||
return nil, ErrServiceOffline |
||||
} |
||||
// Resolve the port from the host, or the reverse proxy
|
||||
webPort := infos.portmap["3000/tcp"] |
||||
if webPort == 0 { |
||||
if proxy, _ := checkNginx(client, network); proxy != nil { |
||||
webPort = proxy.port |
||||
} |
||||
} |
||||
if webPort == 0 { |
||||
return nil, ErrNotExposed |
||||
} |
||||
// Resolve the host from the reverse-proxy and the config values
|
||||
host := infos.envvars["VIRTUAL_HOST"] |
||||
if host == "" { |
||||
host = client.server |
||||
} |
||||
// Run a sanity check to see if the devp2p is reachable
|
||||
nodePort := infos.portmap[infos.envvars["NODE_PORT"]] |
||||
if err = checkPort(client.server, nodePort); err != nil { |
||||
log.Warn(fmt.Sprintf("Explorer devp2p port seems unreachable"), "server", client.server, "port", nodePort, "err", err) |
||||
} |
||||
// Assemble and return the useful infos
|
||||
stats := &explorerInfos{ |
||||
datadir: infos.volumes["/root/.local/share/io.parity.ethereum"], |
||||
nodePort: nodePort, |
||||
webHost: host, |
||||
webPort: webPort, |
||||
ethstats: infos.envvars["STATS"], |
||||
} |
||||
return stats, nil |
||||
} |
@ -0,0 +1,200 @@ |
||||
// Copyright 2017 The go-ethereum Authors
|
||||
// This file is part of go-ethereum.
|
||||
//
|
||||
// go-ethereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// go-ethereum 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 General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"bytes" |
||||
"fmt" |
||||
"html/template" |
||||
"math/rand" |
||||
"path/filepath" |
||||
"strconv" |
||||
"strings" |
||||
|
||||
"github.com/ethereum/go-ethereum/log" |
||||
) |
||||
|
||||
// walletDockerfile is the Dockerfile required to run a web wallet.
|
||||
var walletDockerfile = ` |
||||
FROM puppeth/wallet:latest |
||||
|
||||
ADD genesis.json /genesis.json |
||||
|
||||
RUN \
|
||||
echo 'node server.js &' > wallet.sh && \
|
||||
echo 'geth --cache 512 init /genesis.json' >> wallet.sh && \
|
||||
echo $'geth --networkid {{.NetworkID}} --port {{.NodePort}} --bootnodes {{.Bootnodes}} --ethstats \'{{.Ethstats}}\' --cache=512 --rpc --rpcaddr=0.0.0.0 --rpccorsdomain "*"' >> wallet.sh |
||||
|
||||
RUN \
|
||||
sed -i 's/PuppethNetworkID/{{.NetworkID}}/g' dist/js/etherwallet-master.js && \
|
||||
sed -i 's/PuppethNetwork/{{.Network}}/g' dist/js/etherwallet-master.js && \
|
||||
sed -i 's/PuppethDenom/{{.Denom}}/g' dist/js/etherwallet-master.js && \
|
||||
sed -i 's/PuppethHost/{{.Host}}/g' dist/js/etherwallet-master.js && \
|
||||
sed -i 's/PuppethRPCPort/{{.RPCPort}}/g' dist/js/etherwallet-master.js |
||||
|
||||
ENTRYPOINT ["/bin/sh", "wallet.sh"] |
||||
` |
||||
|
||||
// walletComposefile is the docker-compose.yml file required to deploy and
|
||||
// maintain a web wallet.
|
||||
var walletComposefile = ` |
||||
version: '2' |
||||
services: |
||||
wallet: |
||||
build: . |
||||
image: {{.Network}}/wallet |
||||
ports: |
||||
- "{{.NodePort}}:{{.NodePort}}" |
||||
- "{{.NodePort}}:{{.NodePort}}/udp" |
||||
- "{{.RPCPort}}:8545"{{if not .VHost}} |
||||
- "{{.WebPort}}:80"{{end}} |
||||
volumes: |
||||
- {{.Datadir}}:/root/.ethereum |
||||
environment: |
||||
- NODE_PORT={{.NodePort}}/tcp |
||||
- STATS={{.Ethstats}}{{if .VHost}} |
||||
- VIRTUAL_HOST={{.VHost}} |
||||
- VIRTUAL_PORT=80{{end}} |
||||
logging: |
||||
driver: "json-file" |
||||
options: |
||||
max-size: "1m" |
||||
max-file: "10" |
||||
restart: always |
||||
` |
||||
|
||||
// deployWallet deploys a new web wallet container to a remote machine via SSH,
|
||||
// docker and docker-compose. If an instance with the specified network name
|
||||
// already exists there, it will be overwritten!
|
||||
func deployWallet(client *sshClient, network string, bootnodes []string, config *walletInfos, nocache bool) ([]byte, error) { |
||||
// Generate the content to upload to the server
|
||||
workdir := fmt.Sprintf("%d", rand.Int63()) |
||||
files := make(map[string][]byte) |
||||
|
||||
dockerfile := new(bytes.Buffer) |
||||
template.Must(template.New("").Parse(walletDockerfile)).Execute(dockerfile, map[string]interface{}{ |
||||
"Network": strings.ToTitle(network), |
||||
"Denom": strings.ToUpper(network), |
||||
"NetworkID": config.network, |
||||
"NodePort": config.nodePort, |
||||
"RPCPort": config.rpcPort, |
||||
"Bootnodes": strings.Join(bootnodes, ","), |
||||
"Ethstats": config.ethstats, |
||||
"Host": client.address, |
||||
}) |
||||
files[filepath.Join(workdir, "Dockerfile")] = dockerfile.Bytes() |
||||
|
||||
composefile := new(bytes.Buffer) |
||||
template.Must(template.New("").Parse(walletComposefile)).Execute(composefile, map[string]interface{}{ |
||||
"Datadir": config.datadir, |
||||
"Network": network, |
||||
"NodePort": config.nodePort, |
||||
"RPCPort": config.rpcPort, |
||||
"VHost": config.webHost, |
||||
"WebPort": config.webPort, |
||||
"Ethstats": config.ethstats[:strings.Index(config.ethstats, ":")], |
||||
}) |
||||
files[filepath.Join(workdir, "docker-compose.yaml")] = composefile.Bytes() |
||||
|
||||
files[filepath.Join(workdir, "genesis.json")] = config.genesis |
||||
|
||||
// Upload the deployment files to the remote server (and clean up afterwards)
|
||||
if out, err := client.Upload(files); err != nil { |
||||
return out, err |
||||
} |
||||
defer client.Run("rm -rf " + workdir) |
||||
|
||||
// Build and deploy the boot or seal node service
|
||||
if nocache { |
||||
return nil, client.Stream(fmt.Sprintf("cd %s && docker-compose -p %s build --pull --no-cache && docker-compose -p %s up -d --force-recreate", workdir, network, network)) |
||||
} |
||||
return nil, client.Stream(fmt.Sprintf("cd %s && docker-compose -p %s up -d --build --force-recreate", workdir, network)) |
||||
} |
||||
|
||||
// walletInfos is returned from a web wallet status check to allow reporting
|
||||
// various configuration parameters.
|
||||
type walletInfos struct { |
||||
genesis []byte |
||||
network int64 |
||||
datadir string |
||||
ethstats string |
||||
nodePort int |
||||
rpcPort int |
||||
webHost string |
||||
webPort int |
||||
} |
||||
|
||||
// Report converts the typed struct into a plain string->string map, containing
|
||||
// most - but not all - fields for reporting to the user.
|
||||
func (info *walletInfos) Report() map[string]string { |
||||
report := map[string]string{ |
||||
"Data directory": info.datadir, |
||||
"Ethstats username": info.ethstats, |
||||
"Node listener port ": strconv.Itoa(info.nodePort), |
||||
"RPC listener port ": strconv.Itoa(info.rpcPort), |
||||
"Website address ": info.webHost, |
||||
"Website listener port ": strconv.Itoa(info.webPort), |
||||
} |
||||
return report |
||||
} |
||||
|
||||
// checkWallet does a health-check against web wallet server to verify whether
|
||||
// it's running, and if yes, whether it's responsive.
|
||||
func checkWallet(client *sshClient, network string) (*walletInfos, error) { |
||||
// Inspect a possible web wallet container on the host
|
||||
infos, err := inspectContainer(client, fmt.Sprintf("%s_wallet_1", network)) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
if !infos.running { |
||||
return nil, ErrServiceOffline |
||||
} |
||||
// Resolve the port from the host, or the reverse proxy
|
||||
webPort := infos.portmap["80/tcp"] |
||||
if webPort == 0 { |
||||
if proxy, _ := checkNginx(client, network); proxy != nil { |
||||
webPort = proxy.port |
||||
} |
||||
} |
||||
if webPort == 0 { |
||||
return nil, ErrNotExposed |
||||
} |
||||
// Resolve the host from the reverse-proxy and the config values
|
||||
host := infos.envvars["VIRTUAL_HOST"] |
||||
if host == "" { |
||||
host = client.server |
||||
} |
||||
// Run a sanity check to see if the devp2p and RPC ports are reachable
|
||||
nodePort := infos.portmap[infos.envvars["NODE_PORT"]] |
||||
if err = checkPort(client.server, nodePort); err != nil { |
||||
log.Warn(fmt.Sprintf("Wallet devp2p port seems unreachable"), "server", client.server, "port", nodePort, "err", err) |
||||
} |
||||
rpcPort := infos.portmap["8545/tcp"] |
||||
if err = checkPort(client.server, rpcPort); err != nil { |
||||
log.Warn(fmt.Sprintf("Wallet RPC port seems unreachable"), "server", client.server, "port", rpcPort, "err", err) |
||||
} |
||||
// Assemble and return the useful infos
|
||||
stats := &walletInfos{ |
||||
datadir: infos.volumes["/root/.ethereum"], |
||||
nodePort: nodePort, |
||||
rpcPort: rpcPort, |
||||
webHost: host, |
||||
webPort: webPort, |
||||
ethstats: infos.envvars["STATS"], |
||||
} |
||||
return stats, nil |
||||
} |
@ -0,0 +1,117 @@ |
||||
// Copyright 2017 The go-ethereum Authors
|
||||
// This file is part of go-ethereum.
|
||||
//
|
||||
// go-ethereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// go-ethereum 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 General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"encoding/json" |
||||
"fmt" |
||||
"time" |
||||
|
||||
"github.com/ethereum/go-ethereum/log" |
||||
) |
||||
|
||||
// deployExplorer creates a new block explorer based on some user input.
|
||||
func (w *wizard) deployExplorer() { |
||||
// Do some sanity check before the user wastes time on input
|
||||
if w.conf.Genesis == nil { |
||||
log.Error("No genesis block configured") |
||||
return |
||||
} |
||||
if w.conf.ethstats == "" { |
||||
log.Error("No ethstats server configured") |
||||
return |
||||
} |
||||
if w.conf.Genesis.Config.Ethash == nil { |
||||
log.Error("Only ethash network supported") |
||||
return |
||||
} |
||||
// Select the server to interact with
|
||||
server := w.selectServer() |
||||
if server == "" { |
||||
return |
||||
} |
||||
client := w.servers[server] |
||||
|
||||
// Retrieve any active node configurations from the server
|
||||
infos, err := checkExplorer(client, w.network) |
||||
if err != nil { |
||||
infos = &explorerInfos{ |
||||
nodePort: 30303, webPort: 80, webHost: client.server, |
||||
} |
||||
} |
||||
existed := err == nil |
||||
|
||||
chainspec, err := newParityChainSpec(w.network, w.conf.Genesis, w.conf.bootFull) |
||||
if err != nil { |
||||
log.Error("Failed to create chain spec for explorer", "err", err) |
||||
return |
||||
} |
||||
chain, _ := json.MarshalIndent(chainspec, "", " ") |
||||
|
||||
// Figure out which port to listen on
|
||||
fmt.Println() |
||||
fmt.Printf("Which port should the explorer listen on? (default = %d)\n", infos.webPort) |
||||
infos.webPort = w.readDefaultInt(infos.webPort) |
||||
|
||||
// Figure which virtual-host to deploy ethstats on
|
||||
if infos.webHost, err = w.ensureVirtualHost(client, infos.webPort, infos.webHost); err != nil { |
||||
log.Error("Failed to decide on explorer host", "err", err) |
||||
return |
||||
} |
||||
// Figure out where the user wants to store the persistent data
|
||||
fmt.Println() |
||||
if infos.datadir == "" { |
||||
fmt.Printf("Where should data be stored on the remote machine?\n") |
||||
infos.datadir = w.readString() |
||||
} else { |
||||
fmt.Printf("Where should data be stored on the remote machine? (default = %s)\n", infos.datadir) |
||||
infos.datadir = w.readDefaultString(infos.datadir) |
||||
} |
||||
// Figure out which port to listen on
|
||||
fmt.Println() |
||||
fmt.Printf("Which TCP/UDP port should the archive node listen on? (default = %d)\n", infos.nodePort) |
||||
infos.nodePort = w.readDefaultInt(infos.nodePort) |
||||
|
||||
// Set a proper name to report on the stats page
|
||||
fmt.Println() |
||||
if infos.ethstats == "" { |
||||
fmt.Printf("What should the explorer be called on the stats page?\n") |
||||
infos.ethstats = w.readString() + ":" + w.conf.ethstats |
||||
} else { |
||||
fmt.Printf("What should the explorer be called on the stats page? (default = %s)\n", infos.ethstats) |
||||
infos.ethstats = w.readDefaultString(infos.ethstats) + ":" + w.conf.ethstats |
||||
} |
||||
// Try to deploy the explorer on the host
|
||||
nocache := false |
||||
if existed { |
||||
fmt.Println() |
||||
fmt.Printf("Should the explorer be built from scratch (y/n)? (default = no)\n") |
||||
nocache = w.readDefaultString("n") != "n" |
||||
} |
||||
if out, err := deployExplorer(client, w.network, chain, infos, nocache); err != nil { |
||||
log.Error("Failed to deploy explorer container", "err", err) |
||||
if len(out) > 0 { |
||||
fmt.Printf("%s\n", out) |
||||
} |
||||
return |
||||
} |
||||
// All ok, run a network scan to pick any changes up
|
||||
log.Info("Waiting for node to finish booting") |
||||
time.Sleep(3 * time.Second) |
||||
|
||||
w.networkStats() |
||||
} |
@ -0,0 +1,113 @@ |
||||
// Copyright 2017 The go-ethereum Authors
|
||||
// This file is part of go-ethereum.
|
||||
//
|
||||
// go-ethereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// go-ethereum 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 General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"encoding/json" |
||||
"fmt" |
||||
"time" |
||||
|
||||
"github.com/ethereum/go-ethereum/log" |
||||
) |
||||
|
||||
// deployWallet creates a new web wallet based on some user input.
|
||||
func (w *wizard) deployWallet() { |
||||
// Do some sanity check before the user wastes time on input
|
||||
if w.conf.Genesis == nil { |
||||
log.Error("No genesis block configured") |
||||
return |
||||
} |
||||
if w.conf.ethstats == "" { |
||||
log.Error("No ethstats server configured") |
||||
return |
||||
} |
||||
// Select the server to interact with
|
||||
server := w.selectServer() |
||||
if server == "" { |
||||
return |
||||
} |
||||
client := w.servers[server] |
||||
|
||||
// Retrieve any active node configurations from the server
|
||||
infos, err := checkWallet(client, w.network) |
||||
if err != nil { |
||||
infos = &walletInfos{ |
||||
nodePort: 30303, rpcPort: 8545, webPort: 80, webHost: client.server, |
||||
} |
||||
} |
||||
existed := err == nil |
||||
|
||||
infos.genesis, _ = json.MarshalIndent(w.conf.Genesis, "", " ") |
||||
infos.network = w.conf.Genesis.Config.ChainId.Int64() |
||||
|
||||
// Figure out which port to listen on
|
||||
fmt.Println() |
||||
fmt.Printf("Which port should the wallet listen on? (default = %d)\n", infos.webPort) |
||||
infos.webPort = w.readDefaultInt(infos.webPort) |
||||
|
||||
// Figure which virtual-host to deploy ethstats on
|
||||
if infos.webHost, err = w.ensureVirtualHost(client, infos.webPort, infos.webHost); err != nil { |
||||
log.Error("Failed to decide on wallet host", "err", err) |
||||
return |
||||
} |
||||
// Figure out where the user wants to store the persistent data
|
||||
fmt.Println() |
||||
if infos.datadir == "" { |
||||
fmt.Printf("Where should data be stored on the remote machine?\n") |
||||
infos.datadir = w.readString() |
||||
} else { |
||||
fmt.Printf("Where should data be stored on the remote machine? (default = %s)\n", infos.datadir) |
||||
infos.datadir = w.readDefaultString(infos.datadir) |
||||
} |
||||
// Figure out which port to listen on
|
||||
fmt.Println() |
||||
fmt.Printf("Which TCP/UDP port should the backing node listen on? (default = %d)\n", infos.nodePort) |
||||
infos.nodePort = w.readDefaultInt(infos.nodePort) |
||||
|
||||
fmt.Println() |
||||
fmt.Printf("Which port should the backing RPC API listen on? (default = %d)\n", infos.rpcPort) |
||||
infos.rpcPort = w.readDefaultInt(infos.rpcPort) |
||||
|
||||
// Set a proper name to report on the stats page
|
||||
fmt.Println() |
||||
if infos.ethstats == "" { |
||||
fmt.Printf("What should the wallet be called on the stats page?\n") |
||||
infos.ethstats = w.readString() + ":" + w.conf.ethstats |
||||
} else { |
||||
fmt.Printf("What should the wallet be called on the stats page? (default = %s)\n", infos.ethstats) |
||||
infos.ethstats = w.readDefaultString(infos.ethstats) + ":" + w.conf.ethstats |
||||
} |
||||
// Try to deploy the wallet on the host
|
||||
nocache := false |
||||
if existed { |
||||
fmt.Println() |
||||
fmt.Printf("Should the wallet be built from scratch (y/n)? (default = no)\n") |
||||
nocache = w.readDefaultString("n") != "n" |
||||
} |
||||
if out, err := deployWallet(client, w.network, w.conf.bootFull, infos, nocache); err != nil { |
||||
log.Error("Failed to deploy wallet container", "err", err) |
||||
if len(out) > 0 { |
||||
fmt.Printf("%s\n", out) |
||||
} |
||||
return |
||||
} |
||||
// All ok, run a network scan to pick any changes up
|
||||
log.Info("Waiting for node to finish booting") |
||||
time.Sleep(3 * time.Second) |
||||
|
||||
w.networkStats() |
||||
} |
@ -0,0 +1,342 @@ |
||||
// Copyright 2017 The go-ethereum Authors
|
||||
// This file is part of go-ethereum.
|
||||
//
|
||||
// go-ethereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// go-ethereum 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 General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"errors" |
||||
"fmt" |
||||
"io" |
||||
"os" |
||||
"reflect" |
||||
"strconv" |
||||
"strings" |
||||
"unicode" |
||||
|
||||
cli "gopkg.in/urfave/cli.v1" |
||||
|
||||
"github.com/ethereum/go-ethereum/cmd/utils" |
||||
"github.com/ethereum/go-ethereum/common" |
||||
"github.com/ethereum/go-ethereum/log" |
||||
"github.com/ethereum/go-ethereum/node" |
||||
"github.com/naoina/toml" |
||||
|
||||
bzzapi "github.com/ethereum/go-ethereum/swarm/api" |
||||
) |
||||
|
||||
var ( |
||||
//flag definition for the dumpconfig command
|
||||
DumpConfigCommand = cli.Command{ |
||||
Action: utils.MigrateFlags(dumpConfig), |
||||
Name: "dumpconfig", |
||||
Usage: "Show configuration values", |
||||
ArgsUsage: "", |
||||
Flags: app.Flags, |
||||
Category: "MISCELLANEOUS COMMANDS", |
||||
Description: `The dumpconfig command shows configuration values.`, |
||||
} |
||||
|
||||
//flag definition for the config file command
|
||||
SwarmTomlConfigPathFlag = cli.StringFlag{ |
||||
Name: "config", |
||||
Usage: "TOML configuration file", |
||||
} |
||||
) |
||||
|
||||
//constants for environment variables
|
||||
const ( |
||||
SWARM_ENV_CHEQUEBOOK_ADDR = "SWARM_CHEQUEBOOK_ADDR" |
||||
SWARM_ENV_ACCOUNT = "SWARM_ACCOUNT" |
||||
SWARM_ENV_LISTEN_ADDR = "SWARM_LISTEN_ADDR" |
||||
SWARM_ENV_PORT = "SWARM_PORT" |
||||
SWARM_ENV_NETWORK_ID = "SWARM_NETWORK_ID" |
||||
SWARM_ENV_SWAP_ENABLE = "SWARM_SWAP_ENABLE" |
||||
SWARM_ENV_SWAP_API = "SWARM_SWAP_API" |
||||
SWARM_ENV_SYNC_ENABLE = "SWARM_SYNC_ENABLE" |
||||
SWARM_ENV_ENS_API = "SWARM_ENS_API" |
||||
SWARM_ENV_ENS_ADDR = "SWARM_ENS_ADDR" |
||||
SWARM_ENV_CORS = "SWARM_CORS" |
||||
SWARM_ENV_BOOTNODES = "SWARM_BOOTNODES" |
||||
GETH_ENV_DATADIR = "GETH_DATADIR" |
||||
) |
||||
|
||||
// These settings ensure that TOML keys use the same names as Go struct fields.
|
||||
var tomlSettings = toml.Config{ |
||||
NormFieldName: func(rt reflect.Type, key string) string { |
||||
return key |
||||
}, |
||||
FieldToKey: func(rt reflect.Type, field string) string { |
||||
return field |
||||
}, |
||||
MissingField: func(rt reflect.Type, field string) error { |
||||
link := "" |
||||
if unicode.IsUpper(rune(rt.Name()[0])) && rt.PkgPath() != "main" { |
||||
link = fmt.Sprintf(", check github.com/ethereum/go-ethereum/swarm/api/config.go for available fields") |
||||
} |
||||
return fmt.Errorf("field '%s' is not defined in %s%s", field, rt.String(), link) |
||||
}, |
||||
} |
||||
|
||||
//before booting the swarm node, build the configuration
|
||||
func buildConfig(ctx *cli.Context) (config *bzzapi.Config, err error) { |
||||
//check for deprecated flags
|
||||
checkDeprecated(ctx) |
||||
//start by creating a default config
|
||||
config = bzzapi.NewDefaultConfig() |
||||
//first load settings from config file (if provided)
|
||||
config, err = configFileOverride(config, ctx) |
||||
//override settings provided by environment variables
|
||||
config = envVarsOverride(config) |
||||
//override settings provided by command line
|
||||
config = cmdLineOverride(config, ctx) |
||||
|
||||
return |
||||
} |
||||
|
||||
//finally, after the configuration build phase is finished, initialize
|
||||
func initSwarmNode(config *bzzapi.Config, stack *node.Node, ctx *cli.Context) { |
||||
//at this point, all vars should be set in the Config
|
||||
//get the account for the provided swarm account
|
||||
prvkey := getAccount(config.BzzAccount, ctx, stack) |
||||
//set the resolved config path (geth --datadir)
|
||||
config.Path = stack.InstanceDir() |
||||
//finally, initialize the configuration
|
||||
config.Init(prvkey) |
||||
//configuration phase completed here
|
||||
log.Debug("Starting Swarm with the following parameters:") |
||||
//after having created the config, print it to screen
|
||||
log.Debug(printConfig(config)) |
||||
} |
||||
|
||||
//override the current config with whatever is in the config file, if a config file has been provided
|
||||
func configFileOverride(config *bzzapi.Config, ctx *cli.Context) (*bzzapi.Config, error) { |
||||
var err error |
||||
|
||||
//only do something if the -config flag has been set
|
||||
if ctx.GlobalIsSet(SwarmTomlConfigPathFlag.Name) { |
||||
var filepath string |
||||
if filepath = ctx.GlobalString(SwarmTomlConfigPathFlag.Name); filepath == "" { |
||||
utils.Fatalf("Config file flag provided with invalid file path") |
||||
} |
||||
f, err := os.Open(filepath) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
defer f.Close() |
||||
|
||||
//decode the TOML file into a Config struct
|
||||
//note that we are decoding into the existing defaultConfig;
|
||||
//if an entry is not present in the file, the default entry is kept
|
||||
err = tomlSettings.NewDecoder(f).Decode(&config) |
||||
// Add file name to errors that have a line number.
|
||||
if _, ok := err.(*toml.LineError); ok { |
||||
err = errors.New(filepath + ", " + err.Error()) |
||||
} |
||||
} |
||||
return config, err |
||||
} |
||||
|
||||
//override the current config with whatever is provided through the command line
|
||||
//most values are not allowed a zero value (empty string), if not otherwise noted
|
||||
func cmdLineOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Config { |
||||
|
||||
if keyid := ctx.GlobalString(SwarmAccountFlag.Name); keyid != "" { |
||||
currentConfig.BzzAccount = keyid |
||||
} |
||||
|
||||
if chbookaddr := ctx.GlobalString(ChequebookAddrFlag.Name); chbookaddr != "" { |
||||
currentConfig.Contract = common.HexToAddress(chbookaddr) |
||||
} |
||||
|
||||
if networkid := ctx.GlobalString(SwarmNetworkIdFlag.Name); networkid != "" { |
||||
if id, _ := strconv.Atoi(networkid); id != 0 { |
||||
currentConfig.NetworkId = uint64(id) |
||||
} |
||||
} |
||||
|
||||
if ctx.GlobalIsSet(utils.DataDirFlag.Name) { |
||||
if datadir := ctx.GlobalString(utils.DataDirFlag.Name); datadir != "" { |
||||
currentConfig.Path = datadir |
||||
} |
||||
} |
||||
|
||||
bzzport := ctx.GlobalString(SwarmPortFlag.Name) |
||||
if len(bzzport) > 0 { |
||||
currentConfig.Port = bzzport |
||||
} |
||||
|
||||
if bzzaddr := ctx.GlobalString(SwarmListenAddrFlag.Name); bzzaddr != "" { |
||||
currentConfig.ListenAddr = bzzaddr |
||||
} |
||||
|
||||
if ctx.GlobalIsSet(SwarmSwapEnabledFlag.Name) { |
||||
currentConfig.SwapEnabled = true |
||||
} |
||||
|
||||
if ctx.GlobalIsSet(SwarmSyncEnabledFlag.Name) { |
||||
currentConfig.SyncEnabled = true |
||||
} |
||||
|
||||
currentConfig.SwapApi = ctx.GlobalString(SwarmSwapAPIFlag.Name) |
||||
if currentConfig.SwapEnabled && currentConfig.SwapApi == "" { |
||||
utils.Fatalf(SWARM_ERR_SWAP_SET_NO_API) |
||||
} |
||||
|
||||
//EnsAPIs can be set to "", so can't check for empty string, as it is allowed!
|
||||
if ctx.GlobalIsSet(EnsAPIFlag.Name) { |
||||
ensAPIs := ctx.GlobalStringSlice(EnsAPIFlag.Name) |
||||
// Disable ENS resolver if --ens-api="" is specified
|
||||
if len(ensAPIs) == 1 && ensAPIs[0] == "" { |
||||
currentConfig.EnsDisabled = true |
||||
currentConfig.EnsAPIs = nil |
||||
} else { |
||||
currentConfig.EnsDisabled = false |
||||
currentConfig.EnsAPIs = ensAPIs |
||||
} |
||||
} |
||||
|
||||
if ensaddr := ctx.GlobalString(DeprecatedEnsAddrFlag.Name); ensaddr != "" { |
||||
currentConfig.EnsRoot = common.HexToAddress(ensaddr) |
||||
} |
||||
|
||||
if cors := ctx.GlobalString(CorsStringFlag.Name); cors != "" { |
||||
currentConfig.Cors = cors |
||||
} |
||||
|
||||
if ctx.GlobalIsSet(utils.BootnodesFlag.Name) { |
||||
currentConfig.BootNodes = ctx.GlobalString(utils.BootnodesFlag.Name) |
||||
} |
||||
|
||||
return currentConfig |
||||
|
||||
} |
||||
|
||||
//override the current config with whatver is provided in environment variables
|
||||
//most values are not allowed a zero value (empty string), if not otherwise noted
|
||||
func envVarsOverride(currentConfig *bzzapi.Config) (config *bzzapi.Config) { |
||||
|
||||
if keyid := os.Getenv(SWARM_ENV_ACCOUNT); keyid != "" { |
||||
currentConfig.BzzAccount = keyid |
||||
} |
||||
|
||||
if chbookaddr := os.Getenv(SWARM_ENV_CHEQUEBOOK_ADDR); chbookaddr != "" { |
||||
currentConfig.Contract = common.HexToAddress(chbookaddr) |
||||
} |
||||
|
||||
if networkid := os.Getenv(SWARM_ENV_NETWORK_ID); networkid != "" { |
||||
if id, _ := strconv.Atoi(networkid); id != 0 { |
||||
currentConfig.NetworkId = uint64(id) |
||||
} |
||||
} |
||||
|
||||
if datadir := os.Getenv(GETH_ENV_DATADIR); datadir != "" { |
||||
currentConfig.Path = datadir |
||||
} |
||||
|
||||
bzzport := os.Getenv(SWARM_ENV_PORT) |
||||
if len(bzzport) > 0 { |
||||
currentConfig.Port = bzzport |
||||
} |
||||
|
||||
if bzzaddr := os.Getenv(SWARM_ENV_LISTEN_ADDR); bzzaddr != "" { |
||||
currentConfig.ListenAddr = bzzaddr |
||||
} |
||||
|
||||
if swapenable := os.Getenv(SWARM_ENV_SWAP_ENABLE); swapenable != "" { |
||||
if swap, err := strconv.ParseBool(swapenable); err != nil { |
||||
currentConfig.SwapEnabled = swap |
||||
} |
||||
} |
||||
|
||||
if syncenable := os.Getenv(SWARM_ENV_SYNC_ENABLE); syncenable != "" { |
||||
if sync, err := strconv.ParseBool(syncenable); err != nil { |
||||
currentConfig.SyncEnabled = sync |
||||
} |
||||
} |
||||
|
||||
if swapapi := os.Getenv(SWARM_ENV_SWAP_API); swapapi != "" { |
||||
currentConfig.SwapApi = swapapi |
||||
} |
||||
|
||||
if currentConfig.SwapEnabled && currentConfig.SwapApi == "" { |
||||
utils.Fatalf(SWARM_ERR_SWAP_SET_NO_API) |
||||
} |
||||
|
||||
//EnsAPIs can be set to "", so can't check for empty string, as it is allowed
|
||||
if ensapi, exists := os.LookupEnv(SWARM_ENV_ENS_API); exists == true { |
||||
ensAPIs := strings.Split(ensapi, ",") |
||||
// Disable ENS resolver if SWARM_ENS_API="" is specified
|
||||
if len(ensAPIs) == 0 { |
||||
currentConfig.EnsDisabled = true |
||||
currentConfig.EnsAPIs = nil |
||||
} else { |
||||
currentConfig.EnsDisabled = false |
||||
currentConfig.EnsAPIs = ensAPIs |
||||
} |
||||
} |
||||
|
||||
if ensaddr := os.Getenv(SWARM_ENV_ENS_ADDR); ensaddr != "" { |
||||
currentConfig.EnsRoot = common.HexToAddress(ensaddr) |
||||
} |
||||
|
||||
if cors := os.Getenv(SWARM_ENV_CORS); cors != "" { |
||||
currentConfig.Cors = cors |
||||
} |
||||
|
||||
if bootnodes := os.Getenv(SWARM_ENV_BOOTNODES); bootnodes != "" { |
||||
currentConfig.BootNodes = bootnodes |
||||
} |
||||
|
||||
return currentConfig |
||||
} |
||||
|
||||
// dumpConfig is the dumpconfig command.
|
||||
// writes a default config to STDOUT
|
||||
func dumpConfig(ctx *cli.Context) error { |
||||
cfg, err := buildConfig(ctx) |
||||
if err != nil { |
||||
utils.Fatalf(fmt.Sprintf("Uh oh - dumpconfig triggered an error %v", err)) |
||||
} |
||||
comment := "" |
||||
out, err := tomlSettings.Marshal(&cfg) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
io.WriteString(os.Stdout, comment) |
||||
os.Stdout.Write(out) |
||||
return nil |
||||
} |
||||
|
||||
//deprecated flags checked here
|
||||
func checkDeprecated(ctx *cli.Context) { |
||||
// exit if the deprecated --ethapi flag is set
|
||||
if ctx.GlobalString(DeprecatedEthAPIFlag.Name) != "" { |
||||
utils.Fatalf("--ethapi is no longer a valid command line flag, please use --ens-api and/or --swap-api.") |
||||
} |
||||
// warn if --ens-api flag is set
|
||||
if ctx.GlobalString(DeprecatedEnsAddrFlag.Name) != "" { |
||||
log.Warn("--ens-addr is no longer a valid command line flag, please use --ens-api to specify contract address.") |
||||
} |
||||
} |
||||
|
||||
//print a Config as string
|
||||
func printConfig(config *bzzapi.Config) string { |
||||
out, err := tomlSettings.Marshal(&config) |
||||
if err != nil { |
||||
return (fmt.Sprintf("Something is not right with the configuration: %v", err)) |
||||
} |
||||
return string(out) |
||||
} |
@ -0,0 +1,459 @@ |
||||
// Copyright 2017 The go-ethereum Authors
|
||||
// This file is part of go-ethereum.
|
||||
//
|
||||
// go-ethereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// go-ethereum 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 General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"io" |
||||
"io/ioutil" |
||||
"os" |
||||
"os/exec" |
||||
"testing" |
||||
"time" |
||||
|
||||
"github.com/ethereum/go-ethereum/rpc" |
||||
"github.com/ethereum/go-ethereum/swarm" |
||||
"github.com/ethereum/go-ethereum/swarm/api" |
||||
|
||||
"github.com/docker/docker/pkg/reexec" |
||||
) |
||||
|
||||
func TestDumpConfig(t *testing.T) { |
||||
swarm := runSwarm(t, "dumpconfig") |
||||
defaultConf := api.NewDefaultConfig() |
||||
out, err := tomlSettings.Marshal(&defaultConf) |
||||
if err != nil { |
||||
t.Fatal(err) |
||||
} |
||||
swarm.Expect(string(out)) |
||||
swarm.ExpectExit() |
||||
} |
||||
|
||||
func TestFailsSwapEnabledNoSwapApi(t *testing.T) { |
||||
flags := []string{ |
||||
fmt.Sprintf("--%s", SwarmNetworkIdFlag.Name), "42", |
||||
fmt.Sprintf("--%s", SwarmPortFlag.Name), "54545", |
||||
fmt.Sprintf("--%s", SwarmSwapEnabledFlag.Name), |
||||
} |
||||
|
||||
swarm := runSwarm(t, flags...) |
||||
swarm.Expect("Fatal: " + SWARM_ERR_SWAP_SET_NO_API + "\n") |
||||
swarm.ExpectExit() |
||||
} |
||||
|
||||
func TestFailsNoBzzAccount(t *testing.T) { |
||||
flags := []string{ |
||||
fmt.Sprintf("--%s", SwarmNetworkIdFlag.Name), "42", |
||||
fmt.Sprintf("--%s", SwarmPortFlag.Name), "54545", |
||||
} |
||||
|
||||
swarm := runSwarm(t, flags...) |
||||
swarm.Expect("Fatal: " + SWARM_ERR_NO_BZZACCOUNT + "\n") |
||||
swarm.ExpectExit() |
||||
} |
||||
|
||||
func TestCmdLineOverrides(t *testing.T) { |
||||
dir, err := ioutil.TempDir("", "bzztest") |
||||
if err != nil { |
||||
t.Fatal(err) |
||||
} |
||||
defer os.RemoveAll(dir) |
||||
|
||||
conf, account := getTestAccount(t, dir) |
||||
node := &testNode{Dir: dir} |
||||
|
||||
// assign ports
|
||||
httpPort, err := assignTCPPort() |
||||
if err != nil { |
||||
t.Fatal(err) |
||||
} |
||||
|
||||
flags := []string{ |
||||
fmt.Sprintf("--%s", SwarmNetworkIdFlag.Name), "42", |
||||
fmt.Sprintf("--%s", SwarmPortFlag.Name), httpPort, |
||||
fmt.Sprintf("--%s", SwarmSyncEnabledFlag.Name), |
||||
fmt.Sprintf("--%s", CorsStringFlag.Name), "*", |
||||
fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(), |
||||
fmt.Sprintf("--%s", EnsAPIFlag.Name), "", |
||||
"--datadir", dir, |
||||
"--ipcpath", conf.IPCPath, |
||||
} |
||||
node.Cmd = runSwarm(t, flags...) |
||||
node.Cmd.InputLine(testPassphrase) |
||||
defer func() { |
||||
if t.Failed() { |
||||
node.Shutdown() |
||||
} |
||||
}() |
||||
// wait for the node to start
|
||||
for start := time.Now(); time.Since(start) < 10*time.Second; time.Sleep(50 * time.Millisecond) { |
||||
node.Client, err = rpc.Dial(conf.IPCEndpoint()) |
||||
if err == nil { |
||||
break |
||||
} |
||||
} |
||||
if node.Client == nil { |
||||
t.Fatal(err) |
||||
} |
||||
|
||||
// load info
|
||||
var info swarm.Info |
||||
if err := node.Client.Call(&info, "bzz_info"); err != nil { |
||||
t.Fatal(err) |
||||
} |
||||
|
||||
if info.Port != httpPort { |
||||
t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port) |
||||
} |
||||
|
||||
if info.NetworkId != 42 { |
||||
t.Fatalf("Expected network ID to be %d, got %d", 42, info.NetworkId) |
||||
} |
||||
|
||||
if info.SyncEnabled != true { |
||||
t.Fatal("Expected Sync to be enabled, but is false") |
||||
} |
||||
|
||||
if info.Cors != "*" { |
||||
t.Fatalf("Expected Cors flag to be set to %s, got %s", "*", info.Cors) |
||||
} |
||||
|
||||
node.Shutdown() |
||||
} |
||||
|
||||
func TestFileOverrides(t *testing.T) { |
||||
|
||||
// assign ports
|
||||
httpPort, err := assignTCPPort() |
||||
if err != nil { |
||||
t.Fatal(err) |
||||
} |
||||
|
||||
//create a config file
|
||||
//first, create a default conf
|
||||
defaultConf := api.NewDefaultConfig() |
||||
//change some values in order to test if they have been loaded
|
||||
defaultConf.SyncEnabled = true |
||||
defaultConf.NetworkId = 54 |
||||
defaultConf.Port = httpPort |
||||
defaultConf.StoreParams.DbCapacity = 9000000 |
||||
defaultConf.ChunkerParams.Branches = 64 |
||||
defaultConf.HiveParams.CallInterval = 6000000000 |
||||
defaultConf.Swap.Params.Strategy.AutoCashInterval = 600 * time.Second |
||||
defaultConf.SyncParams.KeyBufferSize = 512 |
||||
//create a TOML string
|
||||
out, err := tomlSettings.Marshal(&defaultConf) |
||||
if err != nil { |
||||
t.Fatalf("Error creating TOML file in TestFileOverride: %v", err) |
||||
} |
||||
//create file
|
||||
f, err := ioutil.TempFile("", "testconfig.toml") |
||||
if err != nil { |
||||
t.Fatalf("Error writing TOML file in TestFileOverride: %v", err) |
||||
} |
||||
//write file
|
||||
_, err = f.WriteString(string(out)) |
||||
if err != nil { |
||||
t.Fatalf("Error writing TOML file in TestFileOverride: %v", err) |
||||
} |
||||
f.Sync() |
||||
|
||||
dir, err := ioutil.TempDir("", "bzztest") |
||||
if err != nil { |
||||
t.Fatal(err) |
||||
} |
||||
defer os.RemoveAll(dir) |
||||
conf, account := getTestAccount(t, dir) |
||||
node := &testNode{Dir: dir} |
||||
|
||||
flags := []string{ |
||||
fmt.Sprintf("--%s", SwarmTomlConfigPathFlag.Name), f.Name(), |
||||
fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(), |
||||
"--ens-api", "", |
||||
"--ipcpath", conf.IPCPath, |
||||
"--datadir", dir, |
||||
} |
||||
node.Cmd = runSwarm(t, flags...) |
||||
node.Cmd.InputLine(testPassphrase) |
||||
defer func() { |
||||
if t.Failed() { |
||||
node.Shutdown() |
||||
} |
||||
}() |
||||
// wait for the node to start
|
||||
for start := time.Now(); time.Since(start) < 10*time.Second; time.Sleep(50 * time.Millisecond) { |
||||
node.Client, err = rpc.Dial(conf.IPCEndpoint()) |
||||
if err == nil { |
||||
break |
||||
} |
||||
} |
||||
if node.Client == nil { |
||||
t.Fatal(err) |
||||
} |
||||
|
||||
// load info
|
||||
var info swarm.Info |
||||
if err := node.Client.Call(&info, "bzz_info"); err != nil { |
||||
t.Fatal(err) |
||||
} |
||||
|
||||
if info.Port != httpPort { |
||||
t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port) |
||||
} |
||||
|
||||
if info.NetworkId != 54 { |
||||
t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkId) |
||||
} |
||||
|
||||
if info.SyncEnabled != true { |
||||
t.Fatal("Expected Sync to be enabled, but is false") |
||||
} |
||||
|
||||
if info.StoreParams.DbCapacity != 9000000 { |
||||
t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkId) |
||||
} |
||||
|
||||
if info.ChunkerParams.Branches != 64 { |
||||
t.Fatalf("Expected chunker params branches to be %d, got %d", 64, info.ChunkerParams.Branches) |
||||
} |
||||
|
||||
if info.HiveParams.CallInterval != 6000000000 { |
||||
t.Fatalf("Expected HiveParams CallInterval to be %d, got %d", uint64(6000000000), uint64(info.HiveParams.CallInterval)) |
||||
} |
||||
|
||||
if info.Swap.Params.Strategy.AutoCashInterval != 600*time.Second { |
||||
t.Fatalf("Expected SwapParams AutoCashInterval to be %ds, got %d", 600, info.Swap.Params.Strategy.AutoCashInterval) |
||||
} |
||||
|
||||
if info.SyncParams.KeyBufferSize != 512 { |
||||
t.Fatalf("Expected info.SyncParams.KeyBufferSize to be %d, got %d", 512, info.SyncParams.KeyBufferSize) |
||||
} |
||||
|
||||
node.Shutdown() |
||||
} |
||||
|
||||
func TestEnvVars(t *testing.T) { |
||||
// assign ports
|
||||
httpPort, err := assignTCPPort() |
||||
if err != nil { |
||||
t.Fatal(err) |
||||
} |
||||
|
||||
envVars := os.Environ() |
||||
envVars = append(envVars, fmt.Sprintf("%s=%s", SwarmPortFlag.EnvVar, httpPort)) |
||||
envVars = append(envVars, fmt.Sprintf("%s=%s", SwarmNetworkIdFlag.EnvVar, "999")) |
||||
envVars = append(envVars, fmt.Sprintf("%s=%s", CorsStringFlag.EnvVar, "*")) |
||||
envVars = append(envVars, fmt.Sprintf("%s=%s", SwarmSyncEnabledFlag.EnvVar, "true")) |
||||
|
||||
dir, err := ioutil.TempDir("", "bzztest") |
||||
if err != nil { |
||||
t.Fatal(err) |
||||
} |
||||
defer os.RemoveAll(dir) |
||||
conf, account := getTestAccount(t, dir) |
||||
node := &testNode{Dir: dir} |
||||
flags := []string{ |
||||
fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(), |
||||
"--ens-api", "", |
||||
"--datadir", dir, |
||||
"--ipcpath", conf.IPCPath, |
||||
} |
||||
|
||||
//node.Cmd = runSwarm(t,flags...)
|
||||
//node.Cmd.cmd.Env = envVars
|
||||
//the above assignment does not work, so we need a custom Cmd here in order to pass envVars:
|
||||
cmd := &exec.Cmd{ |
||||
Path: reexec.Self(), |
||||
Args: append([]string{"swarm-test"}, flags...), |
||||
Stderr: os.Stderr, |
||||
Stdout: os.Stdout, |
||||
} |
||||
cmd.Env = envVars |
||||
//stdout, err := cmd.StdoutPipe()
|
||||
//if err != nil {
|
||||
// t.Fatal(err)
|
||||
//}
|
||||
//stdout = bufio.NewReader(stdout)
|
||||
var stdin io.WriteCloser |
||||
if stdin, err = cmd.StdinPipe(); err != nil { |
||||
t.Fatal(err) |
||||
} |
||||
if err := cmd.Start(); err != nil { |
||||
t.Fatal(err) |
||||
} |
||||
|
||||
//cmd.InputLine(testPassphrase)
|
||||
io.WriteString(stdin, testPassphrase+"\n") |
||||
defer func() { |
||||
if t.Failed() { |
||||
node.Shutdown() |
||||
cmd.Process.Kill() |
||||
} |
||||
}() |
||||
// wait for the node to start
|
||||
for start := time.Now(); time.Since(start) < 10*time.Second; time.Sleep(50 * time.Millisecond) { |
||||
node.Client, err = rpc.Dial(conf.IPCEndpoint()) |
||||
if err == nil { |
||||
break |
||||
} |
||||
} |
||||
|
||||
if node.Client == nil { |
||||
t.Fatal(err) |
||||
} |
||||
|
||||
// load info
|
||||
var info swarm.Info |
||||
if err := node.Client.Call(&info, "bzz_info"); err != nil { |
||||
t.Fatal(err) |
||||
} |
||||
|
||||
if info.Port != httpPort { |
||||
t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port) |
||||
} |
||||
|
||||
if info.NetworkId != 999 { |
||||
t.Fatalf("Expected network ID to be %d, got %d", 999, info.NetworkId) |
||||
} |
||||
|
||||
if info.Cors != "*" { |
||||
t.Fatalf("Expected Cors flag to be set to %s, got %s", "*", info.Cors) |
||||
} |
||||
|
||||
if info.SyncEnabled != true { |
||||
t.Fatal("Expected Sync to be enabled, but is false") |
||||
} |
||||
|
||||
node.Shutdown() |
||||
cmd.Process.Kill() |
||||
} |
||||
|
||||
func TestCmdLineOverridesFile(t *testing.T) { |
||||
|
||||
// assign ports
|
||||
httpPort, err := assignTCPPort() |
||||
if err != nil { |
||||
t.Fatal(err) |
||||
} |
||||
|
||||
//create a config file
|
||||
//first, create a default conf
|
||||
defaultConf := api.NewDefaultConfig() |
||||
//change some values in order to test if they have been loaded
|
||||
defaultConf.SyncEnabled = false |
||||
defaultConf.NetworkId = 54 |
||||
defaultConf.Port = "8588" |
||||
defaultConf.StoreParams.DbCapacity = 9000000 |
||||
defaultConf.ChunkerParams.Branches = 64 |
||||
defaultConf.HiveParams.CallInterval = 6000000000 |
||||
defaultConf.Swap.Params.Strategy.AutoCashInterval = 600 * time.Second |
||||
defaultConf.SyncParams.KeyBufferSize = 512 |
||||
//create a TOML file
|
||||
out, err := tomlSettings.Marshal(&defaultConf) |
||||
if err != nil { |
||||
t.Fatalf("Error creating TOML file in TestFileOverride: %v", err) |
||||
} |
||||
//write file
|
||||
f, err := ioutil.TempFile("", "testconfig.toml") |
||||
if err != nil { |
||||
t.Fatalf("Error writing TOML file in TestFileOverride: %v", err) |
||||
} |
||||
//write file
|
||||
_, err = f.WriteString(string(out)) |
||||
if err != nil { |
||||
t.Fatalf("Error writing TOML file in TestFileOverride: %v", err) |
||||
} |
||||
f.Sync() |
||||
|
||||
dir, err := ioutil.TempDir("", "bzztest") |
||||
if err != nil { |
||||
t.Fatal(err) |
||||
} |
||||
defer os.RemoveAll(dir) |
||||
conf, account := getTestAccount(t, dir) |
||||
node := &testNode{Dir: dir} |
||||
|
||||
expectNetworkId := uint64(77) |
||||
|
||||
flags := []string{ |
||||
fmt.Sprintf("--%s", SwarmNetworkIdFlag.Name), "77", |
||||
fmt.Sprintf("--%s", SwarmPortFlag.Name), httpPort, |
||||
fmt.Sprintf("--%s", SwarmSyncEnabledFlag.Name), |
||||
fmt.Sprintf("--%s", SwarmTomlConfigPathFlag.Name), f.Name(), |
||||
fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(), |
||||
"--ens-api", "", |
||||
"--datadir", dir, |
||||
"--ipcpath", conf.IPCPath, |
||||
} |
||||
node.Cmd = runSwarm(t, flags...) |
||||
node.Cmd.InputLine(testPassphrase) |
||||
defer func() { |
||||
if t.Failed() { |
||||
node.Shutdown() |
||||
} |
||||
}() |
||||
// wait for the node to start
|
||||
for start := time.Now(); time.Since(start) < 10*time.Second; time.Sleep(50 * time.Millisecond) { |
||||
node.Client, err = rpc.Dial(conf.IPCEndpoint()) |
||||
if err == nil { |
||||
break |
||||
} |
||||
} |
||||
if node.Client == nil { |
||||
t.Fatal(err) |
||||
} |
||||
|
||||
// load info
|
||||
var info swarm.Info |
||||
if err := node.Client.Call(&info, "bzz_info"); err != nil { |
||||
t.Fatal(err) |
||||
} |
||||
|
||||
if info.Port != httpPort { |
||||
t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port) |
||||
} |
||||
|
||||
if info.NetworkId != expectNetworkId { |
||||
t.Fatalf("Expected network ID to be %d, got %d", expectNetworkId, info.NetworkId) |
||||
} |
||||
|
||||
if info.SyncEnabled != true { |
||||
t.Fatal("Expected Sync to be enabled, but is false") |
||||
} |
||||
|
||||
if info.StoreParams.DbCapacity != 9000000 { |
||||
t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkId) |
||||
} |
||||
|
||||
if info.ChunkerParams.Branches != 64 { |
||||
t.Fatalf("Expected chunker params branches to be %d, got %d", 64, info.ChunkerParams.Branches) |
||||
} |
||||
|
||||
if info.HiveParams.CallInterval != 6000000000 { |
||||
t.Fatalf("Expected HiveParams CallInterval to be %d, got %d", uint64(6000000000), uint64(info.HiveParams.CallInterval)) |
||||
} |
||||
|
||||
if info.Swap.Params.Strategy.AutoCashInterval != 600*time.Second { |
||||
t.Fatalf("Expected SwapParams AutoCashInterval to be %ds, got %d", 600, info.Swap.Params.Strategy.AutoCashInterval) |
||||
} |
||||
|
||||
if info.SyncParams.KeyBufferSize != 512 { |
||||
t.Fatalf("Expected info.SyncParams.KeyBufferSize to be %d, got %d", 512, info.SyncParams.KeyBufferSize) |
||||
} |
||||
|
||||
node.Shutdown() |
||||
} |
@ -1,141 +0,0 @@ |
||||
// Copyright 2017 The go-ethereum Authors
|
||||
// This file is part of go-ethereum.
|
||||
//
|
||||
// go-ethereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// go-ethereum 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 General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"testing" |
||||
|
||||
"github.com/ethereum/go-ethereum/swarm" |
||||
) |
||||
|
||||
func TestParseFlagEnsAPI(t *testing.T) { |
||||
for _, x := range []struct { |
||||
description string |
||||
value string |
||||
config swarm.ENSClientConfig |
||||
}{ |
||||
{ |
||||
description: "IPC endpoint", |
||||
value: "/data/testnet/geth.ipc", |
||||
config: swarm.ENSClientConfig{ |
||||
Endpoint: "/data/testnet/geth.ipc", |
||||
}, |
||||
}, |
||||
{ |
||||
description: "HTTP endpoint", |
||||
value: "http://127.0.0.1:1234", |
||||
config: swarm.ENSClientConfig{ |
||||
Endpoint: "http://127.0.0.1:1234", |
||||
}, |
||||
}, |
||||
{ |
||||
description: "WS endpoint", |
||||
value: "ws://127.0.0.1:1234", |
||||
config: swarm.ENSClientConfig{ |
||||
Endpoint: "ws://127.0.0.1:1234", |
||||
}, |
||||
}, |
||||
{ |
||||
description: "IPC Endpoint and TLD", |
||||
value: "test:/data/testnet/geth.ipc", |
||||
config: swarm.ENSClientConfig{ |
||||
Endpoint: "/data/testnet/geth.ipc", |
||||
TLD: "test", |
||||
}, |
||||
}, |
||||
{ |
||||
description: "HTTP endpoint and TLD", |
||||
value: "test:http://127.0.0.1:1234", |
||||
config: swarm.ENSClientConfig{ |
||||
Endpoint: "http://127.0.0.1:1234", |
||||
TLD: "test", |
||||
}, |
||||
}, |
||||
{ |
||||
description: "WS endpoint and TLD", |
||||
value: "test:ws://127.0.0.1:1234", |
||||
config: swarm.ENSClientConfig{ |
||||
Endpoint: "ws://127.0.0.1:1234", |
||||
TLD: "test", |
||||
}, |
||||
}, |
||||
{ |
||||
description: "IPC Endpoint and contract address", |
||||
value: "314159265dD8dbb310642f98f50C066173C1259b@/data/testnet/geth.ipc", |
||||
config: swarm.ENSClientConfig{ |
||||
Endpoint: "/data/testnet/geth.ipc", |
||||
ContractAddress: "314159265dD8dbb310642f98f50C066173C1259b", |
||||
}, |
||||
}, |
||||
{ |
||||
description: "HTTP endpoint and contract address", |
||||
value: "314159265dD8dbb310642f98f50C066173C1259b@http://127.0.0.1:1234", |
||||
config: swarm.ENSClientConfig{ |
||||
Endpoint: "http://127.0.0.1:1234", |
||||
ContractAddress: "314159265dD8dbb310642f98f50C066173C1259b", |
||||
}, |
||||
}, |
||||
{ |
||||
description: "WS endpoint and contract address", |
||||
value: "314159265dD8dbb310642f98f50C066173C1259b@ws://127.0.0.1:1234", |
||||
config: swarm.ENSClientConfig{ |
||||
Endpoint: "ws://127.0.0.1:1234", |
||||
ContractAddress: "314159265dD8dbb310642f98f50C066173C1259b", |
||||
}, |
||||
}, |
||||
{ |
||||
description: "IPC Endpoint, TLD and contract address", |
||||
value: "test:314159265dD8dbb310642f98f50C066173C1259b@/data/testnet/geth.ipc", |
||||
config: swarm.ENSClientConfig{ |
||||
Endpoint: "/data/testnet/geth.ipc", |
||||
ContractAddress: "314159265dD8dbb310642f98f50C066173C1259b", |
||||
TLD: "test", |
||||
}, |
||||
}, |
||||
{ |
||||
description: "HTTP endpoint, TLD and contract address", |
||||
value: "eth:314159265dD8dbb310642f98f50C066173C1259b@http://127.0.0.1:1234", |
||||
config: swarm.ENSClientConfig{ |
||||
Endpoint: "http://127.0.0.1:1234", |
||||
ContractAddress: "314159265dD8dbb310642f98f50C066173C1259b", |
||||
TLD: "eth", |
||||
}, |
||||
}, |
||||
{ |
||||
description: "WS endpoint, TLD and contract address", |
||||
value: "eth:314159265dD8dbb310642f98f50C066173C1259b@ws://127.0.0.1:1234", |
||||
config: swarm.ENSClientConfig{ |
||||
Endpoint: "ws://127.0.0.1:1234", |
||||
ContractAddress: "314159265dD8dbb310642f98f50C066173C1259b", |
||||
TLD: "eth", |
||||
}, |
||||
}, |
||||
} { |
||||
t.Run(x.description, func(t *testing.T) { |
||||
config := parseFlagEnsAPI(x.value) |
||||
if config.Endpoint != x.config.Endpoint { |
||||
t.Errorf("expected Endpoint %q, got %q", x.config.Endpoint, config.Endpoint) |
||||
} |
||||
if config.ContractAddress != x.config.ContractAddress { |
||||
t.Errorf("expected ContractAddress %q, got %q", x.config.ContractAddress, config.ContractAddress) |
||||
} |
||||
if config.TLD != x.config.TLD { |
||||
t.Errorf("expected TLD %q, got %q", x.config.TLD, config.TLD) |
||||
} |
||||
}) |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue