Browse Source

Gaa. Get them out of that namespace!

cl-refactor
Gav Wood 10 years ago
parent
commit
c2392fd81a
  1. 55
      abi/main.cpp
  2. 8
      libethereum/ABI.h

55
abi/main.cpp

@ -162,6 +162,8 @@ struct ABIType
{ {
if (base == Base::Fixed) if (base == Base::Fixed)
size = ssize = 16; size = ssize = 16;
else if (base == Base::Address || base == Base::Bytes)
size = 0;
else else
size = 32; size = 32;
return; return;
@ -188,7 +190,7 @@ struct ABIType
string ret; string ret;
switch (base) switch (base)
{ {
case Base::Bytes: ret = "bytes" + toString(size); break; case Base::Bytes: ret = "bytes" + (size > 0 ? toString(size) : ""); break;
case Base::Address: ret = "address"; break; case Base::Address: ret = "address"; break;
case Base::Int: ret = "int" + toString(size); break; case Base::Int: ret = "int" + toString(size); break;
case Base::Uint: ret = "uint" + toString(size); break; case Base::Uint: ret = "uint" + toString(size); break;
@ -361,15 +363,30 @@ struct ABIMethod
{ {
for (unsigned j = 0; j < inArity[ii]; ++j) for (unsigned j = 0; j < inArity[ii]; ++j)
{ {
ret += aligned(_params[pi].first, i, _params[pi].second, (i.base == Base::Bytes && i.size == 1) ? 1 : 32); if (i.base == Base::Bytes && !i.size)
{
ret += _params[pi].first;
while (ret.size() % 32 != 0)
ret.push_back(0);
}
else
ret += aligned(_params[pi].first, i, _params[pi].second, 32);
++pi; ++pi;
} }
++ii; ++ii;
while (ret.size() % 32 != 0)
ret.push_back(0);
} }
return ret; return ret;
} }
string decode(bytes const& _data, int _index = -1)
{
stringstream out;
if (_index == -1)
out << "[";
(void)_data;
if (_index == -1)
out << "]";
return out.str();
}
}; };
string canonSig(string const& _name, vector<ABIType> const& _args) string canonSig(string const& _name, vector<ABIType> const& _args)
@ -517,10 +534,7 @@ int main(int argc, char** argv)
} }
string abiData; string abiData;
if (abiFile == "--") if (abiFile.empty())
for (int i = cin.get(); i != -1; i = cin.get())
abiData.push_back((char)i);
else if (!abiFile.empty())
abiData = contentsString(abiFile); abiData = contentsString(abiFile);
if (mode == Mode::Encode) if (mode == Mode::Encode)
@ -546,6 +560,31 @@ int main(int argc, char** argv)
} }
else if (mode == Mode::Decode) else if (mode == Mode::Decode)
{ {
if (abiData.empty())
{
cerr << "Please specify an ABI file." << endl;
exit(-1);
}
else
{
ABI abi(abiData);
ABIMethod m;
if (verbose)
cerr << "ABI:" << endl << abi;
try {
m = abi.method(method, args);
}
catch(...)
{
cerr << "Unknown method in ABI." << endl;
exit(-1);
}
string encoded;
for (int i = cin.get(); i != -1; i = cin.get())
encoded.push_back((char)i);
cout << m.decode(fromHex(encoded));
}
// TODO: read abi to determine output format. // TODO: read abi to determine output format.
(void)encoding; (void)encoding;
(void)clearZeroes; (void)clearZeroes;

8
libethereum/ABI.h

@ -21,15 +21,15 @@
#pragma once #pragma once
#include <libdevcore/Common.h>
#include <libdevcore/FixedHash.h>
#include <libdevcore/CommonData.h>
namespace dev namespace dev
{ {
namespace eth namespace eth
{ {
#include <libdevcore/Common.h>
#include <libdevcore/FixedHash.h>
#include <libdevcore/CommonData.h>
template <class T> struct ABISerialiser {}; template <class T> struct ABISerialiser {};
template <unsigned N> struct ABISerialiser<FixedHash<N>> { static bytes serialise(FixedHash<N> const& _t) { static_assert(N <= 32, "Cannot serialise hash > 32 bytes."); static_assert(N > 0, "Cannot serialise zero-length hash."); return bytes(32 - N, 0) + _t.asBytes(); } }; template <unsigned N> struct ABISerialiser<FixedHash<N>> { static bytes serialise(FixedHash<N> const& _t) { static_assert(N <= 32, "Cannot serialise hash > 32 bytes."); static_assert(N > 0, "Cannot serialise zero-length hash."); return bytes(32 - N, 0) + _t.asBytes(); } };
template <> struct ABISerialiser<u256> { static bytes serialise(u256 const& _t) { return h256(_t).asBytes(); } }; template <> struct ABISerialiser<u256> { static bytes serialise(u256 const& _t) { return h256(_t).asBytes(); } };

Loading…
Cancel
Save