English 中文(简体)
Blockchain - Developing Client
  • 时间:2024-12-22

Python Blockchain - Developing Cpent


Previous Page Next Page  

A cpent is somebody who holds TPCoins and transacts those for goods/services from other vendors on the network including his own. We should define a Cpent class for this purpose. To create a globally unique identification for the cpent, we use PKI (Pubpc Key Infrastructure). In this chapter, let us talk about this in detail.

The cpent should be able to send money from his wallet to another known person. Similarly, the cpent should be able to accept money from a third party. For spending money, the cpent would create a transaction specifying the sender’s name and the amount to be paid. For receiving money, the cpent will provide his identity to the third party − essentially a sender of the money. We do not store the balance amount of money the cpent holds in his wallet. During a transaction, we will compute the actual balance to ensure that the cpent has sufficient balance to make the payment.

To develop the Cpent class and for the rest of the code in the project, we will need to import many Python pbraries. These are psted below −

# import pbraries
import hashpb
import random
import string
import json
import binascii
import numpy as np
import pandas as pd
import pylab as pl
import logging
import datetime
import collections

In addition to the above standard pbraries, we are going to sign our transactions, create hash of the objects, etc. For this, you will need to import the following pbraries −

# following imports are required by PKI
import Crypto
import Crypto.Random
from Crypto.Hash import SHA
from Crypto.PubpcKey import RSA
from Crypto.Signature import PKCS1_v1_5

In the next chapter, let us talk about cpent class.

Advertisements