Giter Club home page Giter Club logo

Comments (6)

Sanix-Darker avatar Sanix-Darker commented on May 26, 2024 3

After each calls of mine() you can store it in a database or a file @Fatenfq , in my case i updated the mine() like this:

    import base64
    def mine(self):
        """
        This function serves as an interface to add the pending
        transactions to the blockchain by adding them to the block
        and figuring out Proof Of Work.
        """
        if not self.unconfirmed_transactions:
            return False

        last_block = self.last_block

        new_block = Block.Block(index=last_block.index + 1,
                                transactions=self.unconfirmed_transactions,
                                timestamp=time.time(),
                                previous_hash=last_block.hash,
                                nonce = 0)

        proof = self.proof_of_work(new_block)
        self.add_block(new_block, proof)

        self.unconfirmed_transactions = []
        # announce it to the network
        self.announce_new_block(new_block)

        chain_data = []
        for block in self.chain:
            chain_data.append(block.__dict__)
        # save the blockchain in ./mined [Make sure to create this directory]
        with open("./mined/baron_blockchain", "w") as file_:
            print("New Block mined and wrote sucessfully")
            file_.write(str(base64.b64encode(b''+str.encode(str(chain_data))) ))

        return new_block.index

The reason, i encoded it on base64 is to have an easy block of string simple to encode and decode, so that's just optionnal !

from python_blockchain_app.

satwikkansal avatar satwikkansal commented on May 26, 2024

Currently, It's in your RAM (and it's gone the moment you kill the process). But in a real-world blockchain setup, you'll be persisting it to the disk.

from python_blockchain_app.

AkshaySarawat avatar AkshaySarawat commented on May 26, 2024

Hi Sanix-Darker,

I updated my code with this and node server ran fine, but now the app running on port 5000 errored out while connecting with the node server.

Thanks

from python_blockchain_app.

sjc07 avatar sjc07 commented on May 26, 2024

Hi Sanix-Darker and AkshaySarawat

Did you find a resolution to the 500 error after making this change? I am unable to identify the issue.

Thanks a lot

from python_blockchain_app.

satwikkansal avatar satwikkansal commented on May 26, 2024

There can be various reasons for 500 error, please share your stack trace so that we can figure out

from python_blockchain_app.

sjc07 avatar sjc07 commented on May 26, 2024

It’s caused by the base64 encoding line of code. I wrote that data as free text and the error went away.

from python_blockchain_app.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.