本文整理汇总了C++中h256::data方法的典型用法代码示例。如果您正苦于以下问题:C++ h256::data方法的具体用法?C++ h256::data怎么用?C++ h256::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类h256
的用法示例。
在下文中一共展示了h256::data方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: recover
Public dev::recover(Signature const& _sig, h256 const& _message)
{
int v = _sig[64];
if (v > 3)
return {};
auto* ctx = getCtx();
secp256k1_ecdsa_recoverable_signature rawSig;
if (!secp256k1_ecdsa_recoverable_signature_parse_compact(ctx, &rawSig, _sig.data(), v))
return {};
secp256k1_pubkey rawPubkey;
if (!secp256k1_ecdsa_recover(ctx, &rawPubkey, &rawSig, _message.data()))
return {};
std::array<byte, 65> serializedPubkey;
size_t serializedPubkeySize = serializedPubkey.size();
secp256k1_ec_pubkey_serialize(
ctx, serializedPubkey.data(), &serializedPubkeySize,
&rawPubkey, SECP256K1_EC_UNCOMPRESSED
);
assert(serializedPubkeySize == serializedPubkey.size());
// Expect single byte header of value 0x04 -- uncompressed public key.
assert(serializedPubkey[0] == 0x04);
// Create the Public skipping the header.
return Public{&serializedPubkey[1], Public::ConstructFromPointer};
}
示例2: update
inline void update(_T& _sha, h256 const& _value)
{
int i = 0;
byte const* data = _value.data();
for (; i != 32 && data[i] == 0; ++i);
_sha.Update(data + i, 32 - i);
}
示例3: lookup
std::string OverlayDB::lookup(h256 const& _h) const
{
std::string ret = MemoryDB::lookup(_h);
if (ret.empty() && m_db)
m_db->Get(m_readOptions, ldb::Slice((char const*)_h.data(), 32), &ret);
return ret;
}
示例4:
EthashProofOfWork::Result EthashAux::LightAllocation::compute(h256 const& _headerHash, Nonce const& _nonce) const
{
ethash_return_value r = ethash_light_compute(light, *(ethash_h256_t*)_headerHash.data(), (uint64_t)(u64)_nonce);
if (!r.success)
BOOST_THROW_EXCEPTION(DAGCreationFailure());
return EthashProofOfWork::Result{h256((uint8_t*)&r.result, h256::ConstructFromPointer), h256((uint8_t*)&r.mix_hash, h256::ConstructFromPointer)};
}
示例5: exists
bool OverlayDB::exists(h256 const& _h) const
{
if (MemoryDB::exists(_h))
return true;
std::string ret;
if (m_db)
m_db->Get(m_readOptions, ldb::Slice((char const*)_h.data(), 32), &ret);
return !ret.empty();
}
示例6: deepkill
bool OverlayDB::deepkill(h256 const& _h)
{
// kill in memoryDB
kill(_h);
//kill in overlayDB
ldb::Status s = m_db->Delete(m_writeOptions, ldb::Slice((char const*)_h.data(), 32));
if (s.ok())
return true;
else
return false;
}
示例7: sign
Signature dev::sign(Secret const& _k, h256 const& _hash)
{
#ifdef ETH_HAVE_SECP256K1
Signature s;
int v;
if (!secp256k1_ecdsa_sign_compact(s_secp256k1, _hash.data(), s.data(), _k.data(), NULL, NULL, &v))
return Signature();
s[64] = v;
return s;
#else
return s_secp256k1pp.sign(_k, _hash);
#endif
}
示例8: verify
bool dev::verify(PublicCompressed const& _key, h512 const& _signature, h256 const& _hash)
{
auto* ctx = getCtx();
secp256k1_ecdsa_signature rawSig;
if (!secp256k1_ecdsa_signature_parse_compact(ctx, &rawSig, _signature.data()))
return false;
secp256k1_pubkey rawPubkey;
if (!secp256k1_ec_pubkey_parse(ctx, &rawPubkey, _key.data(), PublicCompressed::size))
return false; // Invalid public key.
return secp256k1_ecdsa_verify(ctx, &rawSig, _hash.data(), &rawPubkey);
}
示例9: recover
Public dev::recover(Signature const& _sig, h256 const& _message)
{
Public ret;
#ifdef ETH_HAVE_SECP256K1
bytes o(65);
int pubkeylen;
if (!secp256k1_ecdsa_recover_compact(s_secp256k1, _message.data(), _sig.data(), o.data(), &pubkeylen, false, _sig[64]))
return Public();
ret = FixedHash<64>(o.data() + 1, Public::ConstructFromPointer);
#else
ret = s_secp256k1pp.recover(_sig, _message.ref());
#endif
if (ret == c_zeroKey)
return Public();
return ret;
}
示例10: fromRaw
string fromRaw(h256 _n)
{
if (_n)
{
string s((char const *)_n.data(), 32);
auto l = s.find_first_of('\0');
if (!l)
return "";
if (l != string::npos)
s.resize(l);
for (auto i: s)
if (i < 32)
return "";
return s;
}
return "";
}
示例11: kill
void OverlayDB::kill(h256 const& _h)
{
#if ELE_PARANOIA || 1
if (!MemoryDB::kill(_h))
{
std::string ret;
if (m_db)
m_db->Get(m_readOptions, ldb::Slice((char const*)_h.data(), 32), &ret);
// No point node ref decreasing for EmptyTrie since we never bother incrementing it in the first place for
// empty storage tries.
if (ret.empty() && _h != EmptyTrie)
cnote << "Decreasing DB node ref count below zero with no DB node. Probably have a corrupt Trie." << _h;
// TODO: for 1.1: ref-counted triedb.
}
#else
MemoryDB::kill(_h);
#endif
}
示例12: sign
Signature dev::sign(Secret const& _k, h256 const& _hash)
{
auto* ctx = getCtx();
secp256k1_ecdsa_recoverable_signature rawSig;
if (!secp256k1_ecdsa_sign_recoverable(ctx, &rawSig, _hash.data(), _k.data(), nullptr, nullptr))
return {};
Signature s;
int v = 0;
secp256k1_ecdsa_recoverable_signature_serialize_compact(ctx, s.data(), &v, &rawSig);
SignatureStruct& ss = *reinterpret_cast<SignatureStruct*>(&s);
ss.v = static_cast<byte>(v);
if (ss.s > c_secp256k1n / 2)
{
ss.v = static_cast<byte>(ss.v ^ 1);
ss.s = h256(c_secp256k1n - u256(ss.s));
}
assert(ss.s <= c_secp256k1n / 2);
return s;
}