Skip to content
Snippets Groups Projects
Select Git revision
  • c60745cf27edef74de07d082777c5a7a139de6a0
  • master default protected
  • dev
  • appimage
  • fix_gitlab
  • fixappveyor
  • gitlab
  • fix_ci
  • fix_dbus_error
  • fix_ci_osx
  • sakia020
  • fix_travis#1105
  • feature/backend
  • check_uniq_node_by_endpoints
  • qt5.7
  • feature/agent_architecture
  • translations
  • pyqt5.6
  • qtwebengine
  • pyinstaller
  • landscape
  • 0.53.2
  • 0.53.1
  • 0.53.0
  • 0.52.0
  • 0.51.1
  • 0.51.0
  • 0.50.5
  • 0.50.4
  • 0.50.3
  • 0.50.2
  • 0.50.1
  • 0.50.0
  • 0.33.0rc7
  • 0.33.0rc6
  • 0.33.0rc5
  • 0.33.0rc4
  • 0.33.0rc3
  • 0.33.0rc2
  • 0.33.0rc1
  • 0.32.10post1
41 results

block.py

Blame
  • block.py 5.06 KiB
    '''
    Created on 2 déc. 2014
    
    @author: inso
    '''
    
    from .. import PROTOCOL_VERSION
    from . import Document
    
    
    class Block(Document):
        '''
    Version: VERSION
    Type: Block
    Currency: CURRENCY
    Nonce: NONCE
    Number: BLOCK_NUMBER
    PoWMin: NUMBER_OF_ZEROS
    Time: GENERATED_ON
    MedianTime: MEDIAN_DATE
    UniversalDividend: DIVIDEND_AMOUNT
    Issuer: ISSUER_KEY
    PreviousHash: PREVIOUS_HASH
    PreviousIssuer: PREVIOUS_ISSUER_KEY
    Parameters: PARAMETERS
    MembersCount: WOT_MEM_COUNT
    Identities:
    PUBLIC_KEY:SIGNATURE:TIMESTAMP:USER_ID
    ...
    Joiners:
    PUBLIC_KEY:SIGNATURE:NUMBER:HASH:TIMESTAMP:USER_ID
    ...
    Actives:
    PUBLIC_KEY:SIGNATURE:NUMBER:HASH:TIMESTAMP:USER_ID
    ...
    Leavers:
    PUBLIC_KEY:SIGNATURE:NUMBER:HASH:TIMESTAMP:USER_ID
    ...
    Excluded:
    PUBLIC_KEY
    ...
    Certifications:
    PUBKEY_FROM:PUBKEY_TO:BLOCK_NUMBER:SIGNATURE
    ...
    Transactions:
    COMPACT_TRANSACTION
    ...
    BOTTOM_SIGNATURE
        '''
    
        def __init__(self, currency, noonce, number, powmin, time,
                     mediantime, ud, issuer, prev_hash, prev_issuer,
                     parameters, members_count, identities, joiners,
                     actives, leavers, excluded, certifications,
                     transactions):
            '''
            Constructor
            '''
            self.currency = currency
            self.noonce = noonce
            self.number = number
            self.powmin = powmin
            self.time = time
            self.mediantime = mediantime
            self.ud = ud
            self.issuer = issuer
            self.prev_hash = prev_hash
            self.prev_issuer = prev_issuer
            self.parameters = parameters
            self.members_count = members_count
            self.identities = identities
            self.joiners = joiners
            self.actives = actives
            self.leavers = leavers
            self.excluded = excluded
            self.certifications = certifications
            self.transactions = transactions
            
        @classmethod
        def from_raw(cls, raw):
            #TODO : Parsing
            lines = raw.splitlines(True)
            
            n = 0
            version_re = re.compile("Version: ([0-9]+)\n") 
            version = version_re.match(lines[n])
            n = 1
            currency_re = re.compile("Currency: ([0-9a-zA-Z_\-]+)\n"
            currency = currency_re.match(lines[n])
            
            n = 2
            noonce_re = re.compile("Nonce: ([0-9]+)\n") 
            noonce = nonce_re.match(lines[n])
            
            n = 3
            number_re = re.compile("Number: ([0-9]+)\n") 
            number = number_re.match(lines[n])
            
            n = 4
            powmin_re = re.compile("PoWMin: ([0-9]+)\n") 
            powmin = powmin.match(lines[n])        
            
            n = 5
            time_re = re.compile("Time: ([0-9]+)\n") 
            time = time.match(lines[n]) 
            
            n = 6
            mediantime_re = re.compile("MedianTime: ([0-9]+)\n") 
            mediantime = mediantime_re.match(line[n])
            
            n = 7
            ud_re = re.compile("UniversalDividend: ([0-9]+)\n") 
            ud = ud_re.match(line[n])
            
            n = 8
            issuer_re = re.compile("Issuer: ([1-9A-Za-z][^OIl]{43,45})\n")
            issuer = issuer_re.match(line[n])
            
            n = 9
            previoushash_re = re.compile("PreviousHash: ([0-9a-fA-F]{5,40})\n")
            prev_hash = previoushash_re.match(line[n])
            
            n = 10
            previousissuer_re = re.compile("PreviousIssuer: ([1-9A-Za-z][^OIl]{43,45})\n")
            prev_issuer = previousissuer_re.match(line[n])
            
            parameters = ""
            members_count = ""
            identities = ""
            joiners = ""
            actives = ""
            leavers = ""
            excluded = ""
            certifications = ""
            transactions = ""
            
            return cls([])
            
        def content(self):
            doc = """
    Version: {0}
    Type: Block
    Currency: {1}
    Nonce: {2}
    Number: {3}
    PoWMin: {4}
    Time: {5}
    MedianTime: {6}
    UniversalDividend: {7}
    Issuer: {8}
    PreviousHash: {9}
    PreviousIssuer: {10}
    Parameters: {11}
    MembersCount: {12}
    Identities:""".format(PROTOCOL_VERSION,
                          self.currency,
                          self.noonce,
                          self.number,
                          self.powmin,
                          self.time,
                          self.mediantime,
                          self.ud,
                          self.issuer,
                          self.prev_hash,
                          self.prev_issuer,
                          self.parameters,
                          self.members_count)
    
            for identity in self.identities:
                doc += "{0}\n".format(identity.inline())
    
            doc += "Joiners:\n"
            for joiner in self.joiners:
                doc += "{0}\n".format(joiner.inline())
    
            doc += "Actives:\n"
            for active in self.actives:
                doc += "{0}\n".format(active.inline())
    
            doc += "Leavers:\n"
            for leaver in self.leavers:
                doc += "{0]\n".format(leaver.inline())
    
            doc += "Excluded:\n"
            for exclude in self.exclude:
                doc += "{0}\n".format(exclude.inline())
    
            doc += "Certifications:\n"
            for cert in self.certifications:
                doc += "{0}\n".format(cert.inline())
    
            doc += "Transactions:\n"
            for transaction in self.transactions:
                doc += "{0}\n".format(transaction.inline())