Beispiel #1
0
def init_chain():
    db = LevelDB("./chain")
    env = Env(db)
    return ChainService(env)
Beispiel #2
0
from chain_service import ChainService
import transactions
import db


service = ChainService()

transact = []
transact.append(transactions.Transaction(1, '', "192.168.9.1/28", 0, 'data', 1, 1, 1)) #to be serializable, address can be empty and
transact.append(transactions.Transaction(2, '', "192.170.9.1/28", 0, 'data', 1, 1, 1)) #v, r, s have to be integers
transact.append(transactions.Transaction(3, '', "192.172.9.1/28", 0, 'data', 1, 1, 1))


for i in range (0, len(transact)):
    service.add_transaction(transact[i])


#print('add_block')
service.add_block()

print('checking if exists block 0')
if service.get_block_in_position_i(0) is not None:
    print ('exists')
else:
    print ('not exists')

print('checking if exists block 1')
if service.get_block_in_position_i(1) is not None:
    print ('exists')
else:
    print ('not exists')
Beispiel #3
0
import sys
sys.path.append("/home/blockchain/blockchain")
sys.path.append("/home/blockchain/blockchain/Tests")
from db import LevelDB
from config import Env
from chain_service import ChainService

db = LevelDB("./chain")
env = Env(db)

chain = ChainService(env)
head_block = chain.get_head_block().header.number
print(chain.get_head_block().header.prevhash.encode("HEX"))
print(head_block)

for i in range(0,head_block+1):
    block = chain.get_block_by_number(i)
    print ("Asking for block number " + str(i))
    print ("Received block number " + str(block.header.number))
    print ("Received block hash " + str(block.hash.encode("HEX")))
    print ("Received prevhash " + str(block.header.prevhash.encode("HEX")))
Beispiel #4
0
tx3 = Transaction(0, 1, add1, 1, '192.152.0.0/24')
tx3.sign(ks3.privkey)
tx4 = Transaction(1, 1, add2, 1, '192.152.0.0/25')
tx4.sign(ks3.privkey)
tx5 = Transaction(2, 0, add1, 1, '192.152.0.0/26')
tx5.sign(ks3.privkey)
tx6 = Transaction(3, 3, add3, 1, '192.152.0.0/16',[2, '2001:cdba:9abc:5678::', 20, 230,1, '5.5.5.5', 45, 50])
tx6.sign(ks3.privkey)
tx7 = Transaction(1, 2, add3, 1, '192.152.0.0/16',[1, '1.1.1.2', '54dbb737eac5007103e729e9ab7ce64a6850a310',
     2, '2001:cdba::3257:9652', '89b44e4d3c81ede05d0f5de8d1a68f754d73d997',
     1, '3.3.3.3', '3a1e02d9ea25349c47fe2e94f4265cd261c5c7ca'])
tx7.sign(ks2.privkey)



chain = ChainService(env)


try:
     chain.add_pending_transaction(tx8)

except Exception as e:
     print e


trans = chain.transactions
print str(len(trans)) + " transacciones en espera"
for tx in trans:
     print tx.nonce, tx.to, tx.afi
#
#chain.add_pending_transaction(tx3)
Beispiel #5
0
from keystore import Keystore
import rlp
import netaddr
from netaddr import IPNetwork, IPAddress, IPSet
from utils import address, normalize_address
from chain_service import ChainService
import logger

logger.setup_custom_logger('Database')

print "Loading the environment..."
db = LevelDB("./chain")
env = Env(db)

print "Loading chain..."
chain = ChainService(env)

print "Loading keystores..."

add1 = "094a2c9f5b46416b9b9bd9f1efa1f3a73d46cec2"
add2 = "7719818983cb546d1badee634621dad4214cba25"
add3 = "a3e04410f475b813c01ca77ff12cb277991e62d2"

ks1 = Keystore.load("./keystore/094a2c9f5b46416b9b9bd9f1efa1f3a73d46cec2",
                    "TFG1234")
ks2 = Keystore.load("./keystore/7719818983cb546d1badee634621dad4214cba25",
                    "TFG1234")
ks3 = Keystore.load("./keystore/a3e04410f475b813c01ca77ff12cb277991e62d2",
                    "TFG1234")

print "Starting test..."
Beispiel #6
0
import datetime
from db import LevelDB
import time
from config import Env
from keystore import Keystore
from chain_service import ChainService

print "Loading the environment..."
db = LevelDB("./chain")
env = Env(db)

print "Loading chain..."
chain = ChainService(env)

print "Loading keystores..."

add1 = "094a2c9f5b46416b9b9bd9f1efa1f3a73d46cec2"
add2 = "7719818983cb546d1badee634621dad4214cba25"
add3 = "a3e04410f475b813c01ca77ff12cb277991e62d2"

ks1 = Keystore.load("./keystore/094a2c9f5b46416b9b9bd9f1efa1f3a73d46cec2",
                    "TFG1234")
ks2 = Keystore.load("./keystore/7719818983cb546d1badee634621dad4214cba25",
                    "TFG1234")
ks3 = Keystore.load("./keystore/a3e04410f475b813c01ca77ff12cb277991e62d2",
                    "TFG1234")

print "Starting test..."

for i in range(5):
    b = chain.create_block(add1)
Beispiel #7
0
    addresses = []
    for file in glob.glob(os.path.join(keys_dir, '*')):
        key = Keystore.load(keys_dir + file[-40:], "TFG1234")
        keys.append(key)
        addresses.append(normalize_address(key.keystore['address']))
    return keys, addresses

logger.setup_custom_logger('Database')
keys, addresses = init_keystore()
print("Loaded ", len(keys), " keys")
nonce = 0
NUM_TX = 5
NUM_BLOCKS = 100
db = LevelDB("./chain")
env = Env(db)
chain = ChainService(env)
block_creation = []
block_addition = []
for NUM_TX in range(0, 250, 10):
    for j in range(NUM_BLOCKS*2):
        time.sleep(1)
        if j%2 != 0:
            for i in range(1,min(NUM_TX,len(addresses)-1)+1):
                ipset = chain.get_own_ips(addresses[i])
                nonce = chain.chain.state.get_nonce(addresses[i])
                tx = Transaction(nonce, 0, addresses[i-1], 1, ipset.iter_cidrs()[0].ip, time=int(time.time()))
                tx.sign(keys[i].privkey)
                chain.validate_transaction(tx)
                chain.add_pending_transaction(tx)

            c1 = datetime.datetime.now()