Skip to content

Commit

Permalink
Add Groestlcoin and change hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kefkius committed May 23, 2017
1 parent 3f89c80 commit b7345bf
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
26 changes: 25 additions & 1 deletion lib/coins.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from hashlib import sha256

import lib.util as util
from lib.hash import Base58, hash160, double_sha256, hash_to_str
from lib.hash import Base58, hash160, double_sha256, hash_to_str, groestlHash
from lib.script import ScriptPubKey
from lib.tx import Deserializer, DeserializerSegWit, DeserializerAuxPow, DeserializerZcash

Expand Down Expand Up @@ -311,6 +311,30 @@ def block_header(cls, block, height):
return block.read_header(height, cls.BASIC_HEADER_SIZE)


class Groestlcoin(Coin):
NAME = "Groestlcoin"
SHORTNAME = "GRS"
NET = "mainnet"
XPUB_VERBYTES = bytes.fromhex("0488b21e")
XPRV_VERBYTES = bytes.fromhex("0488ade4")
GENESIS_HASH = ('00000ac5927c594d49cc0bdb81759d0d'
'a8297eb614683d3acb62f0703b639023')
P2PKH_VERBYTE = bytes.fromhex("24")
P2SH_VERBYTE = bytes.fromhex("05")
WIF_BYTE = bytes.fromhex("80")

TX_COUNT = 1000000
TX_COUNT_HEIGHT = 1000000
TX_PER_BLOCK = 10

IRC_PREFIX = "E-grs_"
IRC_CHANNEL = "#Groestlcoin"

@classmethod
def header_hash(cls, header):
'''Given a header return the hash.'''
return groestlHash(header)

class Bitcoin(Coin):
NAME = "Bitcoin"
SHORTNAME = "BTC"
Expand Down
8 changes: 6 additions & 2 deletions lib/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@

import hashlib
import hmac
import groestlcoin_hash

from lib.util import bytes_to_int, int_to_bytes


def groestlHash(x):
return groestlcoin_hash.getHash(x, len(x))

def sha256(x):
'''Simple wrapper of hashlib sha256.'''
assert isinstance(x, (bytes, bytearray, memoryview))
Expand Down Expand Up @@ -143,7 +147,7 @@ def decode_check(txt):
prefixes it.'''
be_bytes = Base58.decode(txt)
result, check = be_bytes[:-4], be_bytes[-4:]
if check != double_sha256(result)[:4]:
if check != groestlHash(result)[:4]:
raise Base58Error('invalid base 58 checksum for {}'.format(txt))
return result

Expand All @@ -153,5 +157,5 @@ def encode_check(payload):
into a Base58Check string."""
assert isinstance(payload, (bytes, bytearray, memoryview))

be_bytes = payload + double_sha256(payload)[:4]
be_bytes = payload + groestlHash(payload)[:4]
return Base58.encode(be_bytes)
6 changes: 3 additions & 3 deletions lib/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from struct import unpack_from

from lib.util import cachedproperty
from lib.hash import double_sha256, hash_to_str
from lib.hash import sha256, double_sha256, hash_to_str


class Tx(namedtuple("Tx", "version inputs outputs locktime")):
Expand Down Expand Up @@ -104,7 +104,7 @@ def read_tx(self):
self._read_inputs(), # inputs
self._read_outputs(), # outputs
self._read_le_uint32() # locktime
), double_sha256(self.binary[start:self.cursor])
), sha256(self.binary[start:self.cursor])

def read_tx_block(self):
'''Returns a list of (deserialized_tx, tx_hash) pairs.'''
Expand Down Expand Up @@ -237,7 +237,7 @@ def read_tx(self):
orig_ser += self.binary[start:self.cursor]

return TxSegWit(version, marker, flag, inputs,
outputs, witness, locktime), double_sha256(orig_ser)
outputs, witness, locktime), sha256(orig_ser)


class DeserializerAuxPow(Deserializer):
Expand Down
16 changes: 3 additions & 13 deletions tests/lib/test_addresses.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,12 @@

import pytest

from lib.coins import Litecoin, Bitcoin, Zcash
from lib.coins import Litecoin, Bitcoin, Groestlcoin
from lib.hash import Base58

addresses = [
(Bitcoin, "13xDKJbjh4acmLpNVr6Lc9hFcXRr9fyt4x",
"206168f5322583ff37f8e55665a4789ae8963532", "b8cb80b26e8932f5b12a7e"),
(Bitcoin, "3GxRZWkJufR5XA8hnNJgQ2gkASSheoBcmW",
"a773db925b09add367dcc253c1f9bbc1d11ec6fd", "062d8515e50cb92b8a3a73"),
(Litecoin, "LNBAaWuZmipg29WXfz5dtAm1pjo8FEH8yg",
"206168f5322583ff37f8e55665a4789ae8963532", "b8cb80b26e8932f5b12a7e"),
(Litecoin, "3GxRZWkJufR5XA8hnNJgQ2gkASSheoBcmW",
"a773db925b09add367dcc253c1f9bbc1d11ec6fd", "062d8515e50cb92b8a3a73"),
(Zcash, "t1LppKe1sfPNDMysGSGuTjxoAsBcvvSYv5j",
"206168f5322583ff37f8e55665a4789ae8963532", "b8cb80b26e8932f5b12a7e"),
(Zcash, "t3Zq2ZrASszCg7oBbio7oXqnfR6dnSWqo76",
"a773db925b09add367dcc253c1f9bbc1d11ec6fd", "062d8515e50cb92b8a3a73"),
(Groestlcoin, "FY7vmDL7FZGACwqVNx5p4fVaGghojWM5AF",
"206168f5322583ff37f8e55665a4789ae8963532", "b8cb80b26e8932f5b12a7e"),
]


Expand Down

0 comments on commit b7345bf

Please sign in to comment.