@@ -0,0 +1,2265 @@
+# Ethereum flashcards smart-contract v1.0%0D%0A#%0D%0A# This contract is used to place/execute sell and buy%0D%0A# orders for flashcard categories in codingchili/flashcards-webapp.git%0D%0A%0D%0A# maps category owners to a category and its cost.%0D%0Acategories: %7B%0D%0A    category: bytes32,%0D%0A    owner: address,%0D%0A    cost: wei_value,%0D%0A%7D%5Bbytes32%5D%0D%0A%0D%0A# maps buyers to categories for successful purchases.%0D%0Aorders: %7B%0D%0A    buyer: address,%0D%0A    category: bytes32,%0D%0A%7D%5Baddress%5D%0D%0A%0D%0A# a fee in percentage 0.0-1.0 to deduct from purchases%0D%0Afee: public(decimal)%0D%0A# the address of the broker, for arbitrage.%0D%0Abroker: public(address)%0D%0A%0D%0A@public%0D%0Adef __init__():%0D%0A    self.fee = 0.05%0D%0A    self.broker = msg.sender%0D%0A%0D%0A# adds a new category and assigns it to the sending address.%0D%0A@public%0D%0Adef submit(categoryId: bytes32, cost: wei_value):%0D%0A    # assert category does not exist - to prevent overwriting.%0D%0A    assert not (self.categories%5BcategoryId%5D)%0D%0A    self.categories%5BcategoryId%5D.cost = cost;%0D%0A    self.categories%5BcategoryId%5D.owner = msg.sender;%0D%0A    self.categories%5BcategoryId%5D.category = categoryId;%0D%0A    pass%0D%0A%0D%0A# changes the cost of a category, cannot change the address!%0D%0A@public%0D%0Adef update(categoryId: bytes32, cost: wei_value):%0D%0A    assert self.categories%5BcategoryId%5D%0D%0A    assert self.categories%5BcategoryId%5D.owner == msg.sender%0D%0A    self.categories%5BcategoryId%5D.cost = cost%0D%0A%0D%0A# attempts to purchase the specified category.%0D%0A@public%0D%0A@payable%0D%0Adef purchase(categoryId: bytes32):%0D%0A    # ensure the payment is appropriate.%0D%0A    assert msg.value == self.categories%5BcategoryId%5D.cost;%0D%0A%0D%0A    # ensure the sender does not already own the category.%0D%0A    assert not (self.orders%5Bmsg.sender%5D)%0D%0A%0D%0A    # transfer funds to owner and the broker.%0D%0A    send(self.broker, as_wei_value(msg.value * self.fee, wei))%0D%0A    send(self.categories%5BcategoryId%5D.owner, as_wei_value(msg.value * (1 - self.fee), wei))%0D%0A%0D%0A    # add the order: todo: enable one-to-many mappings.%0D%0A    self.orders%5Bmsg.sender%5D.category = categoryId%0D%0A%0D%0A# returns the cost of the given category id.%0D%0A@public%0D%0A@constant%0D%0Adef cost(categoryId: bytes32) -%3E wei_value:%0D%0A    return self.categories%5BcategoryId%5D.cost;%0D%0A%0D%0A# returns true if the given address has bought%0D%0A@public%0D%0A@constant%0D%0Adef allowed(buyer: bytes32) -%3E bool:%0D%0A    return self.orders%5Bbuyer%5D;

Add first draft of ethereum trading contract in Viper.