Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
db/*
*.log
*.pyc
*.so
*.o
.gitignore
electrum.conf
16 changes: 11 additions & 5 deletions electrum.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# 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
#stratum_tcp_ssl_port = 50002
#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 = <yournickname>
Expand All @@ -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 =
Expand All @@ -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
15 changes: 11 additions & 4 deletions src/blockchain_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/deserialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 5 additions & 10 deletions src/networks.py
Original file line number Diff line number Diff line change
@@ -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'
}
}
2 changes: 1 addition & 1 deletion src/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 6 additions & 4 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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:
Expand Down