better enumeration of preferences, using strings for negative numbers :/
This commit is contained in:
parent
aeeab6bb96
commit
d64a8ae28e
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
22
test.py
22
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()
|
||||
|
|
Loading…
Reference in New Issue