get/set prices for items
This commit is contained in:
parent
6868556ead
commit
a859357adb
|
@ -0,0 +1,3 @@
|
|||
a.out
|
||||
db
|
||||
|
|
@ -70,6 +70,11 @@ void PosDb::acceptLogEntry(const LogEntry & l) {
|
|||
break;
|
||||
}
|
||||
|
||||
case ET_PRICE: {
|
||||
upc_to_price[l.PriceChange.upc] = l.PriceChange.price;
|
||||
break;
|
||||
}
|
||||
|
||||
case ET_REVERT: {
|
||||
sto_it q = serial_to_object.find(l.Revert.revert_serial);
|
||||
if((q == serial_to_object.end()) || (q->second.type != ET_TRANS)) {
|
||||
|
@ -172,7 +177,7 @@ uint64_t PosDb::deassociateHash(const SHA1Hash & hash) {
|
|||
} else {
|
||||
LogEntry l;
|
||||
memset(&l, 0, sizeof(LogEntry));
|
||||
l.ts = (uint64_t)time(NULL);
|
||||
l.ts = (uint64_t)time(NULL);
|
||||
l.type = ET_HASH;
|
||||
l.HashChange.uid = acct;
|
||||
l.HashChange.add = false;
|
||||
|
@ -184,6 +189,26 @@ uint64_t PosDb::deassociateHash(const SHA1Hash & hash) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t PosDb::getUPCPrice(UPC upc) {
|
||||
uts_it it = upc_to_price.find(upc);
|
||||
if (it == upc_to_price.end()) {
|
||||
return 0;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
uint64_t PosDb::setUPCPrice(UPC upc, int32_t price) {
|
||||
LogEntry l;
|
||||
memset(&l, 0, sizeof(LogEntry));
|
||||
l.ts = (uint64_t)time(NULL);
|
||||
l.type = ET_PRICE;
|
||||
l.PriceChange.upc = upc;
|
||||
l.PriceChange.price = price;
|
||||
l.serial = log.nextSerial();
|
||||
acceptLogEntry(l);
|
||||
return log.writeEntry(l);
|
||||
}
|
||||
|
||||
uint64_t PosDb::doTransaction(const SHA1Hash & hash, int32_t delta) {
|
||||
// verify hash associated with something
|
||||
uint32_t acct = getAccountFromHash(hash);
|
||||
|
|
|
@ -23,6 +23,9 @@ public:
|
|||
uint64_t associateHash(const SHA1Hash & hash, std::string account);
|
||||
uint64_t deassociateHash(const SHA1Hash & hash);
|
||||
|
||||
int32_t getUPCPrice(UPC upc);
|
||||
uint64_t setUPCPrice(UPC upc, int32_t price);
|
||||
|
||||
uint64_t doTransaction(const SHA1Hash & hash, int32_t delta);
|
||||
uint64_t doTransaction(const uint32_t account, int32_t delta);
|
||||
uint64_t doTransaction(std::string account, int32_t delta);
|
||||
|
@ -38,6 +41,7 @@ private:
|
|||
std::map<uint32_t, int32_t> account_to_balance;
|
||||
|
||||
std::map<UPC, int32_t, UPCLess> upc_to_stock;
|
||||
std::map<UPC, int32_t, UPCLess> upc_to_price;
|
||||
|
||||
std::map<uint64_t, LogEntry> serial_to_object;
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <string>
|
||||
#include <stdint.h>
|
||||
|
||||
enum E_OBJ_TYPE { ET_TRANS, ET_HASH, ET_SALE, ET_REVERT };
|
||||
enum E_OBJ_TYPE { ET_TRANS, ET_HASH, ET_SALE, ET_PRICE, ET_REVERT };
|
||||
|
||||
struct __attribute__ ((packed)) UPC {
|
||||
uint64_t h, l;
|
||||
|
@ -43,6 +43,11 @@ struct __attribute__ ((aligned (64), packed)) LogEntry
|
|||
int32_t delta;
|
||||
} StockChange;
|
||||
|
||||
struct __attribute__ ((packed)) {
|
||||
UPC upc;
|
||||
int32_t price;
|
||||
} PriceChange;
|
||||
|
||||
struct __attribute__ ((packed)) {
|
||||
uint64_t revert_serial;
|
||||
} Revert;
|
||||
|
|
|
@ -19,7 +19,6 @@ uint32_t NameServer::get_id (std::string name) {
|
|||
std::cerr << "Doing LDAP lookup for \"" << name << "\".\n";
|
||||
struct passwd* pwd = getpwnam(name.c_str());
|
||||
if (!pwd) {
|
||||
std::cerr << "Username " << name << " lookup fail!\n";
|
||||
// TODO: oh fuck???
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ int main() {
|
|||
UPC foo;
|
||||
foo.l = 12345;
|
||||
foo.h = 67890;
|
||||
cout << db.setUPCPrice(foo, db.getUPCPrice(foo) + 1) << "\n";
|
||||
cout << "price: " << db.getUPCPrice(foo) << "\n";
|
||||
cout << db.doStockChange(foo, 100) << "\n";
|
||||
cout << db.getStock(foo) << "\n";
|
||||
foo.l = 123;
|
||||
|
|
4
main.cpp
4
main.cpp
|
@ -75,7 +75,7 @@ void render () {
|
|||
);
|
||||
static float x = 0;
|
||||
glTranslatef (-8,0,-20);
|
||||
glRotatef (x+=1.0, 0,1,0);
|
||||
glRotatef (x+=0.01, 0,1,0);
|
||||
glRotatef (30.0, 1.0,0,0);
|
||||
|
||||
GLint shader_tex_loc = glGetUniformLocation(shaders[0].prog_id, "texture");
|
||||
|
@ -253,7 +253,7 @@ void GL_init (float w, float h) {
|
|||
}
|
||||
|
||||
int main () {
|
||||
float scale = 3;
|
||||
float scale = 1;
|
||||
float w = 480*scale;
|
||||
float h = 272*scale;
|
||||
if (!glfwInit () || !glfwOpenWindow (w, h, 8,8,8,0,32,0,GLFW_WINDOW)) {
|
||||
|
|
Loading…
Reference in New Issue