Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Show OTC links if they have an OTC account

  • Loading branch information...
commit 0b9f029ef9932819bd0ddb93b42904a2f36c2421 1 parent c5f828e
@singpolyma authored
View
9 Application.hs
@@ -29,6 +29,7 @@ import qualified Data.ByteString as BS
import Records
import MustacheTemplates
import Sqlite3
+import OTC
#include "PathHelpers.hs"
-- Orphan instances, do not import this module!
@@ -70,13 +71,17 @@ reportFor _ db adr req = case gen of
string ok200 disp (show time ++ ": " ++ show adr ++ " " ++ T.unpack x ++ "\n")
Nothing -> do
assertions <- liftIO $ query db (fromString "SELECT `from`, `fromFingerprint`, `to`, `at`, `asserted`, `assertion` FROM assertions WHERE `to` = ?") [adr]
+ otc <- liftIO $ otcKeys
+ let assertions' = map (\x -> x {otcNick = lookup (fFpr x) otc}) assertions
handleAcceptTypes [
("text/html",
- return $ responseTextBuilder ok200 headers (viewReport htmlEscape $ Report adr assertions)),
+ return $ responseTextBuilder ok200 headers (viewReport htmlEscape $ Report adr assertions')),
("application/json",
- json ok200 [] (Report adr assertions))
+ json ok200 [] (Report adr assertions'))
] req
where
+ fFpr (FormattedAssertionRow { row = [AssertionRow {fromFingerprint = fpr}] }) = fpr
+ fFpr _ = ""
gen = fmap (T.decodeUtf8 . fromMaybe BS.empty) $ lookup (fromString "newAssertion") (queryString req)
Just disp = stringHeaders [("Content-Disposition", "attachment; filename=assertion.txt")]
Just headers = stringHeaders [("Content-Type", "text/html; charset=utf8")]
View
32 OTC.hs
@@ -0,0 +1,32 @@
+module OTC where
+
+import Control.Applicative ((<$>), (<*>))
+import Data.Maybe (fromMaybe, mapMaybe)
+import qualified Network.HTTP as HTTP
+import qualified Data.Aeson as Aeson
+import qualified Data.Text as T
+import qualified Data.ByteString.Lazy as LZ
+
+data OTCKey = OTCKey String String deriving (Eq, Show)
+
+instance Aeson.FromJSON OTCKey where
+ parseJSON (Aeson.Object o) = OTCKey <$>
+ (fromMaybe "" <$> (Aeson..:?) o (T.pack "fingerprint")) <*>
+ (fromMaybe "" <$> (Aeson..:?) o (T.pack "nick"))
+ parseJSON _ = fail "OTCKey is always a JSON object"
+
+otcKeyToTuple :: OTCKey -> Maybe (String, String)
+otcKeyToTuple (OTCKey "" _) = Nothing
+otcKeyToTuple (OTCKey fpr nick) = Just (fpr, nick)
+
+otcKeys :: IO [(String, String)]
+otcKeys = do
+ r <- HTTP.simpleHTTP req
+ -- XXX: Data is all ASCII, but this is still a terrible hack
+ let rbytes = LZ.pack . map (toEnum.fromEnum) . HTTP.rspBody <$> r
+ case rbytes of
+ Left _ -> return []
+ Right x ->
+ return $ mapMaybe otcKeyToTuple $ fromMaybe [] (Aeson.decode x)
+ where
+ req = HTTP.getRequest "http://bitcoin-otc.com/viewgpg.php?outformat=json"
View
3  Records.hs
@@ -61,6 +61,7 @@ data FormattedAssertionRow = FormattedAssertionRow {
atHuman :: String,
keyId :: String,
signedAssertion :: String,
+ otcNick :: Maybe String,
row :: [AssertionRow]
}
deriving (Show, Eq)
@@ -70,7 +71,7 @@ instance Aeson.ToJSON FormattedAssertionRow where
formatAssertionRow :: AssertionRow -> FormattedAssertionRow
formatAssertionRow row =
- FormattedAssertionRow iso8601 human keyId signed [row]
+ FormattedAssertionRow iso8601 human keyId signed Nothing [row]
where
signed = map (toEnum.fromEnum) $ LZ.unpack $ B64.encode $ encode $ assertion row
keyId = reverse $ take 8 $ reverse $ fromFingerprint row
View
14 view/home.mustache
@@ -9,6 +9,13 @@
<body>
<h1><img src="/assets/logo.png" alt="Ripple Union" /> Credit Reports</h1>
+ {{#forForm}}
+ <form method="get" action="{{formAction}}">
+ <input type="text" name="address" placeholder="Ripple.com address" />
+ <input type="submit" value="View Report" />
+ </form>
+ {{/forForm}}
+
<p>This credit reporting system is designed to give support to Ripple.com organizations and users who want to extend credit to other users. Every time a user to whom you have extended credit makes a payment on that credit, you may submit an OpenPGP signed message saying:</p>
<blockquote>&lt;unix timestamp of transaction&gt;: &lt;Ripple.com address of user&gt; made a payment</blockquote>
@@ -21,11 +28,6 @@
<p><strong>Do not blindly trust assertions</strong>. Verify the identity of the key that made the assertion. Do you trust this person or organization? If you don't know who it is, ask around in the community. If you want to tie your OpenPGP key to your community identity, you might consider <a href="https://ripple.com/forum/viewtopic.php?f=1&amp;t=1617">this forum thread</a>.</p>
- {{#forForm}}
- <form method="get" action="{{formAction}}">
- <input type="text" name="address" placeholder="Ripple.com address" />
- <input type="submit" value="View Report" />
- </form>
- {{/forForm}}
+ <p>Do you accept payments through an automated system? Want an API? No problem. Request JSON or JSONP from a report page to get a machine-readable report. Put a signed assertion in the body of a POST to any report URI to add an assertion to that URI, errors can be returned as text or JSON.</p>
</body>
</html>
View
3  view/report.mustache
@@ -23,6 +23,9 @@
<time datetime="{{at8601}}">{{atHuman}}</time> —
<a href="http://singpolyma.net:11371/pks/lookup?op=vindex&amp;search=0x{{#row}}{{fromFingerprint}}{{/row}}">{{keyId}}</a>
+ {{#otcNick}}
+ [<a href="http://bitcoin-otc.com/viewratingdetail.php?nick={{otcNick}}&amp;sign=ANY&amp;type=RECV">otc</a>]
+ {{/otcNick}}
asserted that this address
{{#row}}
{{asserted}}
Please sign in to comment.
Something went wrong with that request. Please try again.