forked from jplewicke/rivulet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.rb
57 lines (46 loc) · 1.36 KB
/
parse.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require "neo_classes"
require "json"
# All OpenTransact asset manipulation functions should include the following fields:
# to = a valid user identifier
# amount = a numeric amount of an asset to transfer
# They can also include a memo field, which is a string giving the reason for a
# transaction.
def parses!(params)
if params["to"] == nil
throw(:halt, [400, "\"to\" field required by OpenTransact protocol.\n"])
end
if params["amount"] == nil
throw(:halt, [400, "\"amount\" field required by OpenTransact protocol.\n"])
end
unless numeric?(params["amount"])
throw(:halt, [400, "\"amount\" field must be a number in OpenTransact.\n"])
end
unless Float(params["amount"]) > 0.0
throw(:halt, [400, "\"amount\" field must be greater than 0 in OpenTransact.\n"])
end
params["amount"] = Float(params["amount"])
end
def get_neo_users(source_id, dest_id)
#One cannot grant credit to oneself.
if source_id == dest_id
throw(:halt, [400, "Cannot grant credit to oneself.\n"])
end
source = User.fromid(source_id)
dest = User.fromid(dest_id)
if (source == nil || dest == nil)
throw(:halt, [400, "Error finding user in Neo4j.\n"])
end
return [source, dest]
end
def numeric?(str)
true if Float(str) rescue false
end
def posinteger?(str)
if Integer(str) > 0
true
else
false
end
rescue
false
end