Example #1
0
TxInfo ToTxInfo(const VarValue& v) {
	TxInfo r;
	if (VarValue vAddress = v["address"])
		r.Address = vAddress.ToString();
	r.HashTx = HashValue(v["txid"].ToString());
	r.Confirmations = int32_t(v["confirmations"].ToInt64());
	r.Timestamp = DateTime::from_time_t(v["time"].ToInt64());
	if (r.Confirmations) {
		r.HashBlock = HashValue(v["blockhash"].ToString());
	}
	r.Amount = AmountToDecimal(v["amount"]);
	r.Generated = v.HasKey("generated") && v["generated"].ToBool();
	if (VarValue vDetails = v["details"]) {
		for (size_t i=0; i<vDetails.size(); ++i) {
			VarValue vd = vDetails[i];
			TxInfo::TxDetails d;
			d.Account = vd["account"].ToString();
			d.Address = vd["address"].ToString();
			d.IsSend = vd["category"].ToString() == "send";
			d.Amount = AmountToDecimal(vd["amount"]);
			r.Details.push_back(d);
		}
	}
	return r;
}
Example #2
0
_int64 JoinerHashTable::InitCurrentRowToGet()
{
	//MEASURE_FET("JoinerHashTable::InitCurrentRowToGet()");
	unsigned int crc_code = HashValue( input_buffer, key_buf_width );
	current_row = crc_code % no_rows;
	// vertical table size is not dividable by the following step values, so they will eventually
	// iterate through the whole table
	current_iterate_step = prime_steps[crc_code % prime_steps_no];
	_int64 startrow = current_row;
	to_be_returned = 0;
	unsigned char *cur_t;
	_int64 multiplier;
	do {
		cur_t = t + current_row * total_width;
		multiplier = *(_int64*)(cur_t + mult_offset);
		if(multiplier != 0) {
			if(memcmp(cur_t, input_buffer, key_buf_width) == 0) {
				// i.e. identical row found
				to_be_returned = multiplier;
				return multiplier;
			}
			else {									// some other value found
				// iterate one step forward
				current_row += current_iterate_step;
				if(current_row >= no_rows)
					current_row = current_row % no_rows;
			}
		} else {
			current_row = NULL_VALUE_64;	// not found
			return 0;
		}
	} while(current_row != startrow);
	current_row = NULL_VALUE_64;			// not found at all
	return 0;
}
	//
	// 加载渲染过程
	//
	VOID CRenderSolution::LoadFromStream(TiXmlNode *pRenderSolutionNode)
	{
		ASSERT(pRenderSolutionNode);

		if (TiXmlNode *pRenderStageNode = pRenderSolutionNode->FirstChild("RenderStage")) {
			do {
				//
				// 1. 获得渲染过程名
				//
				const CHAR *szName = pRenderStageNode->ToElement()->AttributeString("name");
				if (szName == NULL) throw "No render stage name.";

				//
				// 2. 检查是否已经加载
				//
				DWORD dwName = HashValue(szName);
				RenderStageMap::const_iterator itRenderStage = m_renderStageMap.find(dwName);
				if (itRenderStage != m_renderStageMap.end()) continue;

				//
				// 3. 加载渲染过程
				//
				CRenderStage *pRenderStage = SAFE_NEW(MEMTYPE_HEAP) CRenderStage(m_pRenderFlow);
				ASSERT(pRenderStage);

				m_renderStageSet.push_back(pRenderStage);
				m_renderStageMap[dwName] = pRenderStage; // 注意: 先添加到渲染过程集合后再加载渲染过程, 
				                                         //避免内存泄漏!!!

				pRenderStage->LoadFromStream(pRenderStageNode);
			} while (pRenderStageNode = pRenderSolutionNode->IterateChildren("RenderStage", pRenderStageNode));
		}
	}
Example #4
0
Blob ConvertFromBase58ShaSquare(RCString s) {
	BigInteger bi = 0;
	for (const char *p=s; *p; ++p) {
		if (const char *q = strchr(s_pszBase58, *p)) {
			bi = bi*58 + BigInteger(q-s_pszBase58);
		} else
			Throw(E_INVALIDARG);
	}
	vector<byte> v((bi.Length+7)/8);
	bi.ToBytes(&v[0], v.size());
	if (v.size()>=2 && v.end()[-1]==0 && v.end()[-1]>=0x80)
		v.resize(v.size()-1);
	vector<byte> r;
	for (const char *p=s; *p==s_pszBase58[0]; ++p)
		r.push_back(0);
	r.resize(r.size()+v.size());
	std::reverse_copy(v.begin(), v.end(), r.end()-v.size());
	if (r.size() < 4)
		Throw(E_FAIL);
	SHA256 sha;
	HashValue hash = HashValue(sha.ComputeHash(sha.ComputeHash(ConstBuf(&r[0], r.size()-4))));
	if (memcmp(hash.data(), &r.end()[-4], 4))
		Throw(HRESULT_FROM_WIN32(ERROR_CRC));
	return Blob(&r[0], r.size()-4);
}
Example #5
0
HashValue MinerShare::GetHash() const {
	switch (Algo) {
	case HashAlgo::Sha3:
	{
		MemoryStream ms;
		base::WriteHeader(ProtocolWriter(ms).Ref());
		return HashValue(SHA3<256>().ComputeHash(ms));
	}
	case HashAlgo::Metis:
	{
		MemoryStream ms;
		base::WriteHeader(ProtocolWriter(ms).Ref());
		return MetisHash(ms);
	}
#if UCFG_COIN_MOMENTUM
	case HashAlgo::Momentum:
	{
		MemoryStream ms;
		base::WriteHeader(ProtocolWriter(ms).Ref());
		if (!MomentumVerify(Coin::Hash(ms), BirthdayA, BirthdayB))
			return s_hashMax;
	}
#endif
	default:
		return base::GetHash();
	}
}
Example #6
0
  bool BASE_INDEX_3_CLOSED_HASHTABLE ::
  PositionCreate2 (const INDEX_3 & ind, int & apos) 
  {
    int i = HashValue(ind);
    int startpos = i;
    while (1)
      {
        /*
	i++;
	if (i >= hash.Size()) i = 0;
        */
        i = (i+1) % hash.Size();
	if (hash[i] == ind) 
	  {
	    apos = i;
	    return false;
	  }
	if (hash[i].I1() == invalid) 
	  {
	    hash[i] = ind;
	    apos = i;
	    return true;
	  }
	if (i == startpos)
	  throw NgException ("Try to set new element in full closed hashtable");
      }
  }
Example #7
0
			static constexpr uint64_t hash(const char* str
				,HashValue value_init=OFFSET_BASIS)
				{
				return *str=='\0'?
					 value_init
					:hash(str+1, (value_init^(HashValue(*str)))*FNV_PRIME);
				}
	//
	// 加载渲染方案
	//
	VOID CRenderFlow::LoadRenderSolutions(TiXmlNode *pRenderFlowNode)
	{
		ASSERT(pRenderFlowNode);

		if (TiXmlNode *pRenderSolutionNode = pRenderFlowNode->FirstChild("RenderSolution")) {
			do {
				//
				// 1. 获得渲染方案名
				//
				const CHAR *szName = pRenderSolutionNode->ToElement()->AttributeString("name");
				if (szName == NULL) throw "No render solution name.";

				//
				// 2. 检查是否已经加载
				//
				DWORD dwName = HashValue(szName);
				RenderSolutionMap::const_iterator itRenderSolution = m_renderSolutions.find(dwName);
				if (itRenderSolution != m_renderSolutions.end()) continue;

				//
				// 3. 加载渲染方案
				//
				CRenderSolution *pRenderSolution = SAFE_NEW(MEMTYPE_HEAP) CRenderSolution(this);
				ASSERT(pRenderSolution);

				m_renderSolutions[dwName] = pRenderSolution; // 注意: 先添加到渲染方案集合后再加载渲染方案, 
				                                             //       避免内存泄漏!!!

				pRenderSolution->LoadFromStream(pRenderSolutionNode);
			} while (pRenderSolutionNode = pRenderFlowNode->IterateChildren("RenderSolution", pRenderSolutionNode));
		}
	}
	//
	// 加载渲染对象
	//
	VOID CRenderFlow::LoadRenderTargets(TiXmlNode *pRenderFlowNode)
	{
		ASSERT(pRenderFlowNode);

		if (TiXmlNode *pRenderTargetNode = pRenderFlowNode->FirstChild("RenderTarget")) {
			do {
				//
				// 1. 获得渲染对象名
				//
				const CHAR *szName = pRenderTargetNode->ToElement()->AttributeString("category");
				if (szName == NULL) throw "No render target category.";

				//
				// 2. 检查是否已经加载
				//
				DWORD dwName = HashValue(szName);
				RenderTargetMap::const_iterator itRenderTarget = m_renderTargets.find(dwName);
				if (itRenderTarget != m_renderTargets.end()) continue;

				//
				// 3. 加载渲染对象
				//
				CRenderTarget *pRenderTarget = SAFE_NEW(MEMTYPE_HEAP) CRenderTarget(this);
				ASSERT(pRenderTarget);

				m_renderTargets[dwName] = pRenderTarget; // 注意: 先添加到渲染对象集合后再加载渲染对象, 
				                                         //       避免内存泄漏!!!

				pRenderTarget->LoadFromStream(pRenderTargetNode);
			} while (pRenderTargetNode = pRenderFlowNode->IterateChildren("RenderTarget", pRenderTargetNode));
		}
	}
Example #10
0
	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;
	}
Example #11
0
  int Position (const INDEX_3 & ind) const
  {
    int i = HashValue(ind);
    for (;;)
      {
	if (hash[i] == ind) return i;
	if (hash[i].I1() == invalid) return -1;
        i = (i+1) % hash.Size();
      }
  }
Example #12
0
	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;
	}
Example #13
0
  int Position (const INDEX_2 & ind) const
  {
    int i = HashValue(ind);
    for (;;)
      {
	if (hash.Get(i) == ind) return i;
	if (hash.Get(i).I1() == invalid) return 0;
	i++;
	if (i > hash.Size()) i = 1;
      }
  }
  int Position (const INDEX & ind) const
  {
    int i = HashValue(ind);
    while (1)
      {
	if (hash.Get(i) == ind) return i;
	if (hash.Get(i) == invalid) return 0;
	i++;
	if (i > hash.Size()) i = 1;
      }
  }
Example #15
0
  int BASE_INDEX_CLOSED_HASHTABLE ::
  Position2 (const INDEX & ind) const
  {
    int i = HashValue(ind);
    while (1)
      {
	i++;
	if (i > hash.Size()) i = 1;
	if (hash.Get(i) == ind) return i;
	if (hash.Get(i) == invalid) return 0;
      }
  }
Example #16
0
inline void INDEX_3_HASHTABLE<T> :: Set (const INDEX_3 & ahash, const T & acont)
{
  int bnr = HashValue (ahash);
  int pos = Position (bnr, ahash);
  if (pos)
    cont.Set (bnr, pos, acont);
  else
    {
      hash.Add1 (bnr, ahash);
      cont.Add1 (bnr, acont);
    }
}
Example #17
0
  void Set (const INDEX_2 & ahash, const T & acont)
  {
    int bnr = HashValue (ahash);
      int pos = Position (bnr, ahash);
      if (pos)
	cont.Set (bnr, pos, acont);
      else
	{
	  hash.Add1 (bnr, ahash);
	  cont.Add1 (bnr, acont);
	}    
  }
Example #18
0
  int Costs (const INDEX_3 & ind) const
  {
    int i = HashValue(ind);
    int c = 1;
    for (;;)
      {
	if (hash[i] == ind) return c;
	if (hash[i].I1() == invalid) return c;
        i = (i+1) % hash.Size();
        c++;
      }
  }
Example #19
0
inline int INDEX_3_HASHTABLE<T> :: PositionCreate (const INDEX_3 & ahash, int & bnr, int & colnr)
{
  bnr = HashValue (ahash);
  colnr = Position (bnr, ahash);
  if (!colnr)
    {
      hash.Add (bnr, ahash);
      cont.AddEmpty (bnr);
      colnr = cont.EntrySize (bnr);
      return 1;
    }
  return 0;
}
Example #20
0
  int CalcPositionCosts (const INDEX & ind) const
  {
    int i = HashValue(ind);
    int costs = 1;
    for (;;)
      {
	if (hash.Get(i) == ind) return costs;
	if (hash.Get(i) == invalid) return costs;
	i++;
	if (i > hash.Size()) i = 1;
	costs++;
      }
  }
Example #21
0
  // returns true, if new postion is created
  bool PositionCreate (const INDEX_3 & ind, int & apos)
  {
    int i = HashValue (ind);
    if (hash[i] == ind) 
      {
	apos = i;
	return false;
      }
    if (hash[i].I1() == invalid)
      {
	hash[i] = ind; 
	apos = i;
	return true;
      }
    return PositionCreate2 (ind, apos);    
  }
Example #22
0
  // returns 1, if new postion is created
  int PositionCreate (const INDEX_2 & ind, int & apos)
  {
    int i = HashValue (ind);
    if (hash.Get(i) == ind) 
      {
	apos = i;
	return 0;
      }
    if (hash.Get(i).I1() == invalid)
      {
	hash.Elem(i) = ind; 
	apos = i;
	return 1;
      }
    return PositionCreate2 (ind, apos);    
  }
Example #23
0
_int64 JoinerHashTable::FindAndAddCurrentRow()	// a position in the current JoinerHashTable, NULL_VALUE_64 if no more space
{
	//MEASURE_FET("JoinerHashTable::FindAndAddCurrentRow()");
	if(no_of_occupied >= rows_limit)		// no more space
		return NULL_VALUE_64;

	unsigned int crc_code = HashValue(input_buffer, key_buf_width);
	_int64 row = crc_code % no_rows;
	// vertical table size is not dividable by the following step values, so they will eventually
	// iterate through the whole table
	_int64 iterate_step = prime_steps[crc_code % prime_steps_no];
	_int64 startrow = row;
	unsigned char *cur_t;
	do {
		cur_t = t + row * total_width;
		_int64 *multiplier = (_int64*)(cur_t + mult_offset);
		if(*multiplier != 0) {
			if(memcmp(cur_t, input_buffer, key_buf_width) == 0) {
				// i.e. identical row found
				_int64 last_multiplier = *multiplier;
				assert(last_multiplier>0);
				(*multiplier)++;
				if(for_count_only)
					return row;
				// iterate several steps forward to find some free location
				row += iterate_step * last_multiplier;
				if(row >= no_rows)
					row = row % no_rows;

				if(*multiplier > MAX_HASH_CONFLICTS)	// a threshold for switching sides
					too_many_conflicts = true;
			}
			else {										// some other value found
				// iterate one step forward
				row += iterate_step;
				if(row >= no_rows)
					row = row % no_rows;
			}
		} else {
			memcpy(cur_t, input_buffer, key_buf_width);
			*multiplier = 1;
			no_of_occupied++;
			return row;
		}
	} while(row != startrow);
	return NULL_VALUE_64;			// search deadlock (we returned to the same position)
}
Example #24
0
String ConvertToBase58ShaSquare(const ConstBuf& cbuf) {
	SHA256 sha;
	HashValue hash = HashValue(sha.ComputeHash(sha.ComputeHash(cbuf)));
	Blob v = cbuf + Blob(hash.data(), 4);
	vector<char> r;

	vector<byte> tmp(v.Size+1, 0);
	std::reverse_copy(v.begin(), v.end(), tmp.begin());
	for (BigInteger n(&tmp[0], tmp.size()); Sign(n);) {
		pair<BigInteger, BigInteger> pp = div(n, 58);
		n = pp.first;
		r.insert(r.begin(), s_pszBase58[explicit_cast<int>(pp.second)]);
	}

	for (int i=0; i<v.Size && !v.constData()[i]; ++i)
		r.insert(r.begin(), s_pszBase58[0]);
	return String(&r[0], r.size());
}
Example #25
0
  int BASE_INDEX_CLOSED_HASHTABLE ::
  PositionCreate2 (const INDEX & ind, int & apos) 
  {
    int i = HashValue(ind);
    int startpos = i;
    while (1)
      {
	i++;
	if (i > hash.Size()) i = 1;
	if (hash.Get(i) == ind) 
	  {
	    apos = i;
	    return 0;
	  }
	if (hash.Get(i) == invalid) 
	  {
	    hash.Elem(i) = ind;
	    apos = i;
	    return 1;
	  }
	if (i == startpos)
	  throw NgException ("Try to set new element in full closed hashtable");
      }
  }
Example #26
0
 bool Used (const INDEX_2 & ahash) const
 {
   return Position (HashValue (ahash), ahash) > 0;
 }
Example #27
0
 const T & Get (const INDEX_2 & ahash) const
 {
   int bnr = HashValue (ahash);
   int pos = Position (bnr, ahash);
   return cont.Get (bnr, pos);
 }
Example #28
0
inline bool INDEX_HASHTABLE<T> :: Used (const INDEX & ahash) const
    {
    return (Position (HashValue (ahash), ahash)) ? 1 : 0;
    }
Example #29
0
inline const T & INDEX_HASHTABLE<T> :: Get (const INDEX & ahash) const
    {
    int bnr = HashValue (ahash);
    int pos = Position (bnr, ahash);
    return cont.Get (bnr, pos);
    }
Example #30
-1
	void MineNparNonces(BitcoinMiner& miner, BitcoinWorkData& wd, UInt32 *buf, UInt32 nonce) override {
		for (int i=0; i<UCFG_BITCOIN_NPAR; i+=3, nonce+=3) {
			SetNonce(buf, nonce);
			array<array<UInt32, 8>, 3> res3 = CalcSCryptHash_80_3way(buf);
			for (int j=0; j<3; ++j) {
				if (HashValue(ConstBuf(res3[j].data(), 32)) <= wd.HashTarget) {
					if (!miner.TestAndSubmit(&wd, htobe(nonce+j)))
						*miner.m_pTraceStream << "Found NONCE not accepted by Target" << endl;
				}
			}
		}
	}