From 366aad13e733c6cc8eb417f26cf3d0081fee691a Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 9 Oct 2012 12:06:13 -0700 Subject: [PATCH 1/4] Remove Ledger::bumpSeq --- src/Ledger.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Ledger.h b/src/Ledger.h index 3a96bcf6f..41e30d2db 100644 --- a/src/Ledger.h +++ b/src/Ledger.h @@ -116,10 +116,6 @@ public: void armDirty() { mTransactionMap->armDirty(); mAccountStateMap->armDirty(); } void disarmDirty() { mTransactionMap->disarmDirty(); mAccountStateMap->disarmDirty(); } - // This ledger has closed, will never be accepted, and is accepting - // new transactions to be re-reprocessed when do accept a new last-closed ledger - void bumpSeq() { mClosed = true; mLedgerSeq++; } - // ledger signature operations void addRaw(Serializer &s) const; void setRaw(const Serializer& s); From 4c61648a7b32ba15933a70452695297edb5fbfef Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Tue, 9 Oct 2012 12:25:51 -0700 Subject: [PATCH 2/4] WS: Add ledger_accept commnd. --- src/WSDoor.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/WSDoor.cpp b/src/WSDoor.cpp index 25eabb907..f40d0d453 100644 --- a/src/WSDoor.cpp +++ b/src/WSDoor.cpp @@ -79,6 +79,7 @@ public: boost::unordered_set parseAccountIds(const Json::Value& jvArray); // Request-Response Commands + void doLedgerAccept(Json::Value& jvResult, const Json::Value& jvRequest); void doLedgerClosed(Json::Value& jvResult, const Json::Value& jvRequest); void doLedgerCurrent(Json::Value& jvResult, const Json::Value& jvRequest); void doLedgerEntry(Json::Value& jvResult, const Json::Value& jvRequest); @@ -303,6 +304,7 @@ Json::Value WSConnection::invokeCommand(const Json::Value& jvRequest) doFuncPtr dfpFunc; } commandsA[] = { // Request-Response Commands: + { "ledger_accept", &WSConnection::doLedgerAccept }, { "ledger_closed", &WSConnection::doLedgerClosed }, { "ledger_current", &WSConnection::doLedgerCurrent }, { "ledger_entry", &WSConnection::doLedgerEntry }, @@ -541,6 +543,18 @@ void WSConnection::doLedgerAccountsUnsubscribe(Json::Value& jvResult, const Json } } +void WSConnection::doLedgerAccept(Json::Value& jvResult, const Json::Value& jvRequest) +{ + if (!theConfig.RUN_STANDALONE) + { + jvResult["error"] = "notStandAlone"; + } + else + { + jvResult["ledger_current_index"] = mNetwork.getCurrentLedgerID(); + } +} + void WSConnection::doLedgerClosed(Json::Value& jvResult, const Json::Value& jvRequest) { uint256 uLedger = mNetwork.getClosedLedger(); From 8714e40bcfd0d94695e95e832484bb7bd3946f74 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Tue, 9 Oct 2012 16:04:46 -0700 Subject: [PATCH 3/4] Improve amount parsing (accept e notation). --- src/Amount.cpp | 91 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 67 insertions(+), 24 deletions(-) diff --git a/src/Amount.cpp b/src/Amount.cpp index 9012cf69f..78cde08d5 100644 --- a/src/Amount.cpp +++ b/src/Amount.cpp @@ -194,24 +194,30 @@ std::string STAmount::createHumanCurrency(const uint160& uCurrency) return sCurrency; } +// Assumes trusted input. bool STAmount::setValue(const std::string& sAmount) { // Note: mIsNative must be set already! uint64 uValue; int iOffset; size_t uDecimal = sAmount.find_first_of(mIsNative ? "^" : "."); - bool bInteger = uDecimal == std::string::npos; + size_t uExp = uDecimal == std::string::npos ? sAmount.find_first_of("e") : std::string::npos; + bool bInteger = uDecimal == std::string::npos && uExp == std::string::npos; mIsNegative = false; if (bInteger) { + // Integer input: does not necessarily mean native. + try { int64 a = sAmount.empty() ? 0 : lexical_cast_st(sAmount); if (a >= 0) - uValue = static_cast(a); + { + uValue = static_cast(a); + } else { - uValue = static_cast(-a); + uValue = static_cast(-a); mIsNegative = true; } @@ -224,36 +230,73 @@ bool STAmount::setValue(const std::string& sAmount) } iOffset = 0; } + else if (uExp != std::string::npos) + { + // e input + + try + { + int64 iInteger = uExp ? lexical_cast_st(sAmount.substr(0, uExp)) : 0; + if (iInteger >= 0) + { + uValue = static_cast(iInteger); + } + else + { + uValue = static_cast(-iInteger); + mIsNegative = true; + } + + iOffset = lexical_cast_st(sAmount.substr(uExp+1)); + } + catch (...) + { + Log(lsINFO) << "Bad e amount: " << sAmount; + + return false; + } + } else { + // Float input: has a decimal + // Example size decimal size-decimal offset // ^1 2 0 2 -1 // 123^ 4 3 1 0 // 1^23 4 1 3 -2 - iOffset = -int(sAmount.size() - uDecimal - 1); - - - // Issolate integer and fraction. - uint64 uInteger; - int64 iInteger = uDecimal ? lexical_cast_st(sAmount.substr(0, uDecimal)) : 0; - if (iInteger >= 0) - uInteger = static_cast(iInteger); - else + try { - uInteger = static_cast(-iInteger); - mIsNegative = true; + iOffset = -int(sAmount.size() - uDecimal - 1); + + // Issolate integer and fraction. + uint64 uInteger; + int64 iInteger = uDecimal ? lexical_cast_st(sAmount.substr(0, uDecimal)) : 0; + if (iInteger >= 0) + { + uInteger = static_cast(iInteger); + } + else + { + uInteger = static_cast(-iInteger); + mIsNegative = true; + } + + uint64 uFraction = iOffset ? lexical_cast_st(sAmount.substr(uDecimal+1)) : 0; + + // Scale the integer portion to the same offset as the fraction. + uValue = uInteger; + for (int i = -iOffset; i--;) + uValue *= 10; + + // Add in the fraction. + uValue += uFraction; } + catch (...) + { + Log(lsINFO) << "Bad float amount: " << sAmount; - - uint64 uFraction = iOffset ? lexical_cast_st(sAmount.substr(uDecimal+1)) : 0; - - // Scale the integer portion to the same offset as the fraction. - uValue = uInteger; - for (int i = -iOffset; i--;) - uValue *= 10; - - // Add in the fraction. - uValue += uFraction; + return false; + } } if (mIsNative) From 891744431e71823748e1e3a6c2f0908648727818 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Tue, 9 Oct 2012 16:05:25 -0700 Subject: [PATCH 4/4] UT: test for empty string with stringToHex and hexToString. --- test/standalone-test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/standalone-test.js b/test/standalone-test.js index 572b0d0b5..640c27486 100644 --- a/test/standalone-test.js +++ b/test/standalone-test.js @@ -24,6 +24,9 @@ buster.testCase("Utils", { }, "Under 10: 1" : function () { buster.assert.equals("01", utils.stringToHex(utils.hexToString("1"))); + }, + "Empty" : function () { + buster.assert.equals("", utils.stringToHex(utils.hexToString(""))); } } });