From 0fec917b36d2d66e4dd8b5d62368b736d3749214 Mon Sep 17 00:00:00 2001 From: Giannis Dzegoutanis Date: Sun, 30 Nov 2014 17:33:32 +0100 Subject: [PATCH 1/8] Support X11 hash coins like Darkcoin --- src/blockchain_processor.py | 7 +++++-- src/utils.py | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/blockchain_processor.py b/src/blockchain_processor.py index 324c4973..20fb84d1 100644 --- a/src/blockchain_processor.py +++ b/src/blockchain_processor.py @@ -15,6 +15,8 @@ from storage import Storage from utils import logger +import traceback + class BlockchainProcessor(Processor): def __init__(self, config, shared): @@ -181,7 +183,7 @@ def init_headers(self, db_height): self.flush_headers() def hash_header(self, header): - return rev_hex(Hash(header_to_string(header).decode('hex')).encode('hex')) + return rev_hex(HashX11(header_to_string(header).decode('hex')).encode('hex')) def read_header(self, block_height): if os.path.exists(self.headers_filename): @@ -365,6 +367,7 @@ def deserialize_block(self, block): tx = deserialize.parse_Transaction(vds, is_coinbase) except: print_log("ERROR: cannot parse", tx_hash) + print_log(traceback.format_exc()) continue tx_hashes.append(tx_hash) txdict[tx_hash] = tx @@ -396,7 +399,7 @@ def import_block(self, block, block_hash, block_height, sync, revert=False): undo = undo_info.pop(txid) self.storage.revert_transaction(txid, tx, block_height, touched_addr, undo) - if revert: + if revert: assert undo_info == {} # add undo info diff --git a/src/utils.py b/src/utils.py index dd39e17f..6d44946c 100644 --- a/src/utils.py +++ b/src/utils.py @@ -20,6 +20,7 @@ import time import hashlib import sys +import x11_hash __b58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' __b58base = len(__b58chars) @@ -51,7 +52,7 @@ def var_int(i): Hash = lambda x: hashlib.sha256(hashlib.sha256(x).digest()).digest() - +HashX11 = lambda x: x11_hash.getPoWHash(x) hash_encode = lambda x: x[::-1].encode('hex') From 5a28aeb5debd299f001a2c7074be26caf0244437 Mon Sep 17 00:00:00 2001 From: Giannis Dzegoutanis Date: Sun, 30 Nov 2014 18:41:22 +0100 Subject: [PATCH 2/8] peercoin family coins support --- src/blockchain_processor.py | 5 +++-- src/deserialize.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/blockchain_processor.py b/src/blockchain_processor.py index 324c4973..f6c7e6cb 100644 --- a/src/blockchain_processor.py +++ b/src/blockchain_processor.py @@ -8,7 +8,8 @@ import time import threading import urllib - +from calendar import timegm +from time import strptime import deserialize from processor import Processor, print_log from utils import * @@ -129,7 +130,7 @@ def block2header(self, b): "version": b.get('version'), "prev_block_hash": b.get('previousblockhash'), "merkle_root": b.get('merkleroot'), - "timestamp": b.get('time'), + "timestamp": timegm(strptime(b.get('time'), "%Y-%m-%d %H:%M:%S %Z")), "bits": int(b.get('bits'), 16), "nonce": b.get('nonce'), } diff --git a/src/deserialize.py b/src/deserialize.py index 8bf0ca06..d5a9617f 100644 --- a/src/deserialize.py +++ b/src/deserialize.py @@ -244,6 +244,7 @@ def parse_Transaction(vds, is_coinbase): d = {} start = vds.read_cursor d['version'] = vds.read_int32() + d['time'] = vds.read_int32() n_vin = vds.read_compact_size() d['inputs'] = [] for i in xrange(n_vin): From c09d6f1eaa4ed24841af1cea8773b4b685855233 Mon Sep 17 00:00:00 2001 From: Leigh Phillips Date: Wed, 15 Jun 2016 22:27:13 +0000 Subject: [PATCH 3/8] Fix merge. --- src/blockchain_processor.py | 6 +----- src/utils.py | 3 --- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/blockchain_processor.py b/src/blockchain_processor.py index a4bbbe47..07152ee6 100644 --- a/src/blockchain_processor.py +++ b/src/blockchain_processor.py @@ -232,14 +232,10 @@ def init_headers(self, db_height): self.flush_headers() -<<<<<<< HEAD @staticmethod - def hash_header(header): - return rev_hex(Hash(header_to_string(header).decode('hex')).encode('hex')) -======= def hash_header(self, header): +# return rev_hex(Hash(header_to_string(header).decode('hex')).encode('hex')) return rev_hex(HashX11(header_to_string(header).decode('hex')).encode('hex')) ->>>>>>> x11hash def read_header(self, block_height): if os.path.exists(self.headers_filename): diff --git a/src/utils.py b/src/utils.py index 6b2cf22b..573782a9 100644 --- a/src/utils.py +++ b/src/utils.py @@ -25,12 +25,9 @@ import threading import time import hashlib -<<<<<<< HEAD import struct -======= import sys import x11_hash ->>>>>>> x11hash __b58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' __b58base = len(__b58chars) From dc9d201f616de2a2d3d1104e06cc764495c91741 Mon Sep 17 00:00:00 2001 From: Leigh Phillips Date: Thu, 16 Jun 2016 22:02:36 +0000 Subject: [PATCH 4/8] Define Piggycoin parameters. --- electrum.conf.sample | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/electrum.conf.sample b/electrum.conf.sample index 23c73670..010f6969 100644 --- a/electrum.conf.sample +++ b/electrum.conf.sample @@ -20,6 +20,11 @@ banner_file = /etc/electrum.banner logfile = /var/log/electrum.log donation_address = +[network] +pubkey_address = 118 +script_address = 28 +genesis_hash = 00000561d6f5f76b0c101ba6bac27ad99a18fc8927c6af844adfd913097e9271 + [leveldb] # path to your database path = @@ -34,7 +39,7 @@ pruning_limit = 100 [bitcoind] bitcoind_host = localhost -bitcoind_port = 8332 +bitcoind_port = 54480 # user and password from bitcoin.conf -bitcoind_user = -bitcoind_password = +bitcoind_user = piggycoinrpc +bitcoind_password = Testing123 From 28f1407eb0aea73e704194d99c75ef3fd23d0510 Mon Sep 17 00:00:00 2001 From: Leigh Phillips Date: Fri, 17 Jun 2016 04:13:31 +0000 Subject: [PATCH 5/8] Fix x11_hash errors. --- src/blockchain_processor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/blockchain_processor.py b/src/blockchain_processor.py index 07152ee6..f71c274e 100644 --- a/src/blockchain_processor.py +++ b/src/blockchain_processor.py @@ -35,7 +35,7 @@ import deserialize from processor import Processor, print_log from storage import Storage -from utils import logger, hash_decode, hash_encode, Hash, header_from_string, header_to_string, ProfiledThread, \ +from utils import logger, hash_decode, hash_encode, Hash, HashX11, header_from_string, header_to_string, ProfiledThread, \ rev_hex, int_to_hex4 import traceback @@ -233,7 +233,7 @@ def init_headers(self, db_height): self.flush_headers() @staticmethod - def hash_header(self, header): + def hash_header(header): # return rev_hex(Hash(header_to_string(header).decode('hex')).encode('hex')) return rev_hex(HashX11(header_to_string(header).decode('hex')).encode('hex')) From 10aacfed4dd3f7cdfdc95be734155b697ab21cb7 Mon Sep 17 00:00:00 2001 From: Leigh Phillips Date: Fri, 17 Jun 2016 04:14:45 +0000 Subject: [PATCH 6/8] Fix peercoin error (datetimestamp processing) --- src/blockchain_processor.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/blockchain_processor.py b/src/blockchain_processor.py index f71c274e..72fc65de 100644 --- a/src/blockchain_processor.py +++ b/src/blockchain_processor.py @@ -30,8 +30,9 @@ import time import threading import urllib -from calendar import timegm -from time import strptime +#from calendar import timegm +#from time import strptime +#from datetime import datetime import deserialize from processor import Processor, print_log from storage import Storage @@ -182,7 +183,8 @@ def block2header(b): "version": b.get('version'), "prev_block_hash": b.get('previousblockhash'), "merkle_root": b.get('merkleroot'), - "timestamp": timegm(strptime(b.get('time'), "%Y-%m-%d %H:%M:%S %Z")), +# "timestamp": timegm(strptime(datetime.fromtimestamp(b.get('time')), "%Y-%m-%d %H:%M:%S %Z")), + "timestamp": b.get('time'), "bits": int(b.get('bits'), 16), "nonce": b.get('nonce'), } From e0666c48aa7b53a3e3b0c90ec8146a52b3586a65 Mon Sep 17 00:00:00 2001 From: Leigh Phillips Date: Thu, 23 Jun 2016 02:33:06 +0000 Subject: [PATCH 7/8] Update conf.sample --- electrum.conf.sample | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/electrum.conf.sample b/electrum.conf.sample index 010f6969..ea7b3f7e 100644 --- a/electrum.conf.sample +++ b/electrum.conf.sample @@ -2,7 +2,7 @@ # username for running the daemon username = # hostname. set it to a FQDN in order to be reached from outside -host = localhost +host = 0.0.0.0 # ports electrum_rpc_port = 8000 stratum_tcp_port = 50001 @@ -10,7 +10,7 @@ stratum_tcp_port = 50001 #report_host = #report_stratum_tcp_port = 50001 #report_stratum_tcp_ssl_port = 50002 -banner = Welcome to Electrum! +banner = Welcome to PiggyElectrum! banner_file = /etc/electrum.banner #irc = no #irc_nick = From 4a59693425eec4324bb958c94993f71d4d342300 Mon Sep 17 00:00:00 2001 From: Leigh Phillips Date: Thu, 23 Jun 2016 04:22:41 +0000 Subject: [PATCH 8/8] Update conf.sample & genesis pub/scriptkeys --- .gitignore | 3 ++- electrum.conf.sample | 1 + src/networks.py | 15 +++++---------- src/storage.py | 2 +- src/utils.py | 6 +++--- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index c9399a41..0e4d82bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ +db/* +*.log *.pyc *.so *.o -.gitignore electrum.conf diff --git a/electrum.conf.sample b/electrum.conf.sample index ea7b3f7e..d52a130e 100644 --- a/electrum.conf.sample +++ b/electrum.conf.sample @@ -21,6 +21,7 @@ logfile = /var/log/electrum.log donation_address = [network] +type = piggycoin_main pubkey_address = 118 script_address = 28 genesis_hash = 00000561d6f5f76b0c101ba6bac27ad99a18fc8927c6af844adfd913097e9271 diff --git a/src/networks.py b/src/networks.py index 5142c63c..418556df 100644 --- a/src/networks.py +++ b/src/networks.py @@ -1,14 +1,9 @@ -# Main network and testnet3 definitions +# Main network definition params = { - 'bitcoin_main': { - 'pubkey_address': 0, - 'script_address': 5, - 'genesis_hash': '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f' + 'piggycoin_main': { + 'pubkey_address': 118, + 'script_address': 28, + 'genesis_hash': '00000561d6f5f76b0c101ba6bac27ad99a18fc8927c6af844adfd913097e9271' }, - 'bitcoin_test': { - 'pubkey_address': 111, - 'script_address': 196, - 'genesis_hash': '000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943' - } } diff --git a/src/storage.py b/src/storage.py index 1e6a1d5b..81be2ae5 100644 --- a/src/storage.py +++ b/src/storage.py @@ -41,7 +41,7 @@ # increase this when database needs to be updated global GENESIS_HASH -GENESIS_HASH = '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f' +GENESIS_HASH = '00000561d6f5f76b0c101ba6bac27ad99a18fc8927c6af844adfd913097e9271' DB_VERSION = 3 KEYLENGTH = 56 # 20 + 32 + 4 diff --git a/src/utils.py b/src/utils.py index 573782a9..909893df 100644 --- a/src/utils.py +++ b/src/utils.py @@ -34,8 +34,8 @@ global PUBKEY_ADDRESS global SCRIPT_ADDRESS -PUBKEY_ADDRESS = 0 -SCRIPT_ADDRESS = 5 +PUBKEY_ADDRESS = 118 +SCRIPT_ADDRESS = 28 def rev_hex(s): return s.decode('hex')[::-1].encode('hex') @@ -137,7 +137,7 @@ def hash_160_to_script_address(h160): return hash_160_to_address(h160, SCRIPT_ADDRESS) -def hash_160_to_address(h160, addrtype = 0): +def hash_160_to_address(h160, addrtype = 118): """ Checks if the provided hash is actually 160bits or 20 bytes long and returns the address, else None """ if h160 is None or len(h160) is not 20: