Skip to content

Commit 01adc3c

Browse files
committed
Simplewallet console message sending
1 parent bdea9dd commit 01adc3c

File tree

4 files changed

+97
-20
lines changed

4 files changed

+97
-20
lines changed

src/Common/ConsoleHandler.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,40 @@ bool ConsoleHandler::runCommand(const std::vector<std::string>& cmdAndArgs) {
192192
}
193193

194194
void ConsoleHandler::handleCommand(const std::string& cmd) {
195-
std::vector<std::string> args;
196-
boost::split(args, cmd, boost::is_any_of(" "), boost::token_compress_on);
197-
runCommand(args);
195+
bool parseString = false;
196+
std::string arg;
197+
std::vector<std::string> argList;
198+
199+
for (auto ch : cmd) {
200+
switch (ch) {
201+
case ' ':
202+
if (parseString) {
203+
arg += ch;
204+
} else if (!arg.empty()) {
205+
argList.emplace_back(std::move(arg));
206+
arg.clear();
207+
}
208+
break;
209+
210+
case '"':
211+
if (!arg.empty()) {
212+
argList.emplace_back(std::move(arg));
213+
arg.clear();
214+
}
215+
216+
parseString = !parseString;
217+
break;
218+
219+
default:
220+
arg += ch;
221+
}
222+
}
223+
224+
if (!arg.empty()) {
225+
argList.emplace_back(std::move(arg));
226+
}
227+
228+
runCommand(argList);
198229
}
199230

200231
void ConsoleHandler::handlerThread() {

src/CryptoNoteCore/TransactionPool.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,6 @@ namespace CryptoNote {
123123
ttl.ttl = 0;
124124
}
125125

126-
uint64_t now = static_cast<uint64_t>(time(nullptr));
127-
if (ttl.ttl != 0) {
128-
if (ttl.ttl <= now) {
129-
logger(INFO, BRIGHT_WHITE) << "Transaction TTL has already expired: tx = " << id << ", ttl = " << ttl.ttl;
130-
tvc.m_verifivation_failed = true;
131-
return false;
132-
} else if (ttl.ttl - now > m_currency.mempoolTxLiveTime() + m_currency.blockFutureTimeLimit()) {
133-
logger(INFO, BRIGHT_WHITE) << "Transaction TTL is out of range: tx = " << id << ", ttl = " << ttl.ttl;
134-
tvc.m_verifivation_failed = true;
135-
return false;
136-
}
137-
}
138-
139126
const uint64_t fee = inputs_amount - outputs_amount;
140127
bool isFusionTransaction = fee == 0 && m_currency.isFusionTransaction(tx, blobSize);
141128
if (!keptByBlock && !isFusionTransaction && ttl.ttl == 0 && fee < m_currency.minimumFee()) {
@@ -146,6 +133,25 @@ namespace CryptoNote {
146133
return false;
147134
}
148135

136+
if (ttl.ttl != 0 && !keptByBlock) {
137+
uint64_t now = static_cast<uint64_t>(time(nullptr));
138+
if (ttl.ttl <= now) {
139+
logger(WARNING, BRIGHT_YELLOW) << "Transaction TTL has already expired: tx = " << id << ", ttl = " << ttl.ttl;
140+
tvc.m_verifivation_failed = true;
141+
return false;
142+
} else if (ttl.ttl - now > m_currency.mempoolTxLiveTime() + m_currency.blockFutureTimeLimit()) {
143+
logger(WARNING, BRIGHT_YELLOW) << "Transaction TTL is out of range: tx = " << id << ", ttl = " << ttl.ttl;
144+
tvc.m_verifivation_failed = true;
145+
return false;
146+
}
147+
148+
if (fee != 0) {
149+
logger(WARNING, BRIGHT_YELLOW) << "Transaction with TTL has non-zero fee: tx = " << id << ", fee = " << m_currency.formatAmount(fee);
150+
tvc.m_verifivation_failed = true;
151+
return false;
152+
}
153+
}
154+
149155
//check key images for transaction if it is not kept by block
150156
if (!keptByBlock) {
151157
std::lock_guard<std::recursive_mutex> lock(m_transactions_lock);

src/SimpleWallet/SimpleWallet.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@ struct TransferCommand {
137137
std::vector<uint8_t> extra;
138138
uint64_t fee;
139139
std::map<std::string, std::vector<WalletLegacyTransfer>> aliases;
140+
std::vector<std::string> messages;
141+
uint64_t ttl;
140142

141143
TransferCommand(const CryptoNote::Currency& currency) :
142-
m_currency(currency), fake_outs_count(0), fee(currency.minimumFee()) {
144+
m_currency(currency), fake_outs_count(0), fee(currency.minimumFee()), ttl(0) {
143145
}
144146

145147
bool parseArguments(LoggerRef& logger, const std::vector<std::string> &args) {
@@ -155,6 +157,8 @@ struct TransferCommand {
155157
return false;
156158
}
157159

160+
bool feeFound = false;
161+
bool ttlFound = false;
158162
while (!ar.eof()) {
159163

160164
auto arg = ar.next();
@@ -169,6 +173,13 @@ struct TransferCommand {
169173
return false;
170174
}
171175
} else if (arg == "-f") {
176+
feeFound = true;
177+
178+
if (ttlFound) {
179+
logger(ERROR, BRIGHT_RED) << "Transaction with TTL can not have fee";
180+
return false;
181+
}
182+
172183
bool ok = m_currency.parseAmount(value, fee);
173184
if (!ok) {
174185
logger(ERROR, BRIGHT_RED) << "Fee value is invalid: " << value;
@@ -179,6 +190,23 @@ struct TransferCommand {
179190
logger(ERROR, BRIGHT_RED) << "Fee value is less than minimum: " << m_currency.minimumFee();
180191
return false;
181192
}
193+
} else if (arg == "-m") {
194+
messages.emplace_back(value);
195+
} else if (arg == "-ttl") {
196+
ttlFound = true;
197+
198+
if (feeFound) {
199+
logger(ERROR, BRIGHT_RED) << "Transaction with fee can not have TTL";
200+
return false;
201+
} else {
202+
fee = 0;
203+
}
204+
205+
if (!Common::fromString(value, ttl) || ttl < 1 || ttl * 60 > m_currency.mempoolTxLiveTime()) {
206+
logger(ERROR, BRIGHT_RED) << "TTL has invalid format: \"" << value << "\", " <<
207+
"enter time from 1 to " << (m_currency.mempoolTxLiveTime() / 60) << " minutes";
208+
return false;
209+
}
182210
}
183211
} else {
184212
WalletLegacyTransfer destination;
@@ -1113,14 +1141,26 @@ bool simple_wallet::transfer(const std::vector<std::string> &args) {
11131141
}
11141142
}
11151143

1144+
std::vector<TransactionMessage> messages;
1145+
for (auto dst : cmd.dsts) {
1146+
for (auto msg : cmd.messages) {
1147+
messages.emplace_back(TransactionMessage{ msg, dst.address });
1148+
}
1149+
}
1150+
1151+
uint64_t ttl = 0;
1152+
if (cmd.ttl != 0) {
1153+
ttl = static_cast<uint64_t>(time(nullptr)) + cmd.ttl;
1154+
}
1155+
11161156
CryptoNote::WalletHelper::SendCompleteResultObserver sent;
11171157

11181158
std::string extraString;
11191159
std::copy(cmd.extra.begin(), cmd.extra.end(), std::back_inserter(extraString));
11201160

11211161
WalletHelper::IWalletRemoveObserverGuard removeGuard(*m_wallet, sent);
11221162

1123-
CryptoNote::TransactionId tx = m_wallet->sendTransaction(cmd.dsts, cmd.fee, extraString, cmd.fake_outs_count, 0);
1163+
CryptoNote::TransactionId tx = m_wallet->sendTransaction(cmd.dsts, cmd.fee, extraString, cmd.fake_outs_count, 0, messages, ttl);
11241164
if (tx == WALLET_LEGACY_INVALID_TRANSACTION_ID) {
11251165
fail_msg_writer() << "Can't send money";
11261166
return true;

src/version.h.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#define BUILD_COMMIT_ID "@VERSION@"
2-
#define PROJECT_VERSION "3.1.0-beta"
3-
#define PROJECT_VERSION_BUILD_NO "1757"
2+
#define PROJECT_VERSION "3.1.1-beta"
3+
#define PROJECT_VERSION_BUILD_NO "1761"
44
#define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO "(" BUILD_COMMIT_ID ")"

0 commit comments

Comments
 (0)