From e26de2489e1751405372c18360c52b138fa9de75 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 25 Mar 2015 13:10:30 +0100 Subject: [PATCH] Fix AZ accounts/contracts panes. Added initial ABI tool. --- CMakeLists.txt | 3 +- abi/CMakeLists.txt | 16 +++++ abi/main.cpp | 137 ++++++++++++++++++++++++++++++++++++++++++ alethzero/MainWin.cpp | 8 +-- 4 files changed, 159 insertions(+), 5 deletions(-) create mode 100644 abi/CMakeLists.txt create mode 100644 abi/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e7e89a5a7..40a3e8e63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,7 +160,6 @@ if (EVMJIT) endif() add_subdirectory(libdevcore) -add_subdirectory(rlp) add_subdirectory(libevmcore) add_subdirectory(liblll) @@ -199,6 +198,8 @@ add_subdirectory(test) if (NOT JUSTTESTS) + add_subdirectory(rlp) + add_subdirectory(abi) add_subdirectory(eth) if("x${CMAKE_BUILD_TYPE}" STREQUAL "xDebug") diff --git a/abi/CMakeLists.txt b/abi/CMakeLists.txt new file mode 100644 index 000000000..82c7c4240 --- /dev/null +++ b/abi/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_policy(SET CMP0015 NEW) +set(CMAKE_AUTOMOC OFF) + +aux_source_directory(. SRC_LIST) + +include_directories(BEFORE ..) +include_directories(${LEVELDB_INCLUDE_DIRS}) + +set(EXECUTABLE abi) + +add_executable(${EXECUTABLE} ${SRC_LIST}) + +target_link_libraries(${EXECUTABLE} ethereum) + +install( TARGETS ${EXECUTABLE} DESTINATION bin) + diff --git a/abi/main.cpp b/abi/main.cpp new file mode 100644 index 000000000..7bb00e390 --- /dev/null +++ b/abi/main.cpp @@ -0,0 +1,137 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file main.cpp + * @author Gav Wood + * @date 2014 + * RLP tool. + */ +#include +#include +#include +#include "../test/JsonSpiritHeaders.h" +#include +#include +#include +#include +using namespace std; +using namespace dev; +namespace js = json_spirit; + +void help() +{ + cout + << "Usage abi enc (, (, ... ))" << endl + << " abi enc -a (, (, ... ))" << endl + << " abi dec -a [ | ]" << endl + << "Options:" << endl + << " -a,--abi-file Specify the JSON ABI file." << endl + << "Output options (dec mode):" << endl + << " -i,--index When decoding, output only the nth (counting from 0) return value." << endl + << " -d,--decimal All data should be displayed as decimal." << endl + << " -x,--hex Display all data as hex." << endl + << " -b,--binary Display all data as binary." << endl + << " -p,--prefix Prefix by a base identifier." << endl + << " -z,--no-zeroes Remove any leading zeroes from the data." << endl + << " -n,--no-nulls Remove any trailing nulls from the data." << endl + << "General options:" << endl + << " -h,--help Print this help message and exit." << endl + << " -V,--version Show the version and exit." << endl + ; + exit(0); +} + +void version() +{ + cout << "abi version " << dev::Version << endl; + exit(0); +} + +enum class Mode { + Encode, + Decode +}; + +enum class Encoding { + Auto, + Decimal, + Hex, + Binary, +}; + +int main(int argc, char** argv) +{ + Encoding encoding = Encoding::Auto; + Mode mode = Mode::Encode; + string abiFile; + string methodName; + bool outputPrefix = false; + bool clearZeroes = false; + bool clearNulls = false; + int outputIndex = -1; + + for (int i = 1; i < argc; ++i) + { + string arg = argv[i]; + if (arg == "-h" || arg == "--help") + help(); + else if (arg == "enc" && i == 1) + mode = Mode::Encode; + else if (arg == "dec" && i == 1) + mode = Mode::Decode; + else if ((arg == "-a" || arg == "--abi") && argc > i) + abiFile = argv[++i]; + else if ((arg == "-i" || arg == "--index") && argc > i) + outputIndex = atoi(argv[++i]); + else if (arg == "-p" || arg == "--prefix") + outputPrefix = true; + else if (arg == "-z" || arg == "--no-zeroes") + clearZeroes = true; + else if (arg == "-n" || arg == "--no-nulls") + clearNulls = true; + else if (arg == "-x" || arg == "--hex") + encoding = Encoding::Hex; + else if (arg == "-d" || arg == "--decimal" || arg == "--dec") + encoding = Encoding::Decimal; + else if (arg == "-b" || arg == "--binary" || arg == "--bin") + encoding = Encoding::Binary; + else if (arg == "-V" || arg == "--version") + version(); + else + methodName = arg; + } + + string abi; + if (abiFile == "--") + for (int i = cin.get(); i != -1; i = cin.get()) + abi.push_back((char)i); + else if (!abiFile.empty()) + abi = contentsString(abiFile); + + if (mode == Mode::Encode) + { + (void)encoding; + (void)outputPrefix; + (void)clearZeroes; + (void)clearNulls; + (void)outputIndex; + } + else if (mode == Mode::Decode) + { + } + + return 0; +} diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index f63cd74f0..4b9af1666 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -136,8 +136,8 @@ Main::Main(QWidget *parent) : }; #if !ETH_FATDB - ui->dockWidgetAccounts->hide(); - ui->dockWidgetContracts->hide(); + delete ui->dockWidget_accounts; + delete ui->dockWidget_contracts; #endif #if ETH_DEBUG @@ -1633,7 +1633,7 @@ void Main::on_ourAccounts_doubleClicked() void Main::on_accounts_doubleClicked() { - if (!ui->accounts->isEmpty()) + if (ui->accounts->count()) { auto hba = ui->accounts->currentItem()->data(Qt::UserRole).toByteArray(); auto h = Address((byte const*)hba.data(), Address::ConstructFromPointer); @@ -1643,7 +1643,7 @@ void Main::on_accounts_doubleClicked() void Main::on_contracts_doubleClicked() { - if (!ui->contracts->isEmpty()) + if (ui->contracts->count()) { auto hba = ui->contracts->currentItem()->data(Qt::UserRole).toByteArray(); auto h = Address((byte const*)hba.data(), Address::ConstructFromPointer);