From 8b81ad1fc40080af441c0c6df94f0b2ea46e320b Mon Sep 17 00:00:00 2001 From: zelig Date: Tue, 22 Sep 2015 10:34:58 +0200 Subject: console: * lines with leading space are ommitted from history * exit processed even with whitespace around * all whitespace lines (not only empty ones) are ignored add 7 missing commands to admin api autocomplete registrar: methods now return proper error if reg addresses are not set. fixes #1457 rpc/console: fix personal.newAccount() regression. Now all comms accept interactive password registrar: add registrar tests for errors crypto: catch AES decryption error on presale wallet import + fix error msg format. fixes #1580 CLI: improve error message when starting a second instance of geth. fixes #1564 cli/accounts: unlock multiple accounts. fixes #1785 * make unlocking multiple accounts work with inline <() fd * passwdfile now correctly read only once * improve logs * fix CLI help text for unlocking fix regression with docRoot / admin API * docRoot/jspath passed to rpc/api ParseApis, which passes onto adminApi * docRoot field for JS console in order to pass when RPC is (re)started * improve flag desc for jspath common/docserver: catch http errors from response fix rpc/api tests common/natspec: fix end to end test (skipped because takes 8s) registrar: fix major regression: * deploy registrars on frontier * register HashsReg and UrlHint in GlobalRegistrar. * set all 3 contract addresses in code * zero out addresses first in tests --- common/registrar/registrar.go | 52 +++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 12 deletions(-) (limited to 'common/registrar/registrar.go') diff --git a/common/registrar/registrar.go b/common/registrar/registrar.go index d891e161e..24e45edb3 100644 --- a/common/registrar/registrar.go +++ b/common/registrar/registrar.go @@ -48,17 +48,16 @@ The Registrar uses 3 contracts on the blockchain: These contracts are (currently) not included in the genesis block. Each Set needs to be called once on each blockchain/network once. -Contract addresses need to be set (HashReg and UrlHint retrieved from the global -registrar the first time any Registrar method is called in a client session - -So the caller needs to make sure the relevant environment initialised the desired -contracts +Contract addresses need to be set the first time any Registrar method is called +in a client session. +This is done for frontier by default, otherwise the caller needs to make sure +the relevant environment initialised the desired contracts */ var ( - UrlHintAddr = "0x0" - HashRegAddr = "0x0" - GlobalRegistrarAddr = "0x0" - // GlobalRegistrarAddr = "0xc6d9d2cd449a754c494264e1809c50e34d64562b" + // GlobalRegistrarAddr = "0xc6d9d2cd449a754c494264e1809c50e34d64562b" // olympic + GlobalRegistrarAddr = "0x33990122638b9132ca29c723bdf037f1a891a70c" // frontier + HashRegAddr = "0x23bf622b5a65f6060d855fca401133ded3520620" // frontier + UrlHintAddr = "0x73ed5ef6c010727dfd2671dbb70faac19ec18626" // frontier zero = regexp.MustCompile("^(0x)?0*$") ) @@ -113,7 +112,7 @@ func (self *Registrar) SetGlobalRegistrar(namereg string, addr common.Address) ( GlobalRegistrarAddr = namereg return } - if GlobalRegistrarAddr == "0x0" || GlobalRegistrarAddr == "0x" { + if zero.MatchString(GlobalRegistrarAddr) { if (addr == common.Address{}) { err = fmt.Errorf("GlobalRegistrar address not found and sender for creation not given") return @@ -200,6 +199,9 @@ func (self *Registrar) SetUrlHint(urlhint string, addr common.Address) (txhash s // ReserveName(from, name) reserves name for the sender address in the globalRegistrar // the tx needs to be mined to take effect func (self *Registrar) ReserveName(address common.Address, name string) (txh string, err error) { + if zero.MatchString(GlobalRegistrarAddr) { + return "", fmt.Errorf("GlobalRegistrar address is not set") + } nameHex, extra := encodeName(name, 2) abi := reserveAbi + nameHex + extra glog.V(logger.Detail).Infof("Reserve data: %s", abi) @@ -215,6 +217,10 @@ func (self *Registrar) ReserveName(address common.Address, name string) (txh str // in the globalRegistrar using from as the sender of the transaction // the tx needs to be mined to take effect func (self *Registrar) SetAddressToName(from common.Address, name string, address common.Address) (txh string, err error) { + if zero.MatchString(GlobalRegistrarAddr) { + return "", fmt.Errorf("GlobalRegistrar address is not set") + } + nameHex, extra := encodeName(name, 6) addrHex := encodeAddress(address) @@ -231,6 +237,10 @@ func (self *Registrar) SetAddressToName(from common.Address, name string, addres // NameToAddr(from, name) queries the registrar for the address on name func (self *Registrar) NameToAddr(from common.Address, name string) (address common.Address, err error) { + if zero.MatchString(GlobalRegistrarAddr) { + return address, fmt.Errorf("GlobalRegistrar address is not set") + } + nameHex, extra := encodeName(name, 2) abi := resolveAbi + nameHex + extra glog.V(logger.Detail).Infof("NameToAddr data: %s", abi) @@ -249,6 +259,9 @@ func (self *Registrar) NameToAddr(from common.Address, name string) (address com // called as first step in the registration process on HashReg func (self *Registrar) SetOwner(address common.Address) (txh string, err error) { + if zero.MatchString(HashRegAddr) { + return "", fmt.Errorf("HashReg address is not set") + } return self.backend.Transact( address.Hex(), HashRegAddr, @@ -261,6 +274,10 @@ func (self *Registrar) SetOwner(address common.Address) (txh string, err error) // e.g., the contract Info combined Json Doc's ContentHash // to CodeHash of a contract or hash of a domain func (self *Registrar) SetHashToHash(address common.Address, codehash, dochash common.Hash) (txh string, err error) { + if zero.MatchString(HashRegAddr) { + return "", fmt.Errorf("HashReg address is not set") + } + _, err = self.SetOwner(address) if err != nil { return @@ -284,6 +301,10 @@ func (self *Registrar) SetHashToHash(address common.Address, codehash, dochash c // FIXME: silently doing nothing if sender is not the owner // note that with content addressed storage, this step is no longer necessary func (self *Registrar) SetUrlToHash(address common.Address, hash common.Hash, url string) (txh string, err error) { + if zero.MatchString(UrlHintAddr) { + return "", fmt.Errorf("UrlHint address is not set") + } + hashHex := common.Bytes2Hex(hash[:]) var urlHex string urlb := []byte(url) @@ -321,13 +342,17 @@ func (self *Registrar) SetUrlToHash(address common.Address, hash common.Hash, ur // resolution is costless non-transactional // implemented as direct retrieval from db func (self *Registrar) HashToHash(khash common.Hash) (chash common.Hash, err error) { + if zero.MatchString(HashRegAddr) { + return common.Hash{}, fmt.Errorf("HashReg address is not set") + } + // look up in hashReg at := HashRegAddr[2:] key := storageAddress(storageMapping(storageIdx2Addr(1), khash[:])) hash := self.backend.StorageAt(at, key) if hash == "0x0" || len(hash) < 3 || (hash == common.Hash{}.Hex()) { - err = fmt.Errorf("content hash not found for '%v'", khash.Hex()) + err = fmt.Errorf("HashToHash: content hash not found for '%v'", khash.Hex()) return } copy(chash[:], common.Hex2BytesFixed(hash[2:], 32)) @@ -339,6 +364,9 @@ func (self *Registrar) HashToHash(khash common.Hash) (chash common.Hash, err err // implemented as direct retrieval from db // if we use content addressed storage, this step is no longer necessary func (self *Registrar) HashToUrl(chash common.Hash) (uri string, err error) { + if zero.MatchString(UrlHintAddr) { + return "", fmt.Errorf("UrlHint address is not set") + } // look up in URL reg var str string = " " var idx uint32 @@ -358,7 +386,7 @@ func (self *Registrar) HashToUrl(chash common.Hash) (uri string, err error) { } if len(uri) == 0 { - err = fmt.Errorf("GetURLhint: URL hint not found for '%v'", chash.Hex()) + err = fmt.Errorf("HashToUrl: URL hint not found for '%v'", chash.Hex()) } return } -- cgit v1.2.3