Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 7157d06

Browse files
committed
Audit protocol actions
1 parent f14ca27 commit 7157d06

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

market/protocol.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from interfaces import MessageProcessor, BroadcastListener, MessageListener, NotificationListener
1111
from keys.bip32utils import derive_childkey
1212
from log import Logger
13+
from market.audit import Audit
1314
from market.contracts import Contract
1415
from market.moderation import process_dispute, close_dispute
1516
from market.profile import Profile
@@ -33,6 +34,7 @@ def __init__(self, node, router, signing_key, database):
3334
self.node = node
3435
RPCProtocol.__init__(self, node, router)
3536
self.log = Logger(system=self)
37+
self.audit = Audit(db=database)
3638
self.multiplexer = None
3739
self.db = database
3840
self.signing_key = signing_key
@@ -50,6 +52,7 @@ def add_listener(self, listener):
5052

5153
def rpc_get_contract(self, sender, contract_hash):
5254
self.log.info("serving contract %s to %s" % (contract_hash.encode('hex'), sender))
55+
self.audit.record(sender.id.encode("hex"), "GET_CONTRACT", contract_hash.encode('hex'))
5356
self.router.addContact(sender)
5457
try:
5558
with open(self.db.filemap.get_file(contract_hash.encode("hex")), "r") as filename:
@@ -75,6 +78,7 @@ def rpc_get_image(self, sender, image_hash):
7578

7679
def rpc_get_profile(self, sender):
7780
self.log.info("serving profile to %s" % sender)
81+
self.audit.record(sender.id.encode("hex"), "GET_PROFILE")
7882
self.router.addContact(sender)
7983
try:
8084
proto = Profile(self.db).get(True)
@@ -101,6 +105,7 @@ def rpc_get_user_metadata(self, sender):
101105

102106
def rpc_get_listings(self, sender):
103107
self.log.info("serving store listings to %s" % sender)
108+
self.audit.record(sender.id.encode("hex"), "GET_LISTINGS")
104109
self.router.addContact(sender)
105110
try:
106111
p = Profile(self.db).get()
@@ -186,6 +191,7 @@ def rpc_unfollow(self, sender, signature):
186191

187192
def rpc_get_followers(self, sender, start=None):
188193
self.log.info("serving followers list to %s" % sender)
194+
self.audit.record(sender.id.encode("hex"), "GET_FOLLOWERS")
189195
self.router.addContact(sender)
190196
if start is not None:
191197
ser = self.db.follow.get_followers(int(start))
@@ -195,6 +201,7 @@ def rpc_get_followers(self, sender, start=None):
195201

196202
def rpc_get_following(self, sender):
197203
self.log.info("serving following list to %s" % sender)
204+
self.audit.record(sender.id.encode("hex"), "GET_FOLLOWING")
198205
self.router.addContact(sender)
199206
ser = self.db.follow.get_following()
200207
if ser is None:
@@ -346,6 +353,7 @@ def rpc_dispute_close(self, sender, pubkey, encrypted):
346353
def rpc_get_ratings(self, sender, listing_hash=None):
347354
a = "ALL" if listing_hash is None else listing_hash.encode("hex")
348355
self.log.info("serving ratings for contract %s to %s" % (a, sender))
356+
self.audit.record(sender.id.encode("hex"), "GET_RATINGS", listing_hash.encode("hex"))
349357
self.router.addContact(sender)
350358
try:
351359
ratings = []

0 commit comments

Comments
 (0)