get match making listening to announces and reading ticket information

This commit is contained in:
Jarrad Hope 2015-07-19 14:18:45 +02:00
parent 2e3656b61e
commit 03fe67e019
3 changed files with 30 additions and 18 deletions

View File

@ -97,6 +97,9 @@ def deactivate(ticket):
self.pool[bidkey].state = -1 # non existant
def get_info(ticket):
return([self.pool[ticket].owner, self.pool[ticket].epoch, self.pool[ticket].state]:arr)
def get_preferences(ticket):
# TODO look at outitems clearly
return(self.traverse(self.pool[ticket].preferences.head, outitems=256):arr)

View File

@ -11,7 +11,7 @@ macro private($x):
# traverse the list given either the head or the tail
def traverse(start): # pointer to head or tail
private:
output = array(256)
output = array(64)
i = 0
cur = start
prev = start
@ -32,7 +32,7 @@ def traverse(start): # pointer to head or tail
tmp = cur
cur = prev xor self.xorll[cur].np
prev = tmp
return(slice(output, items=0, items=256):arr)
return(output:arr)
def insert(key, value, prev, cur):

41
test.py
View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from ethereum import tester, slogging
from ethereum import tester, slogging, utils
import os
state = tester.state()
@ -12,20 +12,36 @@ market = state.abi_contract('contracts/market.se', gas=10000000)
# Create Match Maker
class Matchmaker:
def announce(self, data):
ticket = data[0]
info = market.get_info(ticket)
preferences = market.get_preferences(ticket)
print('ticket #', ticket)
print('ticket info', info)
print('ticket preferences', preferences)
def listener(self, msg):
if msg['event'] == 'LOG':
print('announce', msg['topics'])
# TODO: get ticket preferences
'''
Dynamically call Methods based on first param
Currently only announce exists
'''
if msg['event'] == 'LOG' and msg['to'] == self.market:
msg_type = utils.encode_int(msg['topics'][0]).rstrip('\x00')
msg_data = msg['topics'][1:]
try:
getattr(self, msg_type)(msg_data)
except:
raise NotImplementedError(msg_type, msg_data)
def __init__(self):
pass
# slogging.log_listeners.listeners.append(self.listener)
def __init__(self, market):
self.market = market
slogging.log_listeners.listeners.append(self.listener)
match_maker = Matchmaker()
market = '\xc3\x05\xc9\x01\x07\x87\x81\xc22\xa2\xa5!\xc2\xafy\x80\xf88^\xe9'
match_maker = Matchmaker(market)
# Create buy ticket, add preferences, activate
buy_ticket = market.add()
print('buy_ticket', buy_ticket)
market.add_preference(buy_ticket, 'head', 10)
market.add_preference(buy_ticket, 'tail', 20)
market.add_preference(buy_ticket, 'price', 5)
@ -33,14 +49,7 @@ market.activate(buy_ticket)
# Create sell ticket, add preferences, activate
sell_ticket = market.add()
print('sell_ticket', sell_ticket)
market.add_preference(sell_ticket, 'price', -5)
market.activate(sell_ticket)
# print('reveal', market.add_sealed_offer(0, 1))
print('enumerate buy_ticket preferences')
print(market.get_preferences(buy_ticket))
print('enumerate sell_ticket preferences')
print(market.get_preferences(sell_ticket))