Browse Source

- Rollback previous change on toCompactBigEndian, unpadded(bytes _b).

- Change content of padded(bytes _b, unsigned _l).
 - Add function unpadLeft.
cl-refactor
yann300 10 years ago
committed by yann300
parent
commit
ce14b0c150
  1. 2
      libdevcore/CommonData.h
  2. 9
      libdevcore/CommonJS.cpp
  3. 9
      libdevcore/CommonJS.h
  4. 2
      mix/ContractCallDataEncoder.cpp

2
libdevcore/CommonData.h

@ -113,7 +113,7 @@ inline bytes toBigEndian(u160 _val) { bytes ret(20); toBigEndian(_val, ret); ret
/// Convenience function for toBigEndian.
/// @returns a byte array just big enough to represent @a _val.
template <class _T>
inline bytes toCompactBigEndian(_T _val, unsigned _min = 1)
inline bytes toCompactBigEndian(_T _val, unsigned _min = 0)
{
int i = 0;
for (_T v = _val; v; ++i, v >>= 8) {}

9
libdevcore/CommonJS.cpp

@ -42,25 +42,22 @@ bytes padded(bytes _b, unsigned _l)
{
while (_b.size() < _l)
_b.insert(_b.begin(), 0);
while (_b.size() < _l)
_b.push_back(0);
return asBytes(asString(_b).substr(_b.size() - std::max(_l, _l)));
}
bytes unpadded(bytes _b)
{
auto p = asString(_b).find_first_not_of("0");
auto p = asString(_b).find_last_not_of((char)0);
_b.resize(p == std::string::npos ? 0 : (p + 1));
return _b;
}
std::string unpadded(std::string _b)
std::string unpadLeft(std::string _b)
{
auto p = _b.find_first_not_of('0');
if (p == std::string::npos)
return "0";
_b = _b.substr(p, _b.length() - 1);
return _b;
return _b.substr(p, _b.length() - 1);
}
std::string prettyU256(u256 _n)

9
libdevcore/CommonJS.h

@ -46,12 +46,19 @@ inline std::string toJS(dev::bytes const& _n)
return "0x" + dev::toHex(_n);
}
/// Convert string to byte array.
bytes jsToBytes(std::string const& _s);
/// Add '0' on the head of _b until _l.
bytes padded(bytes _b, unsigned _l);
/// Removing all trailing '0'.
bytes unpadded(bytes _s);
std::string unpadded(std::string _s);
/// Remove all '0' on the head of _s.
std::string unpadLeft(std::string _s);
/// Convert u256 to readable string.
std::string prettyU256(u256 _n);
/// Convert h256 to readable string.
std::string fromRaw(h256 _n, unsigned* _inc = nullptr);
/// Convert string to Address (h160).
Address fromString(std::string const& _a);
template <unsigned N> FixedHash<N> jsToFixed(std::string const& _s)

2
mix/ContractCallDataEncoder.cpp

@ -75,7 +75,7 @@ QList<QVariableDefinition*> ContractCallDataEncoder::decode(QList<QVariableDecla
QVariableDeclaration* dec = (QVariableDeclaration*)_returnParameters.at(k);
int padding = this->padding(dec->type());
std::string rawParam = returnValue.substr(0, padding * 2);
r.append(new QVariableDefinition(dec, convertToReadable(unpadded(rawParam), dec)));
r.append(new QVariableDefinition(dec, convertToReadable(unpadLeft(rawParam), dec)));
returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1);
}
return r;

Loading…
Cancel
Save