bool VarValue::operator==(const VarValue& v) const { if (type() != v.type()) return false; switch (type()) { case VarType::Null: return true; case VarType::Bool: return ToBool() == v.ToBool(); case VarType::Int: return ToInt64() == v.ToInt64(); case VarType::Float: return ToDouble() == v.ToDouble(); case VarType::String: return ToString() == v.ToString(); case VarType::Array: if (size() != v.size()) return false; for (int i=0; i<size(); ++i) if (_self[i] != v[i]) return false; return true; case VarType::Map: { if (size() != v.size()) return false; vector<String> keys = Keys(); for (int i=0; i<keys.size(); ++i) { const String& key = keys[i]; if (!v.HasKey(key) || _self[key] != v[key]) return false; } return true; } default: Throw(E_NOTIMPL); } }
size_t hash_value(const VarValue& v) { switch (v.type()) { case VarType::Null: return 0; case VarType::Int: return hash<Int64>()(v.ToInt64()); case VarType::Float: return hash<double>()(v.ToDouble()); case VarType::Bool: return hash<bool>()(v.ToBool()); case VarType::String: return hash<String>()(v.ToString()); case VarType::Array: { size_t r = 0; for (int i=0; i<v.size(); ++i) r += hash<VarValue>()(v[i]); return r; } case VarType::Map: { vector<String> keys = v.Keys(); size_t r = 0; for (int i=0; i<keys.size(); ++i) r += hash<VarValue>()(v[keys[i]]); return r; } default: Throw(E_NOTIMPL); } }
SinceBlockInfo ListSinceBlock(const HashValue& hashBlock) override { SinceBlockInfo r; VarValue v = !hashBlock ? Call("listsinceblock") : Call("listsinceblock", EXT_STR(hashBlock)); r.LastBlock = HashValue(v["lastblock"].ToString()); VarValue vtx = v["transactions"]; r.Txes.resize(vtx.size()); for (int i=0; i<r.Txes.size(); ++i) r.Txes[i] = ToTxInfo(vtx[i]); return r; }
BlockInfo GetBlock(const HashValue& hashBlock) override { BlockInfo r; VarValue v = Call("getblock", EXT_STR(hashBlock)); r.Version = (int32_t)v["version"].ToInt64(); r.Timestamp = DateTime::from_time_t(v["time"].ToInt64()); r.Hash = HashValue(v["hash"].ToString()); if (VarValue vpbh = v["previousblockhash"]) r.PrevBlockHash = HashValue(vpbh.ToString()); r.MerkleRoot = HashValue(v["merkleroot"].ToString()); r.Height = (int)v["height"].ToInt64(); r.Confirmations = (int)v["confirmations"].ToInt64(); r.Difficulty = v["difficulty"].ToDouble(); VarValue vtx = v["tx"]; r.HashTxes.resize(vtx.size()); for (size_t i=0; i<r.HashTxes.size(); ++i) r.HashTxes[i] = HashValue(vtx[i].ToString()); return r; }