mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
synced up to go-ethereum 1.5.0-unstable develop branch major features: * api overhaul due to rpc v2 and node service stack interface changes * blockchain/ethereum contract interaction rewritten using abi/abigen (chequebook, ens) * swarm - cluster control CLI - migration and revamp of prehistoric eth-utils repo * poor man's end to end testing: scripted scenarios in swarm/test using swarm CLI * http proxy now handles 3 url schemes for 1) ens-enabled [bzz], 2) immutable [bzzi] and 3) raw manifest [bzzr] resolution * fixes issues with remote address setting, forwarding and syncing * new control flags to switch swap and sync on and off * placeholder basic implementation Ethereum Name Service * improved logging - now debug level is coherent regression: * uri based versioning support is dropped temporarily since state tree pruning does not guarantee historical record * registrar related functionality temporarily restricted - current ENS provides basic free and unrestricted Register/Resolve accounts/abi: * bind: repeated attempt deployment of contracts, validation against known code, transactor creation from private keys * accountmanager: getUnlocked snatch private key when unlocked cmd: * unlockAccount moved to utils/cmd and exported * getPassPhrase moved to utils/input and exported * accountcmds: reflect the change * js: GlobalRegistrar is dropped (ens) flags: * chequebook, bzzaccount, bzzport, bzzconfig, bzznoswap, bzznosync chequebook: * move from common/ to swarm/services * abigen-ised * specifies its own API (removed chequebook api from swarm/api) kademlia: * move from common to swarm/network/kademlia * address abstracted out to separate file + tests dns/ens/registrar: * moved from swarm/api to swarm/services/ens * implementation is basic placeholder before ENS is implemented * temporary rpc api via ens namespace * the old common/registrar is removed (also from eth/backend apis) swap: * the abstract swap module moved from common to swarm/services * now embedded in the swarm and chequebook specific setup (this will change) * safer chequebook deployment using abigen helpers * backend not field of swap params eth: * public accessor for GPO, needed to construct a PublicBlockChainAPI * extends ContractBackend in eth/bind.go with BalanceAt, GetTxReceipt and CodeAt API calls internal/web3ext * add js bindings for bzz, chequebook rpc apis swarm/api: * refactored api into smaller modules filesystem/storage/testapi * ethereum backend (needed for dns, swap, etc) moved to abi/bind * TODO: further refactor due to #2040 * swarm/api/http: now supports the 3 uri schemes * examples/album updated swarm/cmd: * migrate old eth-utils and modify into a cluster control CLI * bzzup now allows non-local gateway, endpoint specified as second argument swarm/network: * forwarder improved log messages, fixup condition on whether syncer is nil * hive extended with controls for testing support block read/write, swap/sync enabled/disabled * hive keepAlive launches with alarm in case no discover and no kaddb * fix IP address formatting issue [::1] -> became ::1 which refused to dial, now use discover.NewNode#String * integrate functionality for enabling/disabling sync and swap * allow nil sync state - improve syncer interface in protocol * fix SData slice out of bounds bug swarm/test * poor man's testing framework. scripts invoking swarm/cmd/swarm * added tests for basic scenarios connections, swap, sync swarm: * rewrite api using rpc v2 * blockchain comms via abi/abigen + eth.ContractBackend * integrate new flags
109 lines
3.4 KiB
Go
109 lines
3.4 KiB
Go
package bind
|
|
|
|
import (
|
|
"fmt"
|
|
"math/big"
|
|
"time"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
"github.com/ethereum/go-ethereum/logger"
|
|
"github.com/ethereum/go-ethereum/logger/glog"
|
|
)
|
|
|
|
type DeployOptions struct {
|
|
ReceiptQueryInterval time.Duration
|
|
DeployRetryInterval time.Duration
|
|
ConfirmationInterval time.Duration
|
|
MaxReceiptQueryAttempts int
|
|
MaxDeployAttempts int
|
|
}
|
|
|
|
func DefaultDeployOptions() *DeployOptions {
|
|
return &DeployOptions{
|
|
ReceiptQueryInterval: 10000000000, // 10 sec
|
|
DeployRetryInterval: 5000000000, // 5 sec
|
|
ConfirmationInterval: 60000000000, // 60 sec
|
|
MaxReceiptQueryAttempts: 5,
|
|
MaxDeployAttempts: 100,
|
|
}
|
|
}
|
|
|
|
// implemented by eth.APIBackend
|
|
type Backend interface {
|
|
GetTxReceipt(txhash common.Hash) *types.Receipt
|
|
CodeAt(address common.Address) string
|
|
BalanceAt(address common.Address) *big.Int
|
|
ContractBackend
|
|
}
|
|
|
|
func Deploy(deployF func(*TransactOpts, ContractBackend) (*types.Transaction, error), contractCode string, deployTransactor *TransactOpts, opt *DeployOptions, backend Backend) (contractAddr common.Address, err error) {
|
|
|
|
deployRetryTimer := time.NewTimer(0).C
|
|
var receiptQueryTimer <-chan time.Time
|
|
var deployRetries, receiptQueries int
|
|
var txhash common.Hash
|
|
|
|
DEPLOY:
|
|
for {
|
|
select {
|
|
case <-deployRetryTimer:
|
|
deployRetries++
|
|
if deployRetries == opt.MaxDeployAttempts {
|
|
return common.Address{}, fmt.Errorf("deployment failed...giving up after %v attempts", opt.MaxDeployAttempts)
|
|
}
|
|
tx, err := deployF(deployTransactor, backend)
|
|
if err != nil {
|
|
glog.V(logger.Warn).Infof("deployment failed: %v (attempt %v)", err, deployRetries)
|
|
deployRetryTimer = time.NewTimer(opt.DeployRetryInterval).C
|
|
continue DEPLOY
|
|
}
|
|
|
|
txhash = tx.Hash()
|
|
deployRetryTimer = nil
|
|
receiptQueryTimer = time.NewTimer(0).C
|
|
|
|
case <-receiptQueryTimer:
|
|
receipt := backend.GetTxReceipt(txhash)
|
|
receiptQueries++
|
|
if receipt == nil {
|
|
if receiptQueries == opt.MaxReceiptQueryAttempts {
|
|
glog.V(logger.Warn).Infof("attempt %s deployment failed. Given up after %v attempts", opt.MaxReceiptQueryAttempts)
|
|
|
|
deployRetryTimer = time.NewTimer(opt.DeployRetryInterval).C
|
|
receiptQueryTimer = nil
|
|
continue DEPLOY
|
|
|
|
}
|
|
glog.V(logger.Detail).Infof("new checkbook contract (txhash: %v) not yet mined... checking in %v", txhash.Hex(), opt.ReceiptQueryInterval)
|
|
receiptQueryTimer = time.NewTimer(opt.ReceiptQueryInterval).C
|
|
continue DEPLOY
|
|
}
|
|
|
|
contractAddr = receipt.ContractAddress
|
|
glog.V(logger.Detail).Infof("new chequebook contract mined at %v (owner: %v)", contractAddr.Hex(), deployTransactor.From.Hex())
|
|
<-time.NewTimer(opt.ConfirmationInterval).C
|
|
err = Validate(contractAddr, contractCode, backend)
|
|
if err != nil {
|
|
glog.V(logger.Warn).Infof("invalid contract at %v after %v: %v", contractAddr.Hex(), opt.ConfirmationInterval, err)
|
|
deployRetryTimer = time.NewTimer(opt.DeployRetryInterval).C
|
|
receiptQueryTimer = nil
|
|
continue DEPLOY
|
|
}
|
|
break DEPLOY
|
|
|
|
} // select
|
|
} // for
|
|
return contractAddr, nil
|
|
}
|
|
|
|
func Validate(contractAddr common.Address, expCode string, backend Backend) (err error) {
|
|
if (contractAddr == common.Address{}) {
|
|
return fmt.Errorf("zero address")
|
|
}
|
|
code := backend.CodeAt(contractAddr)
|
|
if len(expCode) > 0 && code != expCode {
|
|
return fmt.Errorf("incorrect code %v:\n%v\n%v", contractAddr.Hex(), code, expCode)
|
|
}
|
|
return nil
|
|
}
|