Esempio n. 1
0
 def __init__(self, address=None):
     self._bucket = Bucket(Blockchain.db_file, Blockchain.block_bucket)
     try:
         self._tip = self._bucket.get('l')
     except KeyError:
         genesis = NewGnesisBlock().pow_of_block()
         self._block_put(genesis)
Esempio n. 2
0
    def __init__(self):
        self._bucket = Bucket(Blockchain.db_file, Blockchain.block_bucket)

        try:
            self._tip = self._bucket.get('l')
        except KeyError:
            self._tip = None
Esempio n. 3
0
  def reset(self):
    self._bucket = Bucket(UTXOSet.db_file, UTXOSet.bucket)
    self._bucket.reset()
    utxos = self._bc.find_all_utxo()
    for tx_id, vout_idx in utxos.items():
        self._bucket.put(tx_id, utils.serialize(vout_idx))

    self._bucket.commit()
Esempio n. 4
0
    def __init__(self, address=None):
        self._bucket = Bucket(Blockchain.db_file, Blockchain.block_bucket)

        try:
            self._tip = self._bucket.get('l')
        except KeyError:
            cb_tx = CoinbaseTx(address, Blockchain.genesis_coinbase_data)
            genesis = Block([cb_tx]).pow_of_block()
            self._block_put(genesis)
Esempio n. 5
0
    def __init__(self, address=None):
        self._bucket = Bucket(BlockChain.db_file, BlockChain.block_bucket)

        try:
            self._tip = self._bucket.get('l')
        except KeyError:
            if not address:
                self._tip = None
            else:
                cb_tx = CoinbaseTx(address, BlockChain.genesis_coinbase_data)
                genesis = Block([cb_tx], 0).proof_of_block()
                self._put_block(genesis)
Esempio n. 6
0
 def __init__(self, address=None):
   self._bucket = Bucket(BlockChain.db_file, BlockChain.bucket)
   
   try:
     self._address = self._bucket.get('address')
     self._last_hash = self._bucket.get('l')
     self._last_block = pickle.loads(self._bucket.get(self._last_hash))
   except KeyError:
     if not address: # no data & no given address
       print('Block Chain not created yet!\nPlease create a new block chain with given address first!')
       sys.exit()
     else:
       self.reset(address)
Esempio n. 7
0
  def update(self, block):
    self._bucket = Bucket(UTXOSet.db_file, UTXOSet.bucket)
    transactions = block.transactions
    for tx in transactions:
      if not isinstance(tx, CoinBaseTx):
        for vin in tx.vin:
          update_outs = []
          encoded_outs = self._bucket.get(vin.txid)
          outs = utils.deserialize(encoded_outs)

          for out_idx, out in enumerate(outs):
            if out_idx != vin.vout_idx:
              update_outs.append(out)

          if len(update_outs) == 0:
            self._bucket.delete(vin.txid)
          else:
            self._bucket.put(
              vin.txid, utils.serialize(update_outs))

      new_output = [out for out in tx.vout]
      self._bucket.put(tx.id, utils.serialize(new_output))
    self._bucket.commit()
Esempio n. 8
0
 def __init__(self, blockchain):
     self._bucket = Bucket(UTXOSet.db_file, UTXOSet.utxo_bucket)
     self._bc = blockchain
Esempio n. 9
0
from block import Block
from blockchain import Blockchain
from db import Bucket

if __name__ == "__main__":
#	blockchain = Blockchain()
#	print(blockchain)
#	blockchain.addBlock('addBlock')
#	print(blockchain)
	bucket = Bucket('test.db', 'block')
	bucket2 = Bucket('test.db', 'block2')
	bucket['key1'] = 'value'
	print(bucket['key'])
	bucket2['key2'] = 'value'
	bucket.commit()
	bucket2.commit()
	print(bucket)
	print(bucket2)
Esempio n. 10
0
 def __init__(self):
     self._blocks = Bucket(DB_FILE, BLOCK_BUCKET)