Browse Source

Fix AZ accounts/contracts panes.

Added initial ABI tool.
cl-refactor
Gav Wood 10 years ago
parent
commit
e26de2489e
  1. 3
      CMakeLists.txt
  2. 16
      abi/CMakeLists.txt
  3. 137
      abi/main.cpp
  4. 8
      alethzero/MainWin.cpp

3
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")

16
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)

137
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 <http://www.gnu.org/licenses/>.
*/
/** @file main.cpp
* @author Gav Wood <i@gavwood.com>
* @date 2014
* RLP tool.
*/
#include <fstream>
#include <iostream>
#include <boost/algorithm/string.hpp>
#include "../test/JsonSpiritHeaders.h"
#include <libdevcore/CommonIO.h>
#include <libdevcore/RLP.h>
#include <libdevcrypto/SHA3.h>
#include <libethereum/Client.h>
using namespace std;
using namespace dev;
namespace js = json_spirit;
void help()
{
cout
<< "Usage abi enc <signature> (<arg1>, (<arg2>, ... ))" << endl
<< " abi enc -a <abi.json> <unique_method_name> (<arg1>, (<arg2>, ... ))" << endl
<< " abi dec -a <abi.json> [ <signature> | <unique_method_name> ]" << endl
<< "Options:" << endl
<< " -a,--abi-file <filename> Specify the JSON ABI file." << endl
<< "Output options (dec mode):" << endl
<< " -i,--index <n> 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;
}

8
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);

Loading…
Cancel
Save