From d64a8ae28eebe0b71bdccaa6ec129c8106fede02 Mon Sep 17 00:00:00 2001 From: Jarrad Hope Date: Sat, 18 Jul 2015 19:36:55 +0200 Subject: [PATCH] better enumeration of preferences, using strings for negative numbers :/ --- contracts/market.se | 23 ++++++++++------------- contracts/xorll.se | 5 ++--- test.py | 22 +++++----------------- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/contracts/market.se b/contracts/market.se index 488b84c..9e15304 100644 --- a/contracts/market.se +++ b/contracts/market.se @@ -34,25 +34,23 @@ def shared(): def add(): - # not ideal, only one bid per block per sender - key = self.ticket + ticket = self.ticket self.ticket = self.ticket + 1 - self.pool[key].owner = msg.sender - self.pool[key].epoch = block.number - self.pool[key].state = 0 # inactive + self.pool[ticket].owner = msg.sender + self.pool[ticket].epoch = block.number + self.pool[ticket].state = 0 # inactive # Preferences # Head pointer # TODO: Maybe insert returns np and key, maybe also use autoincrement - # TODO: Make sure no overlap in xorll keys (sha) - head = self.insert("ticket" + key, 10+key, 0, 0) - self.pool[key].preferences.head = head + # TODO: Make SHA3 happen in insert, save label, maybe can use autoincrement for pointers instead of hash? + head = self.insert(sha3(ticket + "head"), 10+ticket, 0, 0) + self.pool[ticket].preferences.head = head # Tail pointer - self.pool[key].preferences.tail = self.insert("tail" + key, 20, 0, head) + self.pool[ticket].preferences.tail = self.insert(sha3(ticket + "tail"), 20, 0, head) # TODO: insurance references - - return(key) + return(ticket) def add_preference(ticket, key, value): @@ -61,7 +59,7 @@ def add_preference(ticket, key, value): tail = self.pool[ticket].preferences.tail # or make tail() return np in insert as well? tail_np = self.np(tail) - tail = self.insert(key + ticket, value, tail_np, tail) + tail = self.insert(sha3(ticket + key), value, tail_np, tail) self.pool[ticket].preferences.tail = tail @@ -88,7 +86,6 @@ def deactivate(ticket): def get_preferences(ticket): - log(ticket, self.pool[ticket].preferences.head) self.traverse(self.pool[ticket].preferences.head) diff --git a/contracts/xorll.se b/contracts/xorll.se index 043cc88..8b1b54e 100644 --- a/contracts/xorll.se +++ b/contracts/xorll.se @@ -6,7 +6,6 @@ data xorll[](value, np) # np = next xor previous # traverse the list given either the head or the tail def traverse(start): # pointer to head or tail - log(666, start) cur = start prev = start @@ -26,8 +25,8 @@ def traverse(start): # pointer to head or tail def insert(pointer, value, prev, cur): - if self.xorll[pointer].value != 0: - stop + # if self.xorll[pointer].value != 0: + # stop self.xorll[pointer].value = value self.xorll[pointer].np = cur # end node points to previous one diff --git a/test.py b/test.py index 69cbe60..a4190a2 100644 --- a/test.py +++ b/test.py @@ -24,32 +24,20 @@ match_maker = Matchmaker() # Create buy ticket, add preferences, activate buy_ticket = market.add() -market.add_preference(buy_ticket, "price", 5) +print('buy_ticket', buy_ticket) +market.add_preference(buy_ticket, 'price', '5') market.activate(buy_ticket) # Create sell ticket, add preferences, activate sell_ticket = market.add() -market.add_preference(sell_ticket, "price", 7) +print('sell_ticket', sell_ticket) +market.add_preference(sell_ticket, 'price', '-7') # TODO: handle negative numbers market.activate(sell_ticket) -print('reveal', market.add_sealed_offer(0, 1)) +# print('reveal', market.add_sealed_offer(0, 1)) print('enumerate buy_ticket preferences') market.get_preferences(buy_ticket) print('enumerate sell_ticket preferences') market.get_preferences(sell_ticket) - - -# head = tail = xorll.insert("head", 10, 0, 0) -# tail = xorll.insert("tail", 20, 0, tail) - -# tail = xorll.insert("monkey", 30, xorll.np(tail), tail) -# tail = xorll.insert("finger", 40, xorll.np(tail), tail) - -# print('---') -# xorll.traverse(head) -# print('---') -# xorll.traverse(tail) -# print('---') -# xorll.test()