Esempio n. 1
0
    def create(self, chain, reveal_hash, vote_hash, last_block_number=-1):
        # FIXME: probably this should turn into a constructor
        reveal_hash = reveal_hash
        vote_hash = vote_hash

        data = None
        if last_block_number == -1:
            data = chain.block_chain_buffer.get_last_block(
            )  # m_get_last_block()
        else:
            data = chain.block_chain_buffer.get_block_n(last_block_number)

        last_block_number = data.blockheader.blocknumber
        prev_blockheaderhash = data.blockheader.headerhash

        hashedtransactions = []
        self.transactions = [None]
        fee_reward = 0

        for tx in chain.transaction_pool:
            if tx.subtype == TX_SUBTYPE_TX:
                fee_reward += tx.fee
            hashedtransactions.append(tx.txhash)
            self.transactions.append(tx)  # copy memory rather than sym link

        self.duplicate_transactions = []

        for tx in chain.duplicate_tx_pool:
            self.duplicate_transactions.append(chain.duplicate_tx_pool[tx])

        if not hashedtransactions:
            hashedtransactions = [sha256('')]

        hashedtransactions = merkle_tx_hash(hashedtransactions)

        self.blockheader = BlockHeader()
        self.blockheader.create(chain=chain,
                                blocknumber=last_block_number + 1,
                                reveal_hash=reveal_hash,
                                vote_hash=vote_hash,
                                prev_blockheaderhash=prev_blockheaderhash,
                                hashedtransactions=hashedtransactions,
                                fee_reward=fee_reward)

        coinbase_tx = CoinBase().create(
            self.blockheader,
            chain.block_chain_buffer.get_slave_xmss(last_block_number + 1))
        # coinbase_tx = CoinBase().create(self.blockheader.block_reward + self.blockheader.fee_reward,
        #                                            self.blockheader.headerhash,
        #                                            chain.wallet.address_bundle[0].xmss.get_address(),
        #                                            chain.block_chain_buffer.get_slave_xmss(last_block_number + 1))

        self.transactions[0] = coinbase_tx
        sv_list = chain.block_chain_buffer.get_stake_validators_list(
            last_block_number + 1).sv_list
        coinbase_tx.nonce = sv_list[chain.mining_address].nonce + 1
Esempio n. 2
0
    def json_to_block(self, json_block):
        self.blockheader = BlockHeader()
        self.blockheader.json_to_blockheader(json_block['blockheader'])

        transactions = json_block['transactions']
        self.transactions = []
        for tx in transactions:
            self.transactions.append(Transaction.get_tx_obj(tx))

        if self.blockheader.blocknumber == 0:
            self.state = json_block['state']
            self.stake_list = json_block['stake_list']
Esempio n. 3
0
    def json_to_block(self, json_block):
        self.blockheader = BlockHeader()
        self.blockheader.json_to_blockheader(json_block['blockheader'])

        transactions = json_block['transactions']
        self.transactions = []
        for tx in transactions:
            self.transactions.append(Transaction.from_txdict(tx))

        duplicate_transactions = json_block['duplicate_transactions']
        self.duplicate_transactions = []
        for tx in duplicate_transactions:
            self.duplicate_transactions.append(
                DuplicateTransaction().from_txdict(tx))

        if self.blockheader.blocknumber == 0:
            self.state = json_block['state']
            self.stake_list = json_block['stake_list']
Esempio n. 4
0
    def create(self, chain, hashchain_link, reveal_list=None, vote_hashes=None, last_block_number=-1):
        # FIXME: probably this should turn into a constructor
        if not reveal_list:
            reveal_list = []
        if not vote_hashes:
            vote_hashes = []

        data = None
        if last_block_number == -1:
            data = chain.block_chain_buffer.get_last_block()  # m_get_last_block()
        else:
            data = chain.block_chain_buffer.get_block_n(last_block_number)

        last_block_number = data.blockheader.blocknumber
        prev_blockheaderhash = data.blockheader.headerhash

        hashedtransactions = []
        self.transactions = [None]

        for tx in chain.transaction_pool:
            hashedtransactions.append(tx.txhash)
            self.transactions.append(tx)  # copy memory rather than sym link

        if not hashedtransactions:
            hashedtransactions = sha256('')

        hashedtransactions = merkle_tx_hash(hashedtransactions)

        self.blockheader = BlockHeader()
        self.blockheader.create(chain=chain,
                                blocknumber=last_block_number + 1,
                                reveal_list=reveal_list,
                                vote_hashes=vote_hashes,
                                hashchain_link=hashchain_link,
                                prev_blockheaderhash=prev_blockheaderhash,
                                hashedtransactions=hashedtransactions)

        coinbase_tx = transaction.CoinBase().create(self.blockheader.block_reward, self.blockheader.headerhash,
                                                    chain.my[0][1])
        self.transactions[0] = coinbase_tx
        coinbase_tx.nonce = chain.block_chain_buffer.get_stxn_state(last_block_number + 1, chain.mining_address)[0] + 1
Esempio n. 5
0
 def test_init(self):
     # TODO: Not much going on here..
     block_header = BlockHeader()
     self.assertIsNotNone(block_header)  # just to avoid warnings