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 23c73670..d52a130e 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 = @@ -20,6 +20,12 @@ banner_file = /etc/electrum.banner logfile = /var/log/electrum.log donation_address = +[network] +type = piggycoin_main +pubkey_address = 118 +script_address = 28 +genesis_hash = 00000561d6f5f76b0c101ba6bac27ad99a18fc8927c6af844adfd913097e9271 + [leveldb] # path to your database path = @@ -34,7 +40,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 diff --git a/src/blockchain_processor.py b/src/blockchain_processor.py index 284f9759..72fc65de 100644 --- a/src/blockchain_processor.py +++ b/src/blockchain_processor.py @@ -30,13 +30,17 @@ import time import threading import urllib - +#from calendar import timegm +#from time import strptime +#from datetime import datetime 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 + class BlockchainProcessor(Processor): def __init__(self, config, shared): @@ -179,6 +183,7 @@ def block2header(b): "version": b.get('version'), "prev_block_hash": b.get('previousblockhash'), "merkle_root": b.get('merkleroot'), +# "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'), @@ -231,7 +236,8 @@ def init_headers(self, db_height): @staticmethod def hash_header(header): - return rev_hex(Hash(header_to_string(header).decode('hex')).encode('hex')) +# 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): @@ -393,6 +399,7 @@ def deserialize_block(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 @@ -424,7 +431,7 @@ def import_block(self, block, block_hash, block_height, 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/deserialize.py b/src/deserialize.py index ccc4eaa7..410ddb48 100644 --- a/src/deserialize.py +++ b/src/deserialize.py @@ -233,6 +233,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): 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 8d81a69e..909893df 100644 --- a/src/utils.py +++ b/src/utils.py @@ -26,21 +26,23 @@ import time import hashlib import struct +import sys +import x11_hash __b58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' __b58base = len(__b58chars) 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') 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') @@ -135,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: