summaryrefslogtreecommitdiff
path: root/lib/CryptoCoins.hs
blob: f417036b71bc1581c9ba5579278e419558517550 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
{-# LANGUAGE ViewPatterns #-}
module CryptoCoins where

import Numeric
import Data.Word
import Data.Maybe

data CoinNetwork = CoinNetwork
    { network_name :: String
    , public_byte_id :: Word8
    , private_byte_id :: Word8
    , source_code_uri :: String
    }
 deriving (Show,Read)

-- For forks of bitcoin, grep sources for PUBKEY_ADDRESS
-- That value + 0x80 will be the private_byte_id.
-- information source: https://raw.github.com/zamgo/PHPCoinAddress/master/README.md
coin_networks :: [CoinNetwork]
coin_networks =
   [ CoinNetwork "bitcoin"        0x00 0x80 "https://github.com/bitcoin/bitcoin"
   , CoinNetwork "litecoin"       0x30 0xB0 "https://github.com/litecoin-project/litecoin"
   , CoinNetwork "peercoin"       0x37 0xB7 "https://github.com/ppcoin/ppcoin" -- AKA: ppcoin
   , CoinNetwork "namecoin"       0x34 0xB4 "https://github.com/namecoin/namecoin"
   , CoinNetwork "bbqcoin"        0x05 0xD5 "https://github.com/overware/BBQCoin"
   , CoinNetwork "bitbar"         0x19 0x99 "https://github.com/aLQ/bitbar"
   , CoinNetwork "bytecoin"       0x12 0x80 "https://github.com/bryan-mills/bytecoin"
   , CoinNetwork "chncoin"        0x1C 0x9C "https://github.com/CHNCoin/CHNCoin"
   , CoinNetwork "devcoin"        0x00 0x80 "http://sourceforge.net/projects/galacticmilieu/files/DeVCoin"
   , CoinNetwork "feathercoin"    0x0E 0x8E "https://github.com/FeatherCoin/FeatherCoin"
   , CoinNetwork "freicoin"       0x00 0x80 "https://github.com/freicoin/freicoin"
   , CoinNetwork "junkcoin"       0x10 0x90 "https://github.com/js2082/JKC"
   , CoinNetwork "mincoin"        0x32 0xB2 "https://github.com/SandyCohen/mincoin"
   , CoinNetwork "novacoin"       0x08 0x88 "https://github.com/CryptoManiac/novacoin"
   , CoinNetwork "onecoin"        0x73 0xF3 "https://github.com/cre8r/onecoin"
   , CoinNetwork "smallchange"    0x3E 0xBE "https://github.com/bfroemel/smallchange"
   , CoinNetwork "terracoin"      0x00 0x80 "https://github.com/terracoin/terracoin"
   , CoinNetwork "yacoin"         0x4D 0xCD "https://github.com/pocopoco/yacoin"
   , CoinNetwork "bitcoin-t"      0x6F 0xEF ""
   , CoinNetwork "bbqcoin-t"      0x19 0x99 ""
   , CoinNetwork "bitbar-t"       0x73 0xF3 ""
   ]
   -- fairbrix          -    - https://github.com/coblee/Fairbrix
   -- ixcoin            -    - https://github.com/ixcoin/ixcoin
   -- royalcoin         -    - http://sourceforge.net/projects/royalcoin/

lookupNetwork :: Eq a => (CoinNetwork -> a) -> a -> Maybe CoinNetwork
lookupNetwork f b = listToMaybe $ filter (\n->f n==b) coin_networks

nameFromSecretByte :: Word8 -> String
nameFromSecretByte b = maybe (defaultName b) network_name (lookupNetwork private_byte_id b)
 where
    defaultName b = "?coin?"++hexit b
      where
        hexit b = pad0 $ showHex b "" 
            where pad0 [c] = '0':c:[]
                  pad0 cs  = take 2 cs

publicByteFromName :: String -> Word8
publicByteFromName n = maybe (secretByteFromName n - 0x80) 
                             -- exceptions to the above: bbqcoin, bytecoin
                             public_byte_id
                             (lookupNetwork network_name n)

secretByteFromName :: String -> Word8
secretByteFromName n = maybe (defaultID n) private_byte_id (lookupNetwork network_name n)
 where
    defaultID ('?':'c':'o':'i':'n':'?':(readHex->((x,_):_))) 
                = x
    defaultID _ = 0x00