Need help in blockchain coding.

Mats Wichmann mats at wichmann.us
Sat Jun 11 18:23:26 EDT 2022


On 6/11/22 15:29, dn wrote:
> On 12/06/2022 02.51, Ayesha Tassaduq wrote:
>> I am a beginner in python I want to transfer generated hash to a local database. I try it with socket programming but I fail. can anyone please help me ow I can do this?
> 
> Where is the database?
> Where is the socket?
> What are the (full) error messages?

Indeed... what you've posted, with the exception that we don't see what
these two _df values are:

t1 = Time_sensitive_df
...
t3 = normal_df

looks basically workable for what it is.

Guessing at your intent here - presumably you want your chain to be
persistent and not be created from scratch each time you go to access
it. You *could* use a database for this, and there are lots of Python
technologies for talking to databases, but there's none of that in your
code so we can't comment on it.

For early experiments you could just use a text file.  Then you need to
code a way to load the existing chain from the file into your working
copy, if the file exists, rather than instantiating a copy of
Blockchain, which will always start over:

    def __init__( self ):
        self.chain = [ ]
        self.generate_genesis_block()

since the chain itself is a list, perhaps you could dump that list to a
json file, and reload it into self.chain if the json file is found to
exist, instead of doing the initial-setup?

Apologies if I have completely misunderstood what you are seeking...


More information about the Python-list mailing list