Blockchain tutorials for double spending and signature verification

0 votes

I am not new to Blockchain technology and have been studying the TPCoin python codes line by line. However, when I was looking into the code, I found that there is no validation method that will prevent the double spending issues. Have shared my code below:-

class Transaction: 
        def __init__( self, sender, recipient, value ): 
              self.sender = sender 
              self.recipient = recipient 
              self.value = value 
              self.time = datetime.datetime.now() 
              self.signer = "" 

      def to_dict( self ): 
            if self.sender == "Genesis": 
                  identity = "Genesis" 
            else: 
                    identity = self.sender.identity 

            return collections.OrderedDict( { 'sender': identity, 'recipient': self.recipient, 'value': self.value, 'time' : self.time } ) 

            def sign_transaction( self ): 
                  private_key = self.sender._private_key 
                  signer = PKCS1_v1_5.new( private_key ) 
                  h = SHA.new( str( self.to_dict( ) ).encode( 'utf8' ) ) 
                  self.signer = binascii.hexlify( signer.sign( h ) ).decode( 'ascii' ) 
                  return self.signer 
            def display_transaction( self ): 
                  dict = self.to_dict( ) 
                  print ("sender: " + dict['sender']) 
                  print ('-----') 
                  print ("recipient: " + dict['recipient']) 
                  print ('-----') 
                  print ("value: " + str(dict['value'])) 
                  print ('-----') 
                  print ("time: " + str(dict['time'])) 
                  print ('-----') 
                  print ("signature: " + self.signer) 
                  print ('-----') 
        def validate_transaction( self ): 
                ### Double spending? Signature Verification? 
                return

I think there should be a sort of validation function within the Transaction class...but not quite sure what to do. I want a few ideas on how to handle this which will be well appreciated!!

Feb 24, 2022 in Blockchain by Soham
• 9,710 points
658 views

1 answer to this question.

0 votes
To answer your question, regardless of how many ever coins are spent, only a single one will be included to the block while the rest will be invalid and also, the invalid transactions cannot be included to the new blocks due to the UTXO’s non-acceptance of the output. However, for instance, when a single or double miner snatch two different types of transactions which are from the same output excluding the latency of the network, then both blocks are added to their own chains. Observing the largest concept of the chain and clarifying the concept of orphaned chains is one of the best ways to solve your problem. Hope this answers your question!!
answered Feb 24, 2022 by Aditya
• 7,680 points

Related Questions In Blockchain

0 votes
1 answer
0 votes
1 answer

Using public and private keys for Blockchain transaction

You need to provide the receiver's public ...READ MORE

answered Jun 20, 2019 in Blockchain by Will
1,078 views
0 votes
0 answers
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,426 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,922 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
0 votes
1 answer
0 votes
1 answer

On-Chain NFT: How to store a pixel image on the ethereum blockchain?

The images are usually not stored in ...READ MORE

answered Feb 24, 2022 in Blockchain by Aditya
• 7,680 points
1,109 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP