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

Function decodeAddress

src/addresses.py:149–239  ·  view source on GitHub ↗
(address)

Source from the content-addressed store, hash-verified

147 return 'BM-'+ encodeBase58(asInt)
148
149def decodeAddress(address):
150 #returns (status, address version number, stream number, data (almost certainly a ripe hash))
151
152 address = str(address).strip()
153
154 if address[:3] == 'BM-':
155 integer = decodeBase58(address[3:])
156 else:
157 integer = decodeBase58(address)
158 if integer == 0:
159 status = 'invalidcharacters'
160 return status,0,0,""
161 #after converting to hex, the string will be prepended with a 0x and appended with a L
162 hexdata = hex(integer)[2:-1]
163
164 if len(hexdata) % 2 != 0:
165 hexdata = '0' + hexdata
166
167 #print 'hexdata', hexdata
168
169 data = unhexlify(hexdata)
170 checksum = data[-4:]
171
172 sha = hashlib.new('sha512')
173 sha.update(data[:-4])
174 currentHash = sha.digest()
175 #print 'sha after first hashing: ', sha.hexdigest()
176 sha = hashlib.new('sha512')
177 sha.update(currentHash)
178 #print 'sha after second hashing: ', sha.hexdigest()
179
180 if checksum != sha.digest()[0:4]:
181 status = 'checksumfailed'
182 return status,0,0,""
183 #else:
184 # print 'checksum PASSED'
185
186 try:
187 addressVersionNumber, bytesUsedByVersionNumber = decodeVarint(data[:9])
188 except varintDecodeError as e:
189 logger.error(str(e))
190 status = 'varintmalformed'
191 return status,0,0,""
192 #print 'addressVersionNumber', addressVersionNumber
193 #print 'bytesUsedByVersionNumber', bytesUsedByVersionNumber
194
195 if addressVersionNumber > 4:
196 logger.error('cannot decode address version numbers this high')
197 status = 'versiontoohigh'
198 return status,0,0,""
199 elif addressVersionNumber == 0:
200 logger.error('cannot decode address version numbers of zero.')
201 status = 'versiontoohigh'
202 return status,0,0,""
203
204 try:
205 streamNumber, bytesUsedByStreamNumber = decodeVarint(data[bytesUsedByVersionNumber:])
206 except varintDecodeError as e:

Callers 15

_verifyAddressMethod · 0.90
HandleListAddressesMethod · 0.90
HandleDecodeAddressMethod · 0.90
sendMethod · 0.90
sendMethod · 0.90
__init__Method · 0.90
click_pushButtonSendMethod · 0.90
on_action_ForceSendMethod · 0.90
addressChangedMethod · 0.90
acceptMethod · 0.90

Calls 3

decodeBase58Function · 0.85
decodeVarintFunction · 0.85
updateMethod · 0.45

Tested by

no test coverage detected