diff options
Diffstat (limited to 'lib/CryptoCoins.hs')
-rw-r--r-- | lib/CryptoCoins.hs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/CryptoCoins.hs b/lib/CryptoCoins.hs new file mode 100644 index 0000000..f417036 --- /dev/null +++ b/lib/CryptoCoins.hs | |||
@@ -0,0 +1,70 @@ | |||
1 | {-# LANGUAGE ViewPatterns #-} | ||
2 | module CryptoCoins where | ||
3 | |||
4 | import Numeric | ||
5 | import Data.Word | ||
6 | import Data.Maybe | ||
7 | |||
8 | data CoinNetwork = CoinNetwork | ||
9 | { network_name :: String | ||
10 | , public_byte_id :: Word8 | ||
11 | , private_byte_id :: Word8 | ||
12 | , source_code_uri :: String | ||
13 | } | ||
14 | deriving (Show,Read) | ||
15 | |||
16 | -- For forks of bitcoin, grep sources for PUBKEY_ADDRESS | ||
17 | -- That value + 0x80 will be the private_byte_id. | ||
18 | -- information source: https://raw.github.com/zamgo/PHPCoinAddress/master/README.md | ||
19 | coin_networks :: [CoinNetwork] | ||
20 | coin_networks = | ||
21 | [ CoinNetwork "bitcoin" 0x00 0x80 "https://github.com/bitcoin/bitcoin" | ||
22 | , CoinNetwork "litecoin" 0x30 0xB0 "https://github.com/litecoin-project/litecoin" | ||
23 | , CoinNetwork "peercoin" 0x37 0xB7 "https://github.com/ppcoin/ppcoin" -- AKA: ppcoin | ||
24 | , CoinNetwork "namecoin" 0x34 0xB4 "https://github.com/namecoin/namecoin" | ||
25 | , CoinNetwork "bbqcoin" 0x05 0xD5 "https://github.com/overware/BBQCoin" | ||
26 | , CoinNetwork "bitbar" 0x19 0x99 "https://github.com/aLQ/bitbar" | ||
27 | , CoinNetwork "bytecoin" 0x12 0x80 "https://github.com/bryan-mills/bytecoin" | ||
28 | , CoinNetwork "chncoin" 0x1C 0x9C "https://github.com/CHNCoin/CHNCoin" | ||
29 | , CoinNetwork "devcoin" 0x00 0x80 "http://sourceforge.net/projects/galacticmilieu/files/DeVCoin" | ||
30 | , CoinNetwork "feathercoin" 0x0E 0x8E "https://github.com/FeatherCoin/FeatherCoin" | ||
31 | , CoinNetwork "freicoin" 0x00 0x80 "https://github.com/freicoin/freicoin" | ||
32 | , CoinNetwork "junkcoin" 0x10 0x90 "https://github.com/js2082/JKC" | ||
33 | , CoinNetwork "mincoin" 0x32 0xB2 "https://github.com/SandyCohen/mincoin" | ||
34 | , CoinNetwork "novacoin" 0x08 0x88 "https://github.com/CryptoManiac/novacoin" | ||
35 | , CoinNetwork "onecoin" 0x73 0xF3 "https://github.com/cre8r/onecoin" | ||
36 | , CoinNetwork "smallchange" 0x3E 0xBE "https://github.com/bfroemel/smallchange" | ||
37 | , CoinNetwork "terracoin" 0x00 0x80 "https://github.com/terracoin/terracoin" | ||
38 | , CoinNetwork "yacoin" 0x4D 0xCD "https://github.com/pocopoco/yacoin" | ||
39 | , CoinNetwork "bitcoin-t" 0x6F 0xEF "" | ||
40 | , CoinNetwork "bbqcoin-t" 0x19 0x99 "" | ||
41 | , CoinNetwork "bitbar-t" 0x73 0xF3 "" | ||
42 | ] | ||
43 | -- fairbrix - - https://github.com/coblee/Fairbrix | ||
44 | -- ixcoin - - https://github.com/ixcoin/ixcoin | ||
45 | -- royalcoin - - http://sourceforge.net/projects/royalcoin/ | ||
46 | |||
47 | lookupNetwork :: Eq a => (CoinNetwork -> a) -> a -> Maybe CoinNetwork | ||
48 | lookupNetwork f b = listToMaybe $ filter (\n->f n==b) coin_networks | ||
49 | |||
50 | nameFromSecretByte :: Word8 -> String | ||
51 | nameFromSecretByte b = maybe (defaultName b) network_name (lookupNetwork private_byte_id b) | ||
52 | where | ||
53 | defaultName b = "?coin?"++hexit b | ||
54 | where | ||
55 | hexit b = pad0 $ showHex b "" | ||
56 | where pad0 [c] = '0':c:[] | ||
57 | pad0 cs = take 2 cs | ||
58 | |||
59 | publicByteFromName :: String -> Word8 | ||
60 | publicByteFromName n = maybe (secretByteFromName n - 0x80) | ||
61 | -- exceptions to the above: bbqcoin, bytecoin | ||
62 | public_byte_id | ||
63 | (lookupNetwork network_name n) | ||
64 | |||
65 | secretByteFromName :: String -> Word8 | ||
66 | secretByteFromName n = maybe (defaultID n) private_byte_id (lookupNetwork network_name n) | ||
67 | where | ||
68 | defaultID ('?':'c':'o':'i':'n':'?':(readHex->((x,_):_))) | ||
69 | = x | ||
70 | defaultID _ = 0x00 | ||