func TestSet(t *testing.T) { a := Uint(0) b := Uint(10) a.Set(b) if a.num.Cmp(b.num) != 0 { t.Error("didn't compare", a, b) } c := Uint(0).SetBytes(common.Hex2Bytes("0a")) if c.num.Cmp(big.NewInt(10)) != 0 { t.Error("c set bytes failed.") } }
// HashToUrl(contenthash) resolves the url for contenthash using UrlHint // resolution is costless non-transactional // 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) { // look up in URL reg var str string = " " var idx uint32 for len(str) > 0 { mapaddr := storageMapping(storageIdx2Addr(1), chash[:]) key := storageAddress(storageFixedArray(mapaddr, storageIdx2Addr(idx))) hex := self.backend.StorageAt(UrlHintAddr[2:], key) str = string(common.Hex2Bytes(hex[2:])) l := 0 for (l < len(str)) && (str[l] == 0) { l++ } str = str[l:] uri = uri + str idx++ } if len(uri) == 0 { err = fmt.Errorf("GetURLhint: URL hint not found for '%v'", chash.Hex()) } return }
// Returns the unsigned version of i func (i *Number) Uint256() *Number { return Uint(0).Set(i) } // Returns the index of the first bit that's set to 1 func (i *Number) FirstBitSet() int { for j := 0; j < i.num.BitLen(); j++ { if i.num.Bit(j) > 0 { return j } } return i.num.BitLen() } // Variables var ( Zero = Uint(0) One = Uint(1) Two = Uint(2) MaxUint256 = Uint(0).SetBytes(common.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) MinOne = Int(-1) // "typedefs" Uint = Uint256 Int = Int256 )