Added API Function: getStatus
This commit is contained in:
parent
05c49a31cd
commit
a4beb436a4
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
import xmlrpclib
|
import xmlrpclib
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
api = xmlrpclib.ServerProxy("http://bradley:password@localhost:8442/")
|
api = xmlrpclib.ServerProxy("http://bradley:password@localhost:8442/")
|
||||||
|
|
||||||
|
@ -45,12 +46,16 @@ print 'Uncomment this next line to decode the actual message data in the first m
|
||||||
print 'Uncomment this next line in the code to delete a message'
|
print 'Uncomment this next line in the code to delete a message'
|
||||||
#print api.trashMessage('584e5826947242a82cb883c8b39ac4a14959f14c228c0fbe6399f73e2cba5b59')
|
#print api.trashMessage('584e5826947242a82cb883c8b39ac4a14959f14c228c0fbe6399f73e2cba5b59')
|
||||||
|
|
||||||
"""print 'Now let\'s send a message. The example addresses are invalid. You will have to put your own in.'
|
print 'Uncomment these lines to send a message. The example addresses are invalid; you will have to put your own in.'
|
||||||
subject = 'subject!'.encode('base64')
|
#subject = 'subject!'.encode('base64')
|
||||||
message = 'Hello, this is the message'.encode('base64')
|
#message = 'Hello, this is the message'.encode('base64')
|
||||||
print api.sendMessage('BM-oqmocYzqK74y3qSRi8c3YqyenyEKiMyLB', 'BM-omzGU4MtzSUCQhMNm5kPR6UNrJ4Q4zeFe', subject,message)"""
|
#ackData = api.sendMessage('BM-Gtsm7PUabZecs3qTeXbNPmqx3xtHCSXF', 'BM-2DCutnUZG16WiW3mdAm66jJUSCUv88xLgS', subject,message)
|
||||||
|
#print 'The ackData is:', ackData
|
||||||
|
#while True:
|
||||||
|
# time.sleep(2)
|
||||||
|
# print 'Current status:', api.getStatus(ackData)
|
||||||
|
|
||||||
"""print 'Now let\'s send a broadcast. The example address is invalid; you will have to put your own in.'
|
print 'Uncomment these lines to send a broadcast. The example address is invalid; you will have to put your own in.'
|
||||||
subject = 'subject within broadcast'.encode('base64')
|
#subject = 'subject within broadcast'.encode('base64')
|
||||||
message = 'Hello, this is the message within a broadcast.'.encode('base64')
|
#message = 'Hello, this is the message within a broadcast.'.encode('base64')
|
||||||
print api.sendBroadcast('BM-onf6V1RELPgeNN6xw9yhpAiNiRexSRD4e', subject,message)"""
|
#print api.sendBroadcast('BM-onf6V1RELPgeNN6xw9yhpAiNiRexSRD4e', subject,message)
|
|
@ -3496,20 +3496,20 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
elif len(params) == 5:
|
elif len(params) == 5:
|
||||||
passphrase, numberOfAddresses, addressVersionNumber, streamNumber, eighteenByteRipe = params
|
passphrase, numberOfAddresses, addressVersionNumber, streamNumber, eighteenByteRipe = params
|
||||||
if len(passphrase) == 0:
|
if len(passphrase) == 0:
|
||||||
return 'API Error 0001: the specified passphrase is blank.'
|
return 'API Error 0001: The specified passphrase is blank.'
|
||||||
passphrase = passphrase.decode('base64')
|
passphrase = passphrase.decode('base64')
|
||||||
if addressVersionNumber == 0: #0 means "just use the proper addressVersionNumber"
|
if addressVersionNumber == 0: #0 means "just use the proper addressVersionNumber"
|
||||||
addressVersionNumber = 3
|
addressVersionNumber = 3
|
||||||
if addressVersionNumber != 3:
|
if addressVersionNumber != 3:
|
||||||
return 'API Error 0002: the address version number currently must be 3 (or 0 which means auto-select).', addressVersionNumber,' isn\'t supported.'
|
return 'API Error 0002: The address version number currently must be 3 (or 0 which means auto-select).', addressVersionNumber,' isn\'t supported.'
|
||||||
if streamNumber == 0: #0 means "just use the most available stream"
|
if streamNumber == 0: #0 means "just use the most available stream"
|
||||||
streamNumber = 1
|
streamNumber = 1
|
||||||
if streamNumber != 1:
|
if streamNumber != 1:
|
||||||
return 'API Error 0003: the stream number must be 1 (or 0 which means auto-select). Others aren\'t supported.'
|
return 'API Error 0003: The stream number must be 1 (or 0 which means auto-select). Others aren\'t supported.'
|
||||||
if numberOfAddresses == 0:
|
if numberOfAddresses == 0:
|
||||||
return 'API Error 0004: Why would you ask me to generate 0 addresses for you?'
|
return 'API Error 0004: Why would you ask me to generate 0 addresses for you?'
|
||||||
if numberOfAddresses > 9999:
|
if numberOfAddresses > 999:
|
||||||
return 'API Error 0005: You have (accidentially?) specified too many addresses to make. Maximum 9999. This check only exists to prevent mischief; if you really want to create more addresses than this, contact the Bitmessage developers and we can modify the check or you can do it yourself by searching the source code for this message.'
|
return 'API Error 0005: You have (accidentally?) specified too many addresses to make. Maximum 999. This check only exists to prevent mischief; if you really want to create more addresses than this, contact the Bitmessage developers and we can modify the check or you can do it yourself by searching the source code for this message.'
|
||||||
apiAddressGeneratorReturnQueue.queue.clear()
|
apiAddressGeneratorReturnQueue.queue.clear()
|
||||||
print 'Requesting that the addressGenerator create', numberOfAddresses, 'addresses.'
|
print 'Requesting that the addressGenerator create', numberOfAddresses, 'addresses.'
|
||||||
#apiSignalQueue.put(('createDeterministicAddresses',(passphrase, numberOfAddresses, addressVersionNumber, streamNumber, eighteenByteRipe)))
|
#apiSignalQueue.put(('createDeterministicAddresses',(passphrase, numberOfAddresses, addressVersionNumber, streamNumber, eighteenByteRipe)))
|
||||||
|
@ -3574,9 +3574,9 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
if status == 'versiontoohigh':
|
if status == 'versiontoohigh':
|
||||||
return 'API Error 0010: Address version number too high (or zero) in address: ' + toAddress
|
return 'API Error 0010: Address version number too high (or zero) in address: ' + toAddress
|
||||||
if addressVersionNumber < 2 or addressVersionNumber > 3:
|
if addressVersionNumber < 2 or addressVersionNumber > 3:
|
||||||
return 'API Error 0011: the address version number currently must be 2 or 3. Others aren\'t supported. Check the toAddress.'
|
return 'API Error 0011: The address version number currently must be 2 or 3. Others aren\'t supported. Check the toAddress.'
|
||||||
if streamNumber != 1:
|
if streamNumber != 1:
|
||||||
return 'API Error 0012: the stream number must be 1. Others aren\'t supported. Check the toAddress.'
|
return 'API Error 0012: The stream number must be 1. Others aren\'t supported. Check the toAddress.'
|
||||||
status,addressVersionNumber,streamNumber,fromRipe = decodeAddress(fromAddress)
|
status,addressVersionNumber,streamNumber,fromRipe = decodeAddress(fromAddress)
|
||||||
if status <> 'success':
|
if status <> 'success':
|
||||||
shared.printLock.acquire()
|
shared.printLock.acquire()
|
||||||
|
@ -3589,17 +3589,17 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
if status == 'versiontoohigh':
|
if status == 'versiontoohigh':
|
||||||
return 'API Error 0010: Address version number too high (or zero) in address: ' + fromAddress
|
return 'API Error 0010: Address version number too high (or zero) in address: ' + fromAddress
|
||||||
if addressVersionNumber < 2 or addressVersionNumber > 3:
|
if addressVersionNumber < 2 or addressVersionNumber > 3:
|
||||||
return 'API Error 0011: the address version number currently must be 2 or 3. Others aren\'t supported. Check the fromAddress.'
|
return 'API Error 0011: The address version number currently must be 2 or 3. Others aren\'t supported. Check the fromAddress.'
|
||||||
if streamNumber != 1:
|
if streamNumber != 1:
|
||||||
return 'API Error 0012: the stream number must be 1. Others aren\'t supported. Check the fromAddress.'
|
return 'API Error 0012: The stream number must be 1. Others aren\'t supported. Check the fromAddress.'
|
||||||
toAddress = addBMIfNotPresent(toAddress)
|
toAddress = addBMIfNotPresent(toAddress)
|
||||||
fromAddress = addBMIfNotPresent(fromAddress)
|
fromAddress = addBMIfNotPresent(fromAddress)
|
||||||
try:
|
try:
|
||||||
fromAddressEnabled = shared.config.getboolean(fromAddress,'enabled')
|
fromAddressEnabled = shared.config.getboolean(fromAddress,'enabled')
|
||||||
except:
|
except:
|
||||||
return 'API Error 0013: could not find your fromAddress in the keys.dat file.'
|
return 'API Error 0013: Could not find your fromAddress in the keys.dat file.'
|
||||||
if not fromAddressEnabled:
|
if not fromAddressEnabled:
|
||||||
return 'API Error 0014: your fromAddress is disabled. Cannot send.'
|
return 'API Error 0014: Your fromAddress is disabled. Cannot send.'
|
||||||
|
|
||||||
ackdata = OpenSSL.rand(32)
|
ackdata = OpenSSL.rand(32)
|
||||||
shared.sqlLock.acquire()
|
shared.sqlLock.acquire()
|
||||||
|
@ -3679,7 +3679,31 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
shared.workerQueue.put(('sendbroadcast',(fromAddress,subject,message)))
|
shared.workerQueue.put(('sendbroadcast',(fromAddress,subject,message)))
|
||||||
|
|
||||||
return ackdata.encode('hex')
|
return ackdata.encode('hex')
|
||||||
|
elif method == 'getStatus':
|
||||||
|
if len(params) != 1:
|
||||||
|
return 'API Error 0000: I need one parameter!'
|
||||||
|
ackdata, = params
|
||||||
|
if len(ackdata) != 64:
|
||||||
|
return 'API Error 0015: The length of ackData should be 32 bytes (encoded in hex thus 64 characters).'
|
||||||
|
shared.sqlLock.acquire()
|
||||||
|
shared.sqlSubmitQueue.put('''SELECT status FROM sent where ackdata=?''')
|
||||||
|
shared.sqlSubmitQueue.put((ackdata.decode('hex'),))
|
||||||
|
queryreturn = shared.sqlReturnQueue.get()
|
||||||
|
shared.sqlLock.release()
|
||||||
|
if queryreturn == []:
|
||||||
|
return 'notFound'
|
||||||
|
for row in queryreturn:
|
||||||
|
status, = row
|
||||||
|
if status == 'findingpubkey':
|
||||||
|
return 'findingPubkey'
|
||||||
|
if status == 'doingpow':
|
||||||
|
return 'doingPow'
|
||||||
|
if status == 'sentmessage':
|
||||||
|
return 'sentMessage'
|
||||||
|
if status == 'ackreceived':
|
||||||
|
return 'ackReceived'
|
||||||
|
else:
|
||||||
|
return 'otherStatus: '+status
|
||||||
else:
|
else:
|
||||||
return 'Invalid Method: %s'%method
|
return 'Invalid Method: %s'%method
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user