From f8edff3f54a888ed9afae6f3fc2075820058cc7e Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 27 Jul 2014 11:20:43 +0200 Subject: [PATCH] Fixes and whatnot. --- alethzero/MainWin.cpp | 26 ++++++++++++++++++++++---- libethereum/Client.cpp | 2 ++ liblll/CompilerState.cpp | 2 ++ libpyserpent/pyserpent.cpp | 6 +++--- libserpent/rewriter.cpp | 2 +- stdserv.js | 12 ++++++------ 6 files changed, 36 insertions(+), 14 deletions(-) diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 471d37411..a929ff6d3 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -1299,8 +1299,9 @@ void Main::on_data_textChanged() QString s = ui->data->toPlainText(); while (s.size()) { - QRegExp r("(@|\\$)?\"([^\"]*)\"(.*)"); - QRegExp h("(@|\\$)?(0x)?(([a-fA-F0-9])+)(.*)"); + QRegExp r("(@|\\$)?\"([^\"]*)\"(\\s.*)?"); + QRegExp d("(@|\\$)?([0-9]+)(\\s*(ether)|(finney)|(szabo))?(\\s.*)?"); + QRegExp h("(@|\\$)?(0x)?(([a-fA-F0-9])+)(\\s.*)?"); if (r.exactMatch(s)) { for (auto i: r.cap(2)) @@ -1312,6 +1313,23 @@ void Main::on_data_textChanged() m_data.push_back(0); s = r.cap(3); } + else if (d.exactMatch(s)) + { + u256 v(d.cap(2).toStdString()); + if (d.cap(6) == "szabo") + v *= eth::szabo; + else if (d.cap(5) == "finney") + v *= eth::finney; + else if (d.cap(4) == "ether") + v *= eth::ether; + bytes bs = eth::toCompactBigEndian(v); + if (d.cap(1) != "$") + for (auto i = bs.size(); i < 32; ++i) + m_data.push_back(0); + for (auto b: bs) + m_data.push_back(b); + s = d.cap(7); + } else if (h.exactMatch(s)) { bytes bs = fromHex((((h.cap(3).size() & 1) ? "0" : "") + h.cap(3)).toStdString()); @@ -1679,9 +1697,9 @@ QString Main::prettyU256(eth::u256 _n) const QString raw; ostringstream s; if (!(_n >> 64)) - s << "0x" << (uint64_t)_n << ""; + s << "" << (uint64_t)_n << " (0x" << hex << (uint64_t)_n << ")"; else if (!~(_n >> 64)) - s << "0x" << (int64_t)_n << ""; + s << "" << (int64_t)_n << " (0x" << hex << (int64_t)_n << ")"; else if (_n >> 200 == 0) { Address a = right160(_n); diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 2b2d1211e..37512d429 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include "Defaults.h" #include "PeerServer.h" using namespace std; diff --git a/liblll/CompilerState.cpp b/liblll/CompilerState.cpp index 380d5a66f..01995674f 100644 --- a/liblll/CompilerState.cpp +++ b/liblll/CompilerState.cpp @@ -62,6 +62,8 @@ void CompilerState::populateStandard() "(def 'create (value code) { [0]:(msize) (create value @0 (lll code @0)) })" "(def 'create (code) { [0]:(msize) (create 0 @0 (lll code @0)) })" "(def 'sha3 (val) { [0]:val (sha3 0 32) })" + "(def 'sha3pair (a b) { [0]:a [32]:b (sha3 0 64) })" + "(def 'sha3trip (a b c) { [0]:a [32]:b [64]:c (sha3 0 96) })" "(def 'return (val) { [0]:val (return 0 32) })" "(def 'returnlll (code) (return 0 (lll code 0)) )" "(def 'makeperm (name pos) { (def name (sload pos)) (def name (v) (sstore pos v)) } )" diff --git a/libpyserpent/pyserpent.cpp b/libpyserpent/pyserpent.cpp index 64fa82ded..ba3750b51 100644 --- a/libpyserpent/pyserpent.cpp +++ b/libpyserpent/pyserpent.cpp @@ -7,7 +7,7 @@ #include #define PYMETHOD(name, FROM, method, TO) \ - static PyObject * name(PyObject *self, PyObject *args) { \ + static PyObject * name(PyObject *, PyObject *args) { \ FROM(med) \ return TO(method(med)); \ } @@ -128,7 +128,7 @@ PYMETHOD(ps_parse_lll, FROMSTR, parseLLL, pyifyNode) static PyMethodDef PyextMethods[] = { {"compile", ps_compile, METH_VARARGS, "Compile code."}, - {"compile_to_lll", ps_parse, METH_VARARGS, + {"compile_to_lll", ps_compile_to_lll, METH_VARARGS, "Compile code to LLL."}, {"compile_lll", ps_compile_lll, METH_VARARGS, "Compile LLL to EVM."}, @@ -151,5 +151,5 @@ static PyMethodDef PyextMethods[] = { PyMODINIT_FUNC initpyext(void) { - PyObject *m = Py_InitModule( "pyext", PyextMethods ); + Py_InitModule( "pyext", PyextMethods ); } diff --git a/libserpent/rewriter.cpp b/libserpent/rewriter.cpp index 00712b871..8b50c9a28 100644 --- a/libserpent/rewriter.cpp +++ b/libserpent/rewriter.cpp @@ -411,7 +411,7 @@ Node apply_rules(Node node) { node.args[0].val = "'" + node.args[0].val; i = 1; } - for (i = i; i < node.args.size(); i++) { + for (; i < node.args.size(); i++) { node.args[i] = apply_rules(node.args[i]); } } diff --git a/stdserv.js b/stdserv.js index 92f075a1b..907455eb4 100644 --- a/stdserv.js +++ b/stdserv.js @@ -92,10 +92,10 @@ var gavCoinCode = eth.lll(" (returnlll { (when (&& (= $0 'kill) (= (caller) @@0x69)) (suicide (caller))) (when (= $0 'balance) (return @@$32)) - (when (= $0 'approved) (return @@ @(sha3 (^ (if (= (calldatasize) 64) (caller) $64) $32))) ) + (when (= $0 'approved) (return @@ (sha3pair (if (= (calldatasize) 64) (caller) $64) $32)) ) (when (= $0 'approve) { - [[@(sha3 (^ (caller) $32))]] $32 + [[(sha3pair (caller) $32)]] $32 (stop) }) @@ -103,18 +103,18 @@ var gavCoinCode = eth.lll(" (set 'fromVar (if (= (calldatasize) 96) (caller) { - (when (! @@ @(sha3 (^ $96 $32)) ) (stop)) - $96 + (when (! @@ (sha3pair (origin) (caller))) (return 0)) + (origin) } )) (def 'to $32) (def 'value $64) (def 'from (get 'fromVar)) (set 'fromBal @@from) - (when (< @fromBal value) (stop)) + (when (< @fromBal value) (return 0)) [[ from ]]: (- @fromBal value) [[ to ]]: (+ @@to value) - (stop) + (return 1) }) (set 'n @@0x42)