Skip to content

Commit 49572fc

Browse files
author
Antonio Juarez
committed
IWallet implementation improvements
1 parent 50cdbfa commit 49572fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+699
-263
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
/build
33
/tags
44
.idea
5+
.ycm_extra_conf.py
6+
.ycm_extra_conf.pyc
7+
Release
8+
Debug

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ else()
8383
set(RELEASE_FLAGS "-Ofast -DNDEBUG -Wno-unused-variable")
8484
if(NOT APPLE)
8585
# There is a clang bug that does not allow to compile code that uses AES-NI intrinsics if -flto is enabled
86-
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND ${CMAKE_SYSTEM_NAME} STREQUAL "Linux"
87-
AND ${CMAKE_BUILD_TYPE} STREQUAL "Release" AND ((CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.9) OR (CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.9)))
86+
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_SYSTEM_NAME STREQUAL "Linux"
87+
AND CMAKE_BUILD_TYPE STREQUAL "Release" AND ((CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.9) OR (CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.9)))
8888
# On linux, to build in lto mode, check that ld.gold linker is used: 'update-alternatives --install /usr/bin/ld ld /usr/bin/ld.gold HIGHEST_PRIORITY'
8989
set(CMAKE_AR gcc-ar)
9090
set(CMAKE_RANLIB gcc-ranlib)

src/CryptoNoteConfig.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ const CheckpointData CHECKPOINTS[] = {
155155
{780000, "8dd55a9bae429e3685b90317281e633917023d3512eb7f37372209d1a5fc1070"},
156156
{785500, "de1a487d70964d25ed6f7de196866f357a293e867ee81313e7fd0352d0126bdd"},
157157
{789000, "acef490bbccce3b7b7ae8554a414f55413fbf4ca1472c6359b126a4439bd9f01"},
158-
{796000, "04e387a00d35db21d4d93d04040b31f22573972a7e61d72cc07d0ab69bcb9c44"}
158+
{796000, "04e387a00d35db21d4d93d04040b31f22573972a7e61d72cc07d0ab69bcb9c44"},
159+
{800000, "d7fa4eea02e5ce60b949136569c0ea7ac71ea46e0065311054072ac415560b86"}
159160
};
160161
} // CryptoNote
161162

src/CryptoNoteCore/Core.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ bool core::check_tx_semantic(const Transaction& tx, bool keeped_by_block) {
261261
get_inputs_money_amount(tx, amount_in);
262262
uint64_t amount_out = get_outs_money_amount(tx);
263263

264-
if (amount_in <= amount_out) {
264+
if (amount_in < amount_out) {
265265
logger(ERROR) << "tx with wrong amounts: ins " << amount_in << ", outs " << amount_out << ", rejected for tx id= " << getObjectHash(tx);
266266
return false;
267267
}

src/CryptoNoteCore/TransactionPool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ namespace CryptoNote {
126126

127127
uint64_t outputs_amount = get_outs_money_amount(tx);
128128

129-
if (outputs_amount >= inputs_amount) {
129+
if (outputs_amount > inputs_amount) {
130130
logger(INFO) << "transaction use more money then it has: use " << m_currency.formatAmount(outputs_amount) <<
131131
", have " << m_currency.formatAmount(inputs_amount);
132132
tvc.m_verifivation_failed = true;

src/PaymentGate/WalletService.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,7 @@
2323
#include <sstream>
2424
#include <unordered_set>
2525

26-
#ifdef WIN32
27-
#ifndef NOMINMAX
28-
#define NOMINMAX
29-
#endif
30-
#include <windows.h>
31-
#else
32-
#include <unistd.h>
33-
#include <stdio.h>
34-
#endif
26+
#include <boost/filesystem/operations.hpp>
3527

3628
#include <System/Timer.h>
3729
#include <System/InterruptedException.h>
@@ -114,11 +106,8 @@ std::string createTemporaryFile(const std::string& path, std::fstream& tempFile)
114106

115107
//returns true on success
116108
bool deleteFile(const std::string& filename) {
117-
#ifdef WIN32
118-
return DeleteFile(filename.c_str()) != 0;
119-
#else
120-
return unlink(filename.c_str()) == 0;
121-
#endif
109+
boost::system::error_code err;
110+
return boost::filesystem::remove(filename, err) && !err;
122111
}
123112

124113
void replaceWalletFiles(const std::string &path, const std::string &tempFilePath) {

src/Platform/Linux/System/Dispatcher.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <string.h>
2626
#include <ucontext.h>
2727
#include <unistd.h>
28+
#include "ErrorMessage.h"
2829

2930
namespace System {
3031

@@ -40,7 +41,7 @@ class MutextGuard {
4041
MutextGuard(pthread_mutex_t& _mutex) : mutex(_mutex) {
4142
auto ret = pthread_mutex_lock(&mutex);
4243
if (ret != 0) {
43-
throw std::runtime_error("failed to acquire mutex, errno=" + std::to_string(ret) + ": " + strerror(ret));
44+
throw std::runtime_error("pthread_mutex_lock failed, " + errorMessage(ret));
4445
}
4546
}
4647

@@ -62,15 +63,15 @@ Dispatcher::Dispatcher() {
6263
std::string message;
6364
epoll = ::epoll_create1(0);
6465
if (epoll == -1) {
65-
message = "epoll_create1() fail errno=" + std::to_string(errno);
66+
message = "epoll_create1 failed, " + lastErrorMessage();
6667
} else {
6768
mainContext.ucontext = new ucontext_t;
6869
if (getcontext(reinterpret_cast<ucontext_t*>(mainContext.ucontext)) == -1) {
69-
message = "getcontext() fail errno=" + std::to_string(errno);
70+
message = "getcontext failed, " + lastErrorMessage();
7071
} else {
7172
remoteSpawnEvent = eventfd(0, O_NONBLOCK);
7273
if(remoteSpawnEvent == -1) {
73-
message = "eventfd() fail errno=" + std::to_string(errno);
74+
message = "eventfd failed, " + lastErrorMessage();
7475
} else {
7576
remoteSpawnEventContext.writeContext = nullptr;
7677
remoteSpawnEventContext.readContext = nullptr;
@@ -80,7 +81,7 @@ Dispatcher::Dispatcher() {
8081
remoteSpawnEventEpollEvent.data.ptr = &remoteSpawnEventContext;
8182

8283
if (epoll_ctl(epoll, EPOLL_CTL_ADD, remoteSpawnEvent, &remoteSpawnEventEpollEvent) == -1) {
83-
message = "epoll_ctl() failed, errno=" + std::to_string(errno);
84+
message = "epoll_ctl failed, " + lastErrorMessage();
8485
} else {
8586
*reinterpret_cast<pthread_mutex_t*>(this->mutex) = pthread_mutex_t(PTHREAD_MUTEX_INITIALIZER);
8687

@@ -155,7 +156,7 @@ void Dispatcher::clear() {
155156
while (!timers.empty()) {
156157
int result = ::close(timers.top());
157158
if (result == -1) {
158-
throw std::runtime_error("Dispatcher::clear, close failed, errno=" + std::to_string(errno));
159+
throw std::runtime_error("Dispatcher::clear, close failed, " + lastErrorMessage());
159160
}
160161

161162
timers.pop();
@@ -179,7 +180,7 @@ void Dispatcher::dispatch() {
179180
uint64_t buf;
180181
auto transferred = read(remoteSpawnEvent, &buf, sizeof buf);
181182
if(transferred == -1) {
182-
throw std::runtime_error("Dispatcher::dispatch() read(remoteSpawnEvent) fail errno=" + std::to_string(errno));
183+
throw std::runtime_error("Dispatcher::dispatch, read(remoteSpawnEvent) failed, " + lastErrorMessage());
183184
}
184185

185186
MutextGuard guard(*reinterpret_cast<pthread_mutex_t*>(this->mutex));
@@ -206,15 +207,15 @@ void Dispatcher::dispatch() {
206207
}
207208

208209
if (errno != EINTR) {
209-
throw std::runtime_error("Dispatcher::dispatch(), epoll_wait() failed, errno=" + std::to_string(errno));
210+
throw std::runtime_error("Dispatcher::dispatch, epoll_wait failed, " + lastErrorMessage());
210211
}
211212
}
212213

213214
if (context != currentContext) {
214215
ucontext_t* oldContext = static_cast<ucontext_t*>(currentContext->ucontext);
215216
currentContext = context;
216217
if (swapcontext(oldContext, static_cast<ucontext_t *>(context->ucontext)) == -1) {
217-
throw std::runtime_error("Dispatcher::dispatch() swapcontext() failed, errno=" + std::to_string(errno));
218+
throw std::runtime_error("Dispatcher::dispatch, swapcontext failed, " + lastErrorMessage());
218219
}
219220
}
220221
}
@@ -269,7 +270,7 @@ void Dispatcher::remoteSpawn(std::function<void()>&& procedure) {
269270
uint64_t one = 1;
270271
auto transferred = write(remoteSpawnEvent, &one, sizeof one);
271272
if(transferred == - 1) {
272-
throw std::runtime_error("Dispatcher::remoteSpawn, write() failed errno = " + std::to_string(errno));
273+
throw std::runtime_error("Dispatcher::remoteSpawn, write failed, " + lastErrorMessage());
273274
}
274275
}
275276

@@ -308,7 +309,7 @@ void Dispatcher::yield() {
308309
uint64_t buf;
309310
auto transferred = read(remoteSpawnEvent, &buf, sizeof buf);
310311
if(transferred == -1) {
311-
throw std::runtime_error("Dispatcher::dispatch() read(remoteSpawnEvent) fail errno=" + std::to_string(errno));
312+
throw std::runtime_error("Dispatcher::dispatch, read(remoteSpawnEvent) failed, " + lastErrorMessage());
312313
}
313314

314315
MutextGuard guard(*reinterpret_cast<pthread_mutex_t*>(this->mutex));
@@ -334,7 +335,7 @@ void Dispatcher::yield() {
334335
}
335336
} else {
336337
if (errno != EINTR) {
337-
throw std::runtime_error("Dispatcher::dispatch(), epoll_wait() failed, errno=" + std::to_string(errno));
338+
throw std::runtime_error("Dispatcher::dispatch, epoll_wait failed, " + lastErrorMessage());
338339
}
339340
}
340341
}
@@ -353,7 +354,7 @@ NativeContext& Dispatcher::getReusableContext() {
353354
if(firstReusableContext == nullptr) {
354355
ucontext_t* newlyCreatedContext = new ucontext_t;
355356
if (getcontext(newlyCreatedContext) == -1) { //makecontext precondition
356-
throw std::runtime_error("Dispatcher::getReusableContext(), getcontext() fail errno=" + std::to_string(errno));
357+
throw std::runtime_error("Dispatcher::getReusableContext, getcontext failed, " + lastErrorMessage());
357358
}
358359

359360
auto stackPointer = new uint8_t[STACK_SIZE];
@@ -365,7 +366,7 @@ NativeContext& Dispatcher::getReusableContext() {
365366

366367
ucontext_t* oldContext = static_cast<ucontext_t*>(currentContext->ucontext);
367368
if (swapcontext(oldContext, newlyCreatedContext) == -1) {
368-
throw std::runtime_error("Dispatcher::getReusableContext() swapcontext() failed, errno=" + std::to_string(errno));
369+
throw std::runtime_error("Dispatcher::getReusableContext, swapcontext failed, " + lastErrorMessage());
369370
}
370371

371372
assert(firstReusableContext != nullptr);
@@ -393,7 +394,7 @@ int Dispatcher::getTimer() {
393394
timerEvent.data.ptr = nullptr;
394395

395396
if (epoll_ctl(getEpoll(), EPOLL_CTL_ADD, timer, &timerEvent) == -1) {
396-
throw std::runtime_error("Dispatcher::getTimer(), epoll_ctl() failed, errno=" + std::to_string(errno));
397+
throw std::runtime_error("Dispatcher::getTimer, epoll_ctl failed, " + lastErrorMessage());
397398
}
398399
} else {
399400
timer = timers.top();
@@ -416,7 +417,7 @@ void Dispatcher::contextProcedure(void* ucontext) {
416417
firstReusableContext = &context;
417418
ucontext_t* oldContext = static_cast<ucontext_t*>(context.ucontext);
418419
if (swapcontext(oldContext, static_cast<ucontext_t*>(currentContext->ucontext)) == -1) {
419-
throw std::runtime_error("Dispatcher::contextProcedure() swapcontext() failed, errno=" + std::to_string(errno));
420+
throw std::runtime_error("Dispatcher::contextProcedure, swapcontext failed, " + lastErrorMessage());
420421
}
421422

422423
for (;;) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2012-2015, The CryptoNote developers, The Bytecoin developers
2+
//
3+
// This file is part of Bytecoin.
4+
//
5+
// Bytecoin is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Lesser General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Bytecoin is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Lesser General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Lesser General Public License
16+
// along with Bytecoin. If not, see <http://www.gnu.org/licenses/>.
17+
18+
#include "ErrorMessage.h"
19+
#include <cerrno>
20+
#include <cstring>
21+
22+
namespace System {
23+
24+
std::string lastErrorMessage() {
25+
return errorMessage(errno);
26+
}
27+
28+
std::string errorMessage(int err) {
29+
return "result=" + std::to_string(err) + ", " + std::strerror(err);
30+
}
31+
32+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2012-2015, The CryptoNote developers, The Bytecoin developers
2+
//
3+
// This file is part of Bytecoin.
4+
//
5+
// Bytecoin is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Lesser General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Bytecoin is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Lesser General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Lesser General Public License
16+
// along with Bytecoin. If not, see <http://www.gnu.org/licenses/>.
17+
18+
#pragma once
19+
20+
#include <string>
21+
22+
namespace System {
23+
std::string lastErrorMessage();
24+
std::string errorMessage(int);
25+
}

src/Platform/Linux/System/Ipv4Resolver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <netdb.h>
2424

2525
#include <System/Dispatcher.h>
26+
#include <System/ErrorMessage.h>
2627
#include <System/InterruptedException.h>
2728
#include <System/Ipv4Address.h>
2829

@@ -62,7 +63,7 @@ Ipv4Address Ipv4Resolver::resolve(const std::string& host) {
6263
addrinfo* addressInfos;
6364
int result = getaddrinfo(host.c_str(), NULL, &hints, &addressInfos);
6465
if (result != 0) {
65-
throw std::runtime_error("Ipv4Resolver::resolve, getaddrinfo failed, result=" + std::to_string(result));
66+
throw std::runtime_error("Ipv4Resolver::resolve, getaddrinfo failed, " + errorMessage(result));
6667
}
6768

6869
std::size_t count = 0;

0 commit comments

Comments
 (0)