Skip to content

Commit 9e513f7

Browse files
MetaDEx: clean up types + rename still_for_sale to amount_remaining
1 parent 4584a63 commit 9e513f7

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

src/mastercore_mdex.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ using namespace mastercore;
2424

2525
md_PropertiesMap mastercore::metadex;
2626

27-
md_PricesMap* mastercore::get_Prices(unsigned int prop)
27+
md_PricesMap* mastercore::get_Prices(uint32_t prop)
2828
{
2929
md_PropertiesMap::iterator it = metadex.find(prop);
3030

@@ -95,8 +95,8 @@ static MatchReturnType x_Trade(CMPMetaDEx* newo)
9595
{
9696
const CMPMetaDEx* p_older = NULL;
9797
md_PricesMap* prices = NULL;
98-
const unsigned int prop = newo->getProperty();
99-
const unsigned int desprop = newo->getDesProperty();
98+
const uint32_t prop = newo->getProperty();
99+
const uint32_t desprop = newo->getDesProperty();
100100
MatchReturnType NewReturn = NOTHING;
101101
bool bBuyerSatisfied = false;
102102
const XDOUBLE buyersprice = newo->effectivePrice();
@@ -266,7 +266,7 @@ XDOUBLE CMPMetaDEx::inversePrice() const
266266
return inverse_price;
267267
}
268268

269-
void CMPMetaDEx::Set(const std::string& sa, int b, unsigned int c, uint64_t nValue, unsigned int cd, uint64_t ad, const uint256& tx, unsigned int i, unsigned char suba)
269+
void CMPMetaDEx::Set(const std::string& sa, int b, uint32_t c, int64_t nValue, uint32_t cd, int64_t ad, const uint256& tx, uint32_t i, unsigned char suba)
270270
{
271271
addr = sa;
272272
block = b;
@@ -298,7 +298,7 @@ void CMPMetaDEx::saveOffer(std::ofstream& file, SHA256_CTX* shaCtx) const
298298
(unsigned int) subaction,
299299
idx,
300300
txid.ToString(),
301-
still_left_forsale
301+
amount_remaining
302302
);
303303

304304
// add the line to the hash
@@ -315,7 +315,7 @@ bool MetaDEx_compare::operator()(const CMPMetaDEx &lhs, const CMPMetaDEx &rhs) c
315315
}
316316

317317
// pretty much directly linked to the ADD TX21 command off the wire
318-
int mastercore::MetaDEx_ADD(const std::string& sender_addr, unsigned int prop, uint64_t amount, int block, unsigned int property_desired, uint64_t amount_desired, const uint256& txid, unsigned int idx)
318+
int mastercore::MetaDEx_ADD(const std::string& sender_addr, uint32_t prop, int64_t amount, int block, uint32_t property_desired, int64_t amount_desired, const uint256& txid, unsigned int idx)
319319
{
320320
int rc = METADEX_ERROR -1;
321321

@@ -390,7 +390,7 @@ int mastercore::MetaDEx_ADD(const std::string& sender_addr, unsigned int prop, u
390390
return rc;
391391
}
392392

393-
int mastercore::MetaDEx_CANCEL_AT_PRICE(const uint256& txid, unsigned int block, const std::string& sender_addr, unsigned int prop, uint64_t amount, unsigned int property_desired, uint64_t amount_desired)
393+
int mastercore::MetaDEx_CANCEL_AT_PRICE(const uint256& txid, unsigned int block, const std::string& sender_addr, uint32_t prop, int64_t amount, uint32_t property_desired, int64_t amount_desired)
394394
{
395395
int rc = METADEX_ERROR -20;
396396
CMPMetaDEx mdex(sender_addr, 0, prop, amount, property_desired, amount_desired, 0, 0, CMPTransaction::CANCEL_AT_PRICE);
@@ -444,7 +444,7 @@ int mastercore::MetaDEx_CANCEL_AT_PRICE(const uint256& txid, unsigned int block,
444444
return rc;
445445
}
446446

447-
int mastercore::MetaDEx_CANCEL_ALL_FOR_PAIR(const uint256& txid, unsigned int block, const std::string& sender_addr, unsigned int prop, unsigned int property_desired)
447+
int mastercore::MetaDEx_CANCEL_ALL_FOR_PAIR(const uint256& txid, unsigned int block, const std::string& sender_addr, uint32_t prop, uint32_t property_desired)
448448
{
449449
int rc = METADEX_ERROR -30;
450450
md_PricesMap* prices = get_Prices(prop);
@@ -556,7 +556,7 @@ void mastercore::MetaDEx_debug_print(bool bShowPriceLevel, bool bDisplay)
556556
{
557557
file_log("<<<\n");
558558
for (md_PropertiesMap::iterator my_it = metadex.begin(); my_it != metadex.end(); ++my_it) {
559-
unsigned int prop = my_it->first;
559+
uint32_t prop = my_it->first;
560560

561561
file_log(" ## property: %u\n", prop);
562562
md_PricesMap& prices = my_it->second;

src/mastercore_mdex.h

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@ class CMPMetaDEx
3030
private:
3131
int block;
3232
uint256 txid;
33-
//! Index within the block
34-
unsigned int idx;
35-
unsigned int property;
36-
uint64_t amount_forsale;
37-
unsigned int desired_property;
33+
unsigned int idx; // index within block
34+
uint32_t property;
35+
int64_t amount_forsale;
36+
uint32_t desired_property;
3837
int64_t amount_desired;
39-
uint64_t still_left_forsale;
38+
int64_t amount_remaining;
4039
unsigned char subaction;
4140
std::string addr;
4241

@@ -47,8 +46,9 @@ class CMPMetaDEx
4746
unsigned int getProperty() const { return property; }
4847
unsigned int getDesProperty() const { return desired_property; }
4948

50-
uint64_t getAmountForSale() const { return amount_forsale; }
49+
int64_t getAmountForSale() const { return amount_forsale; }
5150
int64_t getAmountDesired() const { return amount_desired; }
51+
int64_t getAmountRemaining() const { return amount_remaining; }
5252

5353
void setAmountForSale(int64_t ao, const std::string& label = "")
5454
{
@@ -62,6 +62,12 @@ class CMPMetaDEx
6262
file_log("%s(%ld %s):%s\n", __FUNCTION__, ad, label, ToString());
6363
}
6464

65+
void setAmountRemaining(int64_t ar, const std::string& label = "")
66+
{
67+
amount_remaining = ar;
68+
file_log("%s(%ld %s):%s\n", __FUNCTION__, ar, label, ToString());
69+
}
70+
6571
unsigned char getAction() const { return subaction; }
6672

6773
const std::string& getAddr() const { return addr; }
@@ -79,14 +85,14 @@ class CMPMetaDEx
7985
// needed only by the RPC functions
8086
CMPMetaDEx()
8187
: block(0), txid(0), idx(0), property(0), amount_forsale(0), desired_property(0), amount_desired(0),
82-
still_left_forsale(0), subaction(0) {}
88+
amount_remaining(0), subaction(0) {}
8389

84-
CMPMetaDEx(const std::string& addr, int b, unsigned int c, uint64_t nValue, unsigned int cd, uint64_t ad,
85-
const uint256& tx, unsigned int i, unsigned char suba, uint64_t lfors = 0)
90+
CMPMetaDEx(const std::string& addr, int b, uint32_t c, int64_t nValue, uint32_t cd, int64_t ad,
91+
const uint256& tx, uint32_t i, unsigned char suba, int64_t ar = 0)
8692
: block(b), txid(tx), idx(i), property(c), amount_forsale(nValue), desired_property(cd), amount_desired(ad),
87-
still_left_forsale(lfors), subaction(suba), addr(addr) {}
93+
amount_remaining(ar), subaction(suba), addr(addr) {}
8894

89-
void Set(const std::string&, int, unsigned int, uint64_t, unsigned int, uint64_t, const uint256&, unsigned int, unsigned char);
95+
void Set(const std::string&, int, uint32_t, int64_t, uint32_t, int64_t, const uint256&, uint32_t, unsigned char);
9096

9197
std::string ToString() const;
9298

@@ -109,19 +115,19 @@ typedef std::set<CMPMetaDEx, MetaDEx_compare> md_Set;
109115
//! Map of prices; there is a set of sorted objects for each price
110116
typedef std::map<XDOUBLE, md_Set> md_PricesMap;
111117
//! Map of properties; there is a map of prices for each property
112-
typedef std::map<unsigned int, md_PricesMap> md_PropertiesMap;
118+
typedef std::map<uint32_t, md_PricesMap> md_PropertiesMap;
113119

114120
extern md_PropertiesMap metadex;
115121

116122
// TODO: explore a property-pair, instead of a single property as map's key........
117-
md_PricesMap* get_Prices(unsigned int prop);
123+
md_PricesMap* get_Prices(uint32_t prop);
118124
md_Set* get_Indexes(md_PricesMap* p, XDOUBLE price);
119125
// ---------------
120126

121-
int MetaDEx_ADD(const std::string& sender_addr, unsigned int, uint64_t, int block, unsigned int property_desired, uint64_t amount_desired, const uint256& txid, unsigned int idx);
122-
int MetaDEx_CANCEL_AT_PRICE(const uint256&, unsigned int, const std::string&, unsigned int, uint64_t, unsigned int, uint64_t);
123-
int MetaDEx_CANCEL_ALL_FOR_PAIR(const uint256&, unsigned int, const std::string&, unsigned int, unsigned int);
124-
int MetaDEx_CANCEL_EVERYTHING(const uint256& txid, unsigned int block, const std::string& sender_addr, unsigned char ecosystem);
127+
int MetaDEx_ADD(const std::string& sender_addr, uint32_t, int64_t, int block, uint32_t property_desired, int64_t amount_desired, const uint256& txid, unsigned int idx);
128+
int MetaDEx_CANCEL_AT_PRICE(const uint256&, uint32_t, const std::string&, uint32_t, int64_t, uint32_t, int64_t);
129+
int MetaDEx_CANCEL_ALL_FOR_PAIR(const uint256&, uint32_t, const std::string&, uint32_t, uint32_t);
130+
int MetaDEx_CANCEL_EVERYTHING(const uint256& txid, uint32_t block, const std::string& sender_addr, unsigned char ecosystem);
125131

126132
void MetaDEx_debug_print(bool bShowPriceLevel = false, bool bDisplay = false);
127133
}

0 commit comments

Comments
 (0)