def pack_binary(self): """ Pack the data into a binary string for storage in DB. The standard format is [ dataType(varInt) ][ actual data ] The actual data is stored as follows: [ length of question (varInt) ][ question ] [ amount of answers (varInt) ] for each answer: [ length of answer (varInt) ][ answer } [ amount of addresses (varInt) ] for each address: [ length of address (varInt) ][ address } [ amount of public keys (varInt) ] for each pubkey: [ length of signing pubkey (varInt) ][ signing pubkey } [ length of encryption pubkey (varInt) ][ encryption pubkey ] """ result = ConsensusData.pack_binary_header( ConsensusData.DATA_TYPE_VOTING, self.blockchain, self.time_data) result += encodeVarint(len(self.question)) result += self.question result += encodeVarint(len(self.answers)) for answer in self.answers: result += encodeVarint(len(answer)) result += answer result += encodeVarint(len(self.addresses)) for address in self.addresses: result += encodeVarint(len(address)) result += address if self.public_keys is None: result += encodeVarint(0) else: result += encodeVarint(len(self.public_keys)) for pubkey in self.public_keys: if pubkey is None: result += encodeVarint(0) result += encodeVarint(0) else: # Signing key first if pubkey[0] is None: result += encodeVarint(0) else: result += encodeVarint(len(pubkey[0])) result += pubkey[0] # Then encryption key if pubkey[1] is None: result += encodeVarint(0) else: result += encodeVarint(len(pubkey[1])) result += pubkey[1] return result
def pack_binary( self ): """ Pack the data into a binary string for storage in DB. The standard format is [ dataType(varInt) ][ actual data ] The actual data is stored as follows: [ length of question (varInt) ][ question ] [ amount of answers (varInt) ] for each answer: [ length of answer (varInt) ][ answer } [ amount of addresses (varInt) ] for each address: [ length of address (varInt) ][ address } [ amount of public keys (varInt) ] for each pubkey: [ length of signing pubkey (varInt) ][ signing pubkey } [ length of encryption pubkey (varInt) ][ encryption pubkey ] """ result = ConsensusData.pack_binary_header(ConsensusData.DATA_TYPE_VOTING, self.blockchain, self.time_data) result += encodeVarint( len( self.question ) ) result += self.question result += encodeVarint( len( self.answers ) ) for answer in self.answers: result += encodeVarint( len( answer ) ) result += answer result += encodeVarint( len( self.addresses ) ) for address in self.addresses: result += encodeVarint( len( address ) ) result += address if self.public_keys is None: result += encodeVarint( 0 ) else: result += encodeVarint( len( self.public_keys ) ) for pubkey in self.public_keys: if pubkey is None: result += encodeVarint( 0 ) result += encodeVarint( 0 ) else: # Signing key first if pubkey[0] is None: result += encodeVarint( 0 ) else: result += encodeVarint( len( pubkey[0] ) ) result += pubkey[0] # Then encryption key if pubkey[1] is None: result += encodeVarint( 0 ) else: result += encodeVarint( len( pubkey[1] ) ) result += pubkey[1] return result