Skip to content

Commit

Permalink
Merge pull request #24 from Storj/remove-contract
Browse files Browse the repository at this point in the history
Remove Contracts from Codebase
  • Loading branch information
super3 committed Aug 3, 2015
2 parents 8218956 + 37348b8 commit cc11b43
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 406 deletions.
57 changes: 0 additions & 57 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,63 +144,6 @@ Success Examples:
1CgLoZT1ZuSHPBp3H4rLTXJvEUDV3kK7QK | Last Seen: 13 second(s) | Height: 245
1QACy1Tx5JFzGDyPd8J3oU8SrjhkZkru4H | Last Seen: 14 second(s) | Height: 88

List Contracts
**************

We want to know what contracts the node thinks the node the farmer should be storing.

::

GET /api/contract/list/<btc_address>/

Success Example:

::

GET /api/contract/list/191GVvAaTRxLmz3rW3nU5jAV1rF186VxQc/
RESPONSE:
Status Code: 200
Text:
{
"contracts": [
{
"btc_addr": "191GVvAaTRxLmz3rW3nU5jAV1rF186VxQc",
"byte_size": 10485760,
"contract_type": 0,
"file_hash": "d83c2384e8607e3f521eb00fa4866ceb6c8032983c31e8ab614d7bac5ff49475",
"seed": "102255e2105f2e6b4fe0579b"
},
{
"btc_addr": "191GVvAaTRxLmz3rW3nU5jAV1rF186VxQc",
"byte_size": 10485760,
"contract_type": 0,
"file_hash": "cc5f1a89e3a07e6f5c03b4066382ef1514ca20a81f597ff72480ec999cdca9b1",
"seed": "49ea747563eba1e51d824e50"
},
{
"btc_addr": "191GVvAaTRxLmz3rW3nU5jAV1rF186VxQc",
"byte_size": 10485760,
"contract_type": 0,
"file_hash": "d6d360e3d1aebee804556203d18a728cf25695ceaf66bc3efe7ad6e997502c41",
"seed": "08c339176c805439ca8a12d9"
}
]
}

Fail Example:

::

GET /api/contract/list/notvalidaddress/
RESPONSE:
Status Code: 400
Text: Invalid BTC Address.

GET /api/contract/list/1EawBV7n7f2wDbgxJfNzo1eHyQ9Gj77oJd/
RESPONSE:
Status Code: 404
Text: Farmer not found.


Advertise Height
****************
Expand Down
107 changes: 0 additions & 107 deletions dataserv/Contract.py

This file was deleted.

16 changes: 0 additions & 16 deletions dataserv/Farmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from dataserv.run import db
from datetime import datetime
from sqlalchemy import DateTime
from dataserv.Contract import Contract
from dataserv.Validator import is_btc_address


Expand Down Expand Up @@ -84,21 +83,6 @@ def audit(self):
"""
self.ping()

def new_contract(self, seed=None):
"""Generate a new contract for the farmer."""
self.validate()

con = Contract(self.btc_addr)
con.new_contract(seed)
return con.to_json()

def list_contracts(self):
"""List all current contracts for the farmer."""
self.validate()

con = Contract(self.btc_addr)
return con.list_contracts()

def set_height(self, height):
"""Set the farmers advertised height."""
self.validate()
Expand Down
42 changes: 1 addition & 41 deletions dataserv/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import os.path
import datetime
from flask import make_response, jsonify
from flask import make_response
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))


Expand Down Expand Up @@ -90,46 +90,6 @@ def online():
return output


@app.route('/api/contract/new/<btc_addr>', methods=["GET"])
def new_contract(btc_addr):
# create Farmer object to represent user
user = Farmer(btc_addr)

# error template
error_msg = "Contract Failed: {0}"

# attempt to register the farmer/farming address
try:
contract_payload = user.new_contract()
return make_response(jsonify(contract_payload), 200)
except ValueError:
msg = "Invalid BTC Address."
return make_response(error_msg.format(msg), 400)
except LookupError:
msg = "Farmer Not Found."
return make_response(error_msg.format(msg), 404)
except MemoryError:
msg = "Contract Capacity Limit Reached."
return make_response(error_msg.format(msg), 413)


@app.route('/api/contract/list/<btc_addr>', methods=["GET"])
def list_contracts(btc_addr):
# create Farmer object to represent user
user = Farmer(btc_addr)

# attempt to register the farmer/farming address
try:
contract_payload = user.list_contracts()
return make_response(jsonify(contract_payload), 200)
except ValueError:
msg = "Invalid BTC Address."
return make_response(msg, 400)
except LookupError:
msg = "Farmer Not Found."
return make_response(msg, 404)


@app.route('/api/height/<btc_addr>/<int:height>', methods=["GET"])
def set_height(btc_addr, height):
# create Farmer object to represent user
Expand Down
70 changes: 0 additions & 70 deletions tests/test_App.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import unittest
from dataserv.run import app, db
from dataserv.app import secs_to_mins
Expand Down Expand Up @@ -106,75 +105,6 @@ def test_online(self):
# see if that address is in the online status
self.assertTrue(addr in str(rv.data))

def test_new_contract(self):
addr = '191GVvAaTRxLmz3rW3nU5jAV1rF186VxQc'
rv = self.app.get('/api/register/{0}'.format(addr))

# good registration
self.assertEqual(b"User registered.", rv.data)
self.assertEqual(rv.status_code, 200)

# grab a contract
rv = self.app.get('/api/contract/new/{0}'.format(addr))
self.assertEqual(rv.status_code, 200)
json_data = json.loads(rv.data.decode("utf-8"))

# check type 0 contracts
self.assertEqual(json_data["btc_addr"], addr)
self.assertEqual(json_data["contract_type"], 0)
self.assertEqual(json_data["byte_size"], app.config["BYTE_SIZE"])

def test_new_contract_fail(self):
addr1 = '191GVvAaTRxLmz3rW3nU5jAV1rF186VxQc'
addr2 = 'notvalidaddress'

# grab a contract with no farmer registered
rv = self.app.get('/api/contract/new/{0}'.format(addr1))
self.assertEqual(rv.status_code, 404)

# grab a contract with invalid btc address
rv = self.app.get('/api/contract/new/{0}'.format(addr2))
self.assertEqual(rv.status_code, 400)

def test_max_contracts(self):
addr = '191GVvAaTRxLmz3rW3nU5jAV1rF186VxQc'
self.app.get('/api/register/{0}'.format(addr))

# force app config to testing params
app.config["BYTE_SIZE"] = 10*1024*1024 # 10 MB
app.config["BYTE_FARMER_MAX"] = 30*1024*1024 # 30 MB

self.app.get('/api/contract/new/{0}'.format(addr))
self.app.get('/api/contract/new/{0}'.format(addr))
self.app.get('/api/contract/new/{0}'.format(addr))
rv = self.app.get('/api/contract/new/{0}'.format(addr))
self.assertEqual(rv.status_code, 413)

def test_list_contracts(self):
addr = '191GVvAaTRxLmz3rW3nU5jAV1rF186VxQc'
self.app.get('/api/register/{0}'.format(addr))

# force app config to testing params
app.config["BYTE_SIZE"] = 10*1024*1024 # 10 MB
app.config["BYTE_FARMER_MAX"] = 30*1024*1024 # 30 MB

self.app.get('/api/contract/new/{0}'.format(addr))
self.app.get('/api/contract/new/{0}'.format(addr))
self.app.get('/api/contract/new/{0}'.format(addr))

rv = self.app.get('/api/contract/list/{0}'.format(addr))
self.assertEqual(rv.status_code, 200)

def test_list_contract_no_register(self):
addr = '191GVvAaTRxLmz3rW3nU5jAV1rF186VxQc'
rv = self.app.get('/api/contract/list/{0}'.format(addr))
self.assertEqual(rv.status_code, 404)

def test_list_contract_no_bad_address(self):
addr = 'notvalidaddress'
rv = self.app.get('/api/contract/list/{0}'.format(addr))
self.assertEqual(rv.status_code, 400)

def test_farmer_set_height(self):
addr1 = '191GVvAaTRxLmz3rW3nU5jAV1rF186VxQc'
addr2 = 'notvalidaddress'
Expand Down
Loading

0 comments on commit cc11b43

Please sign in to comment.