From b8f20436d2072732955ded55494c0d9dfc257b07 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 9 Apr 2014 11:50:43 -0400 Subject: [PATCH] More JS APIs. --- alethzero/MainWin.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h index 8c1eff3b6..b40427b66 100644 --- a/alethzero/MainWin.h +++ b/alethzero/MainWin.h @@ -73,6 +73,9 @@ public: Q_INVOKABLE QByteArray bytesOf(QVariant _t) const { eth::h256 b = in(_t); return QByteArray((char const*)&b, sizeof(eth::h256)); } Q_INVOKABLE QVariant fromAddress(QVariant/*eth::Address*/ _a) const { return out((eth::u160)to(_a)); } + Q_INVOKABLE QVariant toAddress(QVariant/*eth::Address*/ _a) const { return toQJS((eth::u160)in(_a)); } + + Q_INVOKABLE bool isNull(QVariant/*eth::Address*/ _a) const { return !in(_a); } }; class KeyHelper: public QObject @@ -125,6 +128,31 @@ public: _v.append(_w); return _v; } + Q_INVOKABLE QByteArray fromString(QString _s) const + { + return _s.toLatin1(); + } + Q_INVOKABLE QByteArray fromString(QString _s, unsigned _padding) const + { + QByteArray b = _s.toLatin1(); + for (unsigned i = b.size(); i < _padding; ++i) + b.append((char)0); + b.resize(_padding); + return b; + } + Q_INVOKABLE QString toString(QByteArray _b) const + { + while (_b.size() && !_b[_b.size() - 1]) + _b.resize(_b.size() - 1); + return QString::fromLatin1(_b); + } + Q_INVOKABLE QVariant u256of(QByteArray _s) const + { + while (_s.size() < 32) + _s.append((char)0); + eth::h256 ret((uint8_t const*)_s.data(), eth::h256::ConstructFromPointer); + return toQJS(ret); + } }; class QAccount: public QObject