mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Metadata stamp.
This commit is contained in:
@@ -38,13 +38,14 @@ h256 swarmHashSimple(bytesConstRef _data, size_t _size)
|
||||
return keccak256(toLittleEndian(_size) + _data.toBytes());
|
||||
}
|
||||
|
||||
h256 swarmHashIntermediate(bytes const& _input, size_t _offset, size_t _length)
|
||||
h256 swarmHashIntermediate(string const& _input, size_t _offset, size_t _length)
|
||||
{
|
||||
bytesConstRef ref;
|
||||
bytes innerNodes;
|
||||
if (_length <= 0x1000)
|
||||
return swarmHashSimple(bytesConstRef(_input.data() + _offset, _length), _length);
|
||||
ref = bytesConstRef(_input).cropped(_offset, _length);
|
||||
else
|
||||
{
|
||||
bytes innerNodes;
|
||||
size_t maxRepresentedSize = 0x1000;
|
||||
while (maxRepresentedSize * (0x1000 / 32) < _length)
|
||||
maxRepresentedSize *= (0x1000 / 32);
|
||||
@@ -53,11 +54,12 @@ h256 swarmHashIntermediate(bytes const& _input, size_t _offset, size_t _length)
|
||||
size_t size = std::min(maxRepresentedSize, _length - i);
|
||||
innerNodes += swarmHashIntermediate(_input, _offset + i, size).asBytes();
|
||||
}
|
||||
return swarmHashSimple(bytesConstRef(&innerNodes), _length);
|
||||
ref = bytesConstRef(&innerNodes);
|
||||
}
|
||||
return swarmHashSimple(ref, _length);
|
||||
}
|
||||
|
||||
h256 dev::swarmHash(bytes const& _input)
|
||||
h256 dev::swarmHash(string const& _input)
|
||||
{
|
||||
return swarmHashIntermediate(_input, 0, _input.size());
|
||||
}
|
||||
|
||||
@@ -20,12 +20,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <libdevcore/FixedHash.h>
|
||||
#include <libdevcore/Common.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace dev
|
||||
{
|
||||
|
||||
/// Compute the "swarm hash" of @a _data
|
||||
h256 swarmHash(bytes const& _data);
|
||||
h256 swarmHash(std::string const& _data);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user