Skip to content

Commit

Permalink
Change offerID to int64_t
Browse files Browse the repository at this point in the history
  • Loading branch information
marta-lokhova committed Apr 16, 2019
1 parent 33a8f47 commit 25b0559
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 106 deletions.
5 changes: 2 additions & 3 deletions src/invariant/LedgerEntryIsValid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,9 @@ LedgerEntryIsValid::checkIsValid(TrustLineEntry const& tl, uint32 version) const
std::string
LedgerEntryIsValid::checkIsValid(OfferEntry const& oe, uint32 version) const
{
if (oe.offerID > INT64_MAX)
if (oe.offerID <= 0)
{
return fmt::format("Offer offerID ({}) exceeds limit ({})", oe.offerID,
INT64_MAX);
return fmt::format("Offer offerID ({}) must be positive", oe.offerID);
}
if (!isAssetValid(oe.selling))
{
Expand Down
20 changes: 9 additions & 11 deletions src/ledger/LedgerTxnOfferSQL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ namespace stellar
std::shared_ptr<LedgerEntry const>
LedgerTxnRoot::Impl::loadOffer(LedgerKey const& key) const
{
uint64_t offerID = key.offer().offerID;
if (offerID > INT64_MAX)
int64_t offerID = key.offer().offerID;
if (offerID < 0)
{
return nullptr;
}
Expand All @@ -34,18 +34,16 @@ LedgerTxnRoot::Impl::loadOffer(LedgerKey const& key) const
auto prep = mDatabase.getPreparedStatement(sql);
auto& st = prep.statement();
st.exchange(soci::use(actIDStrKey));
int64_t signedOfferID = unsignedToSigned(offerID);
st.exchange(soci::use(signedOfferID));
st.exchange(soci::use(offerID));

std::vector<LedgerEntry> offers;
{
auto timer = mDatabase.getSelectTimer("offer");
offers = loadOffers(prep);
}

return offers.size() == 0
? nullptr
: std::make_shared<LedgerEntry const>(offers.front());
return offers.empty() ? nullptr
: std::make_shared<LedgerEntry const>(offers.front());
}

std::vector<LedgerEntry>
Expand Down Expand Up @@ -582,14 +580,14 @@ class BulkLoadOffersOperation
{
Database& mDb;
std::vector<int64_t> mOfferIDs;
std::unordered_map<uint64_t, AccountID> mSellerIDsByOfferID;
std::unordered_map<int64_t, AccountID> mSellerIDsByOfferID;

std::vector<LedgerEntry>
executeAndFetch(soci::statement& st)
{
std::string sellerID, sellingAsset, buyingAsset;
int64_t amount;
uint64_t offerID;
int64_t offerID;
uint32_t flags, lastModified;
Price price;

Expand Down Expand Up @@ -648,9 +646,9 @@ class BulkLoadOffersOperation
for (auto const& k : keys)
{
assert(k.type() == OFFER);
if (k.offer().offerID <= INT64_MAX)
if (k.offer().offerID >= 0)
{
mOfferIDs.emplace_back(unsignedToSigned(k.offer().offerID));
mOfferIDs.emplace_back(k.offer().offerID);
mSellerIDsByOfferID[mOfferIDs.back()] = k.offer().sellerID;
}
}
Expand Down
34 changes: 17 additions & 17 deletions src/ledger/test/LedgerTxnTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ TEST_CASE("LedgerTxn loadWithoutRecord", "[ledgerstate]")
static void
applyLedgerTxnUpdates(
AbstractLedgerTxn& ltx,
std::map<std::pair<AccountID, uint64_t>,
std::map<std::pair<AccountID, int64_t>,
std::tuple<Asset, Asset, int64_t>> const& updates)
{
for (auto const& kv : updates)
Expand Down Expand Up @@ -1318,13 +1318,13 @@ static void
testAllOffers(
AbstractLedgerTxnParent& ltxParent,
std::map<AccountID,
std::vector<std::tuple<uint64_t, Asset, Asset, int64_t>>> const&
std::vector<std::tuple<int64_t, Asset, Asset, int64_t>>> const&
expected,
std::vector<std::map<std::pair<AccountID, uint64_t>,
std::vector<std::map<std::pair<AccountID, int64_t>,
std::tuple<Asset, Asset, int64_t>>>::const_iterator
begin,
std::vector<
std::map<std::pair<AccountID, uint64_t>,
std::map<std::pair<AccountID, int64_t>,
std::tuple<Asset, Asset, int64_t>>>::const_iterator const& end)
{
REQUIRE(begin != end);
Expand Down Expand Up @@ -1370,9 +1370,9 @@ testAllOffers(
static void
testAllOffers(
std::map<AccountID,
std::vector<std::tuple<uint64_t, Asset, Asset, int64_t>>> const&
std::vector<std::tuple<int64_t, Asset, Asset, int64_t>>> const&
expected,
std::vector<std::map<std::pair<AccountID, uint64_t>,
std::vector<std::map<std::pair<AccountID, int64_t>,
std::tuple<Asset, Asset, int64_t>>> const& updates)
{
REQUIRE(!updates.empty());
Expand Down Expand Up @@ -1547,7 +1547,7 @@ TEST_CASE("LedgerTxn loadAllOffers", "[ledgerstate]")
static void
applyLedgerTxnUpdates(
AbstractLedgerTxn& ltx,
std::map<std::pair<AccountID, uint64_t>,
std::map<std::pair<AccountID, int64_t>,
std::tuple<Asset, Asset, Price, int64_t>> const& updates)
{
for (auto const& kv : updates)
Expand Down Expand Up @@ -1583,12 +1583,12 @@ static void
testBestOffer(
AbstractLedgerTxnParent& ltxParent, Asset const& buying,
Asset const& selling,
std::vector<std::tuple<uint64_t, Asset, Asset, Price, int64_t>> const&
std::vector<std::tuple<int64_t, Asset, Asset, Price, int64_t>> const&
expected,
std::vector<std::map<std::pair<AccountID, uint64_t>,
std::vector<std::map<std::pair<AccountID, int64_t>,
std::tuple<Asset, Asset, Price, int64_t>>>::
const_iterator begin,
std::vector<std::map<std::pair<AccountID, uint64_t>,
std::vector<std::map<std::pair<AccountID, int64_t>,
std::tuple<Asset, Asset, Price, int64_t>>>::
const_iterator const& end)
{
Expand Down Expand Up @@ -1621,9 +1621,9 @@ testBestOffer(
static void
testBestOffer(
Asset const& buying, Asset const& selling,
std::vector<std::tuple<uint64_t, Asset, Asset, Price, int64_t>> const&
std::vector<std::tuple<int64_t, Asset, Asset, Price, int64_t>> const&
expected,
std::vector<std::map<std::pair<AccountID, uint64_t>,
std::vector<std::map<std::pair<AccountID, int64_t>,
std::tuple<Asset, Asset, Price, int64_t>>>
updates)
{
Expand Down Expand Up @@ -1826,12 +1826,12 @@ static void
testOffersByAccountAndAsset(
AbstractLedgerTxnParent& ltxParent, AccountID const& accountID,
Asset const& asset,
std::vector<std::tuple<uint64_t, Asset, Asset, int64_t>> const& expected,
std::vector<std::map<std::pair<AccountID, uint64_t>,
std::vector<std::tuple<int64_t, Asset, Asset, int64_t>> const& expected,
std::vector<std::map<std::pair<AccountID, int64_t>,
std::tuple<Asset, Asset, int64_t>>>::const_iterator
begin,
std::vector<
std::map<std::pair<AccountID, uint64_t>,
std::map<std::pair<AccountID, int64_t>,
std::tuple<Asset, Asset, int64_t>>>::const_iterator const& end)
{
REQUIRE(begin != end);
Expand Down Expand Up @@ -1864,8 +1864,8 @@ testOffersByAccountAndAsset(
static void
testOffersByAccountAndAsset(
AccountID const& accountID, Asset const& asset,
std::vector<std::tuple<uint64_t, Asset, Asset, int64_t>> const& expected,
std::vector<std::map<std::pair<AccountID, uint64_t>,
std::vector<std::tuple<int64_t, Asset, Asset, int64_t>> const& expected,
std::vector<std::map<std::pair<AccountID, int64_t>,
std::tuple<Asset, Asset, int64_t>>>
updates)
{
Expand Down
10 changes: 5 additions & 5 deletions src/test/TestAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ TestAccount::bumpSequence(SequenceNumber to)
applyTx(tx({txtest::bumpSequence(to)}), mApp, false);
}

uint64_t
TestAccount::manageOffer(uint64_t offerID, Asset const& selling,
int64_t
TestAccount::manageOffer(int64_t offerID, Asset const& selling,
Asset const& buying, Price const& price,
int64_t amount, ManageOfferEffect expectedEffect)
{
Expand All @@ -223,8 +223,8 @@ TestAccount::manageOffer(uint64_t offerID, Asset const& selling,
expectedEffect);
}

uint64_t
TestAccount::manageBuyOffer(uint64_t offerID, Asset const& selling,
int64_t
TestAccount::manageBuyOffer(int64_t offerID, Asset const& selling,
Asset const& buying, Price const& price,
int64_t amount, ManageOfferEffect expectedEffect)
{
Expand All @@ -233,7 +233,7 @@ TestAccount::manageBuyOffer(uint64_t offerID, Asset const& selling,
expectedEffect);
}

uint64_t
int64_t
TestAccount::createPassiveOffer(Asset const& selling, Asset const& buying,
Price const& price, int64_t amount,
ManageOfferEffect expectedEffect)
Expand Down
10 changes: 5 additions & 5 deletions src/test/TestAccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ class TestAccount

void bumpSequence(SequenceNumber to);

uint64_t
manageOffer(uint64_t offerID, Asset const& selling, Asset const& buying,
int64_t
manageOffer(int64_t offerID, Asset const& selling, Asset const& buying,
Price const& price, int64_t amount,
ManageOfferEffect expectedEffect = MANAGE_OFFER_CREATED);

uint64_t
manageBuyOffer(uint64_t offerID, Asset const& selling, Asset const& buying,
int64_t
manageBuyOffer(int64_t offerID, Asset const& selling, Asset const& buying,
Price const& price, int64_t amount,
ManageOfferEffect expectedEffect = MANAGE_OFFER_CREATED);

uint64_t
int64_t
createPassiveOffer(Asset const& selling, Asset const& buying,
Price const& price, int64_t amount,
ManageOfferEffect expectedEffect = MANAGE_OFFER_CREATED);
Expand Down
2 changes: 1 addition & 1 deletion src/test/TestMarket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ TestMarket::addOffer(TestAccount& account, OfferState const& state,
}

TestMarketOffer
TestMarket::updateOffer(TestAccount& account, uint64_t id,
TestMarket::updateOffer(TestAccount& account, int64_t id,
OfferState const& state,
OfferState const& finishedState)
{
Expand Down
6 changes: 3 additions & 3 deletions src/test/TestMarket.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct OfferEntry;
struct OfferKey
{
AccountID sellerID;
uint64_t offerID;
int64_t offerID;

friend bool operator<(OfferKey const& x, OfferKey const& y);
};
Expand Down Expand Up @@ -96,7 +96,7 @@ class TestMarket
OfferState const& finishedState = OfferState::SAME);

TestMarketOffer
updateOffer(TestAccount& account, uint64_t id, OfferState const& state,
updateOffer(TestAccount& account, int64_t id, OfferState const& state,
OfferState const& finishedState = OfferState::SAME);

void requireChanges(std::vector<TestMarketOffer> const& changes,
Expand All @@ -112,7 +112,7 @@ class TestMarket
private:
Application& mApp;
std::map<OfferKey, OfferState> mOffers;
uint64_t mLastAddedID{0};
int64_t mLastAddedID{0};

void checkState(std::map<OfferKey, OfferState> const& offers,
std::vector<OfferKey> const& deletedOffers);
Expand Down
21 changes: 10 additions & 11 deletions src/test/TxTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ createPassiveOffer(Asset const& selling, Asset const& buying,
}

Operation
manageOffer(uint64 offerId, Asset const& selling, Asset const& buying,
manageOffer(int64 offerId, Asset const& selling, Asset const& buying,
Price const& price, int64_t amount)
{
Operation op;
Expand All @@ -572,7 +572,7 @@ manageOffer(uint64 offerId, Asset const& selling, Asset const& buying,
}

Operation
manageBuyOffer(uint64 offerId, Asset const& selling, Asset const& buying,
manageBuyOffer(int64 offerId, Asset const& selling, Asset const& buying,
Price const& price, int64_t amount)
{
Operation op;
Expand All @@ -587,10 +587,9 @@ manageBuyOffer(uint64 offerId, Asset const& selling, Asset const& buying,
}

static ManageSellOfferResult
applyCreateOfferHelper(Application& app, uint64 offerId,
SecretKey const& source, Asset const& selling,
Asset const& buying, Price const& price, int64_t amount,
SequenceNumber seq)
applyCreateOfferHelper(Application& app, int64 offerId, SecretKey const& source,
Asset const& selling, Asset const& buying,
Price const& price, int64_t amount, SequenceNumber seq)
{
auto getIdPool = [&]() {
LedgerTxn ltx(app.getLedgerTxnRoot());
Expand Down Expand Up @@ -654,8 +653,8 @@ applyCreateOfferHelper(Application& app, uint64 offerId,
return manageSellOfferResult;
}

uint64_t
applyManageOffer(Application& app, uint64 offerId, SecretKey const& source,
int64_t
applyManageOffer(Application& app, int64 offerId, SecretKey const& source,
Asset const& selling, Asset const& buying, Price const& price,
int64_t amount, SequenceNumber seq,
ManageOfferEffect expectedEffect)
Expand All @@ -669,8 +668,8 @@ applyManageOffer(Application& app, uint64 offerId, SecretKey const& source,
: 0;
}

uint64_t
applyManageBuyOffer(Application& app, uint64 offerId, SecretKey const& source,
int64_t
applyManageBuyOffer(Application& app, int64 offerId, SecretKey const& source,
Asset const& selling, Asset const& buying,
Price const& price, int64_t amount, SequenceNumber seq,
ManageOfferEffect expectedEffect)
Expand Down Expand Up @@ -736,7 +735,7 @@ applyManageBuyOffer(Application& app, uint64 offerId, SecretKey const& source,
: 0;
}

uint64_t
int64_t
applyCreatePassiveOffer(Application& app, SecretKey const& source,
Asset const& selling, Asset const& buying,
Price const& price, int64_t amount, SequenceNumber seq,
Expand Down
36 changes: 18 additions & 18 deletions src/test/TxTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,34 +126,34 @@ Operation pathPayment(PublicKey const& to, Asset const& sendCur,
int64_t sendMax, Asset const& destCur, int64_t destAmount,
std::vector<Asset> const& path);

Operation manageOffer(uint64 offerId, Asset const& selling, Asset const& buying,
Operation manageOffer(int64 offerId, Asset const& selling, Asset const& buying,
Price const& price, int64_t amount);
Operation manageBuyOffer(uint64 offerId, Asset const& selling,
Operation manageBuyOffer(int64 offerId, Asset const& selling,
Asset const& buying, Price const& price,
int64_t amount);

Operation createPassiveOffer(Asset const& selling, Asset const& buying,
Price const& price, int64_t amount);

// returns the ID of the new offer if created
uint64_t applyManageOffer(Application& app, uint64 offerId,
SecretKey const& source, Asset const& selling,
Asset const& buying, Price const& price,
int64_t amount, SequenceNumber seq,
ManageOfferEffect expectedEffect);

uint64_t applyManageBuyOffer(Application& app, uint64 offerId,
SecretKey const& source, Asset const& selling,
Asset const& buying, Price const& price,
int64_t amount, SequenceNumber seq,
ManageOfferEffect expectedEffect);
int64_t applyManageOffer(Application& app, int64 offerId,
SecretKey const& source, Asset const& selling,
Asset const& buying, Price const& price,
int64_t amount, SequenceNumber seq,
ManageOfferEffect expectedEffect);

int64_t applyManageBuyOffer(Application& app, int64 offerId,
SecretKey const& source, Asset const& selling,
Asset const& buying, Price const& price,
int64_t amount, SequenceNumber seq,
ManageOfferEffect expectedEffect);

// returns the ID of the new offer if created
uint64_t applyCreatePassiveOffer(Application& app, SecretKey const& source,
Asset const& selling, Asset const& buying,
Price const& price, int64_t amount,
SequenceNumber seq,
ManageOfferEffect expectedEffect);
int64_t applyCreatePassiveOffer(Application& app, SecretKey const& source,
Asset const& selling, Asset const& buying,
Price const& price, int64_t amount,
SequenceNumber seq,
ManageOfferEffect expectedEffect);
Operation setOptions(SetOptionsArguments const& arguments);

SetOptionsArguments setMasterWeight(int master);
Expand Down
4 changes: 2 additions & 2 deletions src/transactions/ManageOfferOpFrameBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace stellar

ManageOfferOpFrameBase::ManageOfferOpFrameBase(
Operation const& op, OperationResult& res, TransactionFrame& parentTx,
Asset const& sheep, Asset const& wheat, uint64_t offerID,
Price const& price, bool setPassiveOnCreate)
Asset const& sheep, Asset const& wheat, int64_t offerID, Price const& price,
bool setPassiveOnCreate)
: OperationFrame(op, res, parentTx)
, mSheep(sheep)
, mWheat(wheat)
Expand Down
Loading

5 comments on commit 25b0559

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from marta-lokhova
at marta-lokhova@25b0559

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging marta-lokhova/stellar-core/xdr_update = 25b0559 into auto

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

marta-lokhova/stellar-core/xdr_update = 25b0559 merged ok, testing candidate = 4f594de

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 4f594de

Please sign in to comment.