Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

I do not fear computers. I fear the lack of them. -- Isaac Asimov


devel / comp.lang.python / Re: Need help in blockchain coding.

SubjectAuthor
* Need help in blockchain coding.Ayesha Tassaduq
+- Re: Need help in blockchain coding.dn
`- Re: Need help in blockchain coding.Mats Wichmann

1
Need help in blockchain coding.

<ed25a8cb-0e5d-4be2-b13b-8f504460a0f3n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18578&group=comp.lang.python#18578

  copy link   Newsgroups: comp.lang.python
X-Received: by 2002:a37:343:0:b0:6a6:7895:8eaf with SMTP id 64-20020a370343000000b006a678958eafmr33578132qkd.493.1654959118147;
Sat, 11 Jun 2022 07:51:58 -0700 (PDT)
X-Received: by 2002:a54:4e8a:0:b0:32e:bdbb:c562 with SMTP id
c10-20020a544e8a000000b0032ebdbbc562mr2640548oiy.64.1654959117834; Sat, 11
Jun 2022 07:51:57 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.python
Date: Sat, 11 Jun 2022 07:51:57 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=39.46.86.120; posting-account=IERH7AoAAAAiocwvZQ3CAXkKMSHv16KV
NNTP-Posting-Host: 39.46.86.120
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ed25a8cb-0e5d-4be2-b13b-8f504460a0f3n@googlegroups.com>
Subject: Need help in blockchain coding.
From: ayeshata...@gmail.com (Ayesha Tassaduq)
Injection-Date: Sat, 11 Jun 2022 14:51:58 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2442
 by: Ayesha Tassaduq - Sat, 11 Jun 2022 14:51 UTC

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?

class Block:
def __init__( self, previous_block_hash, transaction_list ):
self.previous_block_hash = previous_block_hash
self.transaction_list = transaction_list

self.block_data = f"{' - '.join(transaction_list)} - {previous_block_hash}"
self.block_hash = hashlib.sha256(self.block_data.encode()).hexdigest()

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

def generate_genesis_block( self ):
self.chain.append(Block("0", [ 'Genesis Block' ]))

def create_block_from_transaction( self, transaction_list ):
previous_block_hash = self.last_block.block_hash
self.chain.append(Block(previous_block_hash, transaction_list))

def display_chain( self ):
for i in range(len(self.chain)):
print(f"Hash {i + 1}: {self.chain [ i ].block_hash}\n")

@property
def last_block( self ):
return self.chain [ -1 ]

**t1 = Time_sensitive_df
t2 = "abcdefghijklmnopqrstuvwxyz"
t3 = normal_df
myblockchain = Blockchain()
myblockchain.create_block_from_transaction(t1)
myblockchain.create_block_from_transaction(t2)
myblockchain.create_block_from_transaction(t3)
myblockchain.display_chain()**

Re: Need help in blockchain coding.

<mailman.614.1654982975.20749.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18584&group=comp.lang.python#18584

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonL...@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: Need help in blockchain coding.
Date: Sun, 12 Jun 2022 09:29:02 +1200
Organization: DWM
Lines: 50
Message-ID: <mailman.614.1654982975.20749.python-list@python.org>
References: <ed25a8cb-0e5d-4be2-b13b-8f504460a0f3n@googlegroups.com>
<c6acec5d-5608-2a8d-7d79-806a5d4616a2@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de w3hS24b8v5P6BFwKu4wkZwRcy8c2OTxH9R+J5Hb5bnuw==
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=I1VFoTq9; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'generated': 0.03; 'def':
0.04; 'beginner': 0.07; '=dn': 0.09; 'fail.': 0.09;
'from:addr:danceswithmice.info': 0.09; 'from:addr:pythonlist':
0.09; 'database.': 0.16; 'hash': 0.16; 'message-
id:@DancesWithMice.info': 0.16; 'received:51.254': 0.16;
'received:51.254.211': 0.16; 'received:51.254.211.219': 0.16;
'received:cloud': 0.16; 'received:rangi.cloud': 0.16; 'wrote:':
0.16; 'python': 0.16; 'to:addr:python-list': 0.20; 'programming':
0.25; 'anyone': 0.25; 'skip:{ 20': 0.26; 'local': 0.27; 'this?':
0.29; 'error': 0.29; 'header:User-Agent:1': 0.30;
'header:Organization:1': 0.31; 'but': 0.32; 'skip:" 20': 0.34;
'header:In-Reply-To:1': 0.34; 'subject:Need': 0.37; 'class': 0.37;
'received:192.168': 0.37; 'want': 0.40; 'try': 0.40; 'skip:r 20':
0.64; 'received:51': 0.64; 'received:userid': 0.66; 'transfer':
0.69
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud 0ABB0470D
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1654982967;
bh=ZQFJEYNC7JnuzsEPIJ3ptio5aIzY/hEiJ94SfS4AJZ4=;
h=Date:Subject:To:References:From:In-Reply-To:From;
b=I1VFoTq9B71bInGbT75m49UazvpvfjwHXF4CAKdEDp48gFVxWU9tnTQIEuF2Ocw/N
Sd6iC8Z2x3jn4aInRytSmRK1mnchD+XsVxyV0l9SHczSO7dR3LJkVx9K99eJcRPl7H
bRPpocR2ommfNcW6+SE62o527dC6UJqNQuVD6W5wmSu6ADOxLdo0+JVsC5gGF5nMlV
9/OHdNkgtfPkgCraRPWOL0aD4PgNpI0rZxO4TZ4EixIfBn7F02UCaB33Xq7RZXZvZL
S0BmFKT4l6aLh8RC8KQBL/3Y1DMfS/rQoKlgt3L4JU2lxFE0M5vgcSW0B/avbu9S1n
R9Hy/7heEXqBg==
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on vps517507.ovh.net
X-Spam-Level:
X-Spam-Status: No, score=-4.2 required=5.0 tests=ALL_TRUSTED,BAYES_00,
DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,NICE_REPLY_A,T_SCC_BODY_TEXT_LINE
autolearn=ham autolearn_force=no version=3.4.0
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud C2C67470D
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1654982951;
bh=ZQFJEYNC7JnuzsEPIJ3ptio5aIzY/hEiJ94SfS4AJZ4=;
h=Date:Subject:To:References:From:In-Reply-To:From;
b=oGwgfQZ+buX2nj1znElJV1OMdKyOUh/FkNw3PeG3YxO4LS+UOECijK/+rLEKOfQsv
C0Cdc/TttIW0kh4qsMDbo+fiRW88k6MFm+F2dlLrRHKHSpuCrC5YdhqK9ZvwaOHzbq
5WEGQuNKYi2NkSKU4inGNU0sz6MsjdgHcTX9sOY42ImrDYO2le/CVf2TccyLngdpfB
zsIzehl4UGZOl8F6vTfIR45s/G9BD0JzFgE25gPIaT/8BndJJ+1w/I/FLttaXofQ/Q
Qk9IS7eBOl/Cjf6mScifCCQOPg34Whejt36Trq8iKFV+SiNoE5dpWhutmwR/XhWAgI
obaWrc+H0mK4w==
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
Content-Language: en-GB
In-Reply-To: <ed25a8cb-0e5d-4be2-b13b-8f504460a0f3n@googlegroups.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <c6acec5d-5608-2a8d-7d79-806a5d4616a2@DancesWithMice.info>
X-Mailman-Original-References: <ed25a8cb-0e5d-4be2-b13b-8f504460a0f3n@googlegroups.com>
 by: dn - Sat, 11 Jun 2022 21:29 UTC

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?

> class Block:
> def __init__( self, previous_block_hash, transaction_list ):
> self.previous_block_hash = previous_block_hash
> self.transaction_list = transaction_list
>
> self.block_data = f"{' - '.join(transaction_list)} - {previous_block_hash}"
> self.block_hash = hashlib.sha256(self.block_data.encode()).hexdigest()
>
>
> class Blockchain:
> def __init__( self ):
> self.chain = [ ]
> self.generate_genesis_block()
>
> def generate_genesis_block( self ):
> self.chain.append(Block("0", [ 'Genesis Block' ]))
>
> def create_block_from_transaction( self, transaction_list ):
> previous_block_hash = self.last_block.block_hash
> self.chain.append(Block(previous_block_hash, transaction_list))
>
> def display_chain( self ):
> for i in range(len(self.chain)):
> print(f"Hash {i + 1}: {self.chain [ i ].block_hash}\n")
>
> @property
> def last_block( self ):
> return self.chain [ -1 ]
>
>
> **t1 = Time_sensitive_df
> t2 = "abcdefghijklmnopqrstuvwxyz"
> t3 = normal_df
> myblockchain = Blockchain()
> myblockchain.create_block_from_transaction(t1)
> myblockchain.create_block_from_transaction(t2)
> myblockchain.create_block_from_transaction(t3)
> myblockchain.display_chain()**

--
Regards,
=dn

Re: Need help in blockchain coding.

<mailman.615.1654986223.20749.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18585&group=comp.lang.python#18585

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: mat...@wichmann.us (Mats Wichmann)
Newsgroups: comp.lang.python
Subject: Re: Need help in blockchain coding.
Date: Sat, 11 Jun 2022 16:23:26 -0600
Lines: 37
Message-ID: <mailman.615.1654986223.20749.python-list@python.org>
References: <ed25a8cb-0e5d-4be2-b13b-8f504460a0f3n@googlegroups.com>
<c6acec5d-5608-2a8d-7d79-806a5d4616a2@DancesWithMice.info>
<b0bbbaea-e491-6348-9bd2-3d50a7821d75@wichmann.us>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de aAeHPCA20Wyl1ElUQJDm6g89Ppfe9usxcNWoXcMIUUUg==
Return-Path: <mats@wichmann.us>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="1024-bit key; unprotected key"
header.d=pobox.com header.i=@pobox.com header.b=DI54YLSZ;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'looks': 0.02; 'generated':
0.03; 'def': 0.04; 'is.': 0.05; 'beginner': 0.07; 'fail.': 0.09;
'json': 0.09; 'received:173': 0.13; '*could*': 0.16;
'blockchain,': 0.16; 'database.': 0.16; 'databases,': 0.16;
'hash': 0.16; 'intent': 0.16; 'presumably': 0.16; 'wrote:': 0.16;
'python': 0.16; 'values': 0.17; 'instead': 0.17; "can't": 0.17;
'to:addr:python-list': 0.20; 'basically': 0.22; 'exception': 0.22;
'code': 0.23; 'list,': 0.24; 'programming': 0.25; 'anyone': 0.25;
'local': 0.27; 'this?': 0.29; 'error': 0.29; 'header:User-
Agent:1': 0.30; 'comment': 0.31; 'but': 0.32; 'there': 0.33;
'header:In-Reply-To:1': 0.34; 'subject:Need': 0.37;
'received:192.168': 0.37; 'file': 0.38; 'way': 0.38; 'could':
0.38; 'two': 0.39; 'text': 0.39; 'this,': 0.39; 'list': 0.39;
'use': 0.39; 'want': 0.40; 'try': 0.40; "there's": 0.61; 'load':
0.62; 'here': 0.62; 'copy': 0.63; 'your': 0.64; 'transfer': 0.69;
'....': 0.76; 'chain': 0.76; 'database': 0.80; 'experiments': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=message-id
:date:mime-version:subject:to:references:from:in-reply-to
:content-type:content-transfer-encoding; s=sasl; bh=foGuJaB4pmsi
1TDFcN6CVdHcVNZSNNQfrp7xZms42D4=; b=DI54YLSZuxkWTLgO1LRQhHLnJfv2
aEhxRBuRe1FHfyEUPs4XkoPkA1Tf5iiR2PU98gW2ZZFU1hDbbzPmnJYF78p0Z7Tm
oK93UdO5KBI6ra7zAZkW+CehxVRTW0xvS0lVgXK+0N91bMyTGRKRkD5wqAJr/jfY
t5g6jcLN47EwR/E=
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=wichmann.us;
h=message-id:date:mime-version:subject:to:references:from:in-reply-to:content-type:content-transfer-encoding;
s=2018-07.pbsmtp; bh=foGuJaB4pmsi1TDFcN6CVdHcVNZSNNQfrp7xZms42D4=;
b=i6qHG7dKFlg/1UES/TpE5yiaGhxQOeUxJ93CvzPyhTUEsptxew0VEDxHq5t2jbKW2UUZ5ITSiERNryE0yTaJIZaHy0xgKtSV/9Ds8r7rEdwwiNyfW/1W9WzWoccDdNyDNQ+iouyRbUSgdSUntAeum1uQKKs45xC5d6nF69tlGIo=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
Content-Language: en-US
In-Reply-To: <c6acec5d-5608-2a8d-7d79-806a5d4616a2@DancesWithMice.info>
X-Pobox-Relay-ID: 1E67B846-E9D5-11EC-9AB0-CBA7845BAAA9-81526775!pb-smtp21.pobox.com
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <b0bbbaea-e491-6348-9bd2-3d50a7821d75@wichmann.us>
X-Mailman-Original-References: <ed25a8cb-0e5d-4be2-b13b-8f504460a0f3n@googlegroups.com>
<c6acec5d-5608-2a8d-7d79-806a5d4616a2@DancesWithMice.info>
 by: Mats Wichmann - Sat, 11 Jun 2022 22:23 UTC

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...

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor