MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / doPOWForMyV2Pubkey

Method doPOWForMyV2Pubkey

src/class_singleWorker.py:148–215  ·  view source on GitHub ↗

configSections = shared.config.addresses() for addressInKeysFile in configSections: if addressInKeysFile <> 'bitmessagesettings': status,addressVersionNumber,streamNumber,hashFromThisParticularAddress = decodeAddress(addressInKeysFile) if hash == h

(self, hash)

Source from the content-addressed store, hash-verified

146 logger.info("Quitting...")
147
148 def doPOWForMyV2Pubkey(self, hash): # This function also broadcasts out the pubkey message once it is done with the POW
149 # Look up my stream number based on my address hash
150 """configSections = shared.config.addresses()
151 for addressInKeysFile in configSections:
152 if addressInKeysFile <> 'bitmessagesettings':
153 status,addressVersionNumber,streamNumber,hashFromThisParticularAddress = decodeAddress(addressInKeysFile)
154 if hash == hashFromThisParticularAddress:
155 myAddress = addressInKeysFile
156 break"""
157 myAddress = shared.myAddressesByHash[hash]
158 status, addressVersionNumber, streamNumber, hash = decodeAddress(
159 myAddress)
160
161 TTL = int(28 * 24 * 60 * 60 + random.randrange(-300, 300))# 28 days from now plus or minus five minutes
162 embeddedTime = int(time.time() + TTL)
163 payload = pack('>Q', (embeddedTime))
164 payload += '\x00\x00\x00\x01' # object type: pubkey
165 payload += encodeVarint(addressVersionNumber) # Address version number
166 payload += encodeVarint(streamNumber)
167 payload += protocol.getBitfield(myAddress) # bitfield of features supported by me (see the wiki).
168
169 try:
170 privSigningKeyBase58 = BMConfigParser().get(
171 myAddress, 'privsigningkey')
172 privEncryptionKeyBase58 = BMConfigParser().get(
173 myAddress, 'privencryptionkey')
174 except Exception as err:
175 logger.error('Error within doPOWForMyV2Pubkey. Could not read the keys from the keys.dat file for a requested address. %s\n' % err)
176 return
177
178 privSigningKeyHex = hexlify(shared.decodeWalletImportFormat(
179 privSigningKeyBase58))
180 privEncryptionKeyHex = hexlify(shared.decodeWalletImportFormat(
181 privEncryptionKeyBase58))
182 pubSigningKey = unhexlify(highlevelcrypto.privToPub(
183 privSigningKeyHex))
184 pubEncryptionKey = unhexlify(highlevelcrypto.privToPub(
185 privEncryptionKeyHex))
186
187 payload += pubSigningKey[1:]
188 payload += pubEncryptionKey[1:]
189
190 # Do the POW for this pubkey message
191 target = 2 ** 64 / (defaults.networkDefaultProofOfWorkNonceTrialsPerByte*(len(payload) + 8 + defaults.networkDefaultPayloadLengthExtraBytes + ((TTL*(len(payload)+8+defaults.networkDefaultPayloadLengthExtraBytes))/(2 ** 16))))
192 logger.info('(For pubkey message) Doing proof of work...')
193 initialHash = hashlib.sha512(payload).digest()
194 trialValue, nonce = proofofwork.run(target, initialHash)
195 logger.info('(For pubkey message) Found proof of work ' + str(trialValue), ' Nonce: ', str(nonce))
196 payload = pack('>Q', nonce) + payload
197
198 inventoryHash = calculateInventoryHash(payload)
199 objectType = 1
200 Inventory()[inventoryHash] = (
201 objectType, streamNumber, payload, embeddedTime,'')
202 PendingUpload().add(inventoryHash)
203
204 logger.info('broadcasting inv with hash: ' + hexlify(inventoryHash))
205

Callers 1

runMethod · 0.95

Calls 12

BMConfigParserClass · 0.90
InventoryClass · 0.90
PendingUploadClass · 0.90
decodeAddressFunction · 0.85
encodeVarintFunction · 0.85
calculateInventoryHashFunction · 0.85
addMethod · 0.80
putMethod · 0.80
setMethod · 0.80
getMethod · 0.45
runMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected