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