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

Function sendBrd

src/bitmessagecli.py:815–888  ·  view source on GitHub ↗
(fromAddress, subject, message)

Source from the content-addressed store, hash-verified

813
814
815def sendBrd(fromAddress, subject, message): #sends a broadcast
816 global usrPrompt
817 if (fromAddress == ''):
818
819 try:
820 jsonAddresses = json.loads(api.listAddresses())
821 numAddresses = len(jsonAddresses['addresses']) #Number of addresses
822 except:
823 print '\n Connection Error\n'
824 usrPrompt = 0
825 main()
826
827 if (numAddresses > 1): #Ask what address to send from if multiple addresses
828 found = False
829 while True:
830 fromAddress = userInput("\nEnter an Address or Address Label to send from.")
831
832 if fromAddress == "exit":
833 usrPrompt = 1
834 main()
835
836 for addNum in range (0, numAddresses): #processes all of the addresses
837 label = jsonAddresses['addresses'][addNum]['label']
838 address = jsonAddresses['addresses'][addNum]['address']
839 #stream = jsonAddresses['addresses'][addNum]['stream']
840 #enabled = jsonAddresses['addresses'][addNum]['enabled']
841 if (fromAddress == label): #address entered was a label and is found
842 fromAddress = address
843 found = True
844 break
845
846 if (found == False):
847 if(validAddress(fromAddress)== False):
848 print '\n Invalid Address. Please try again.\n'
849
850 else:
851 for addNum in range (0, numAddresses): #processes all of the addresses
852 #label = jsonAddresses['addresses'][addNum]['label']
853 address = jsonAddresses['addresses'][addNum]['address']
854 #stream = jsonAddresses['addresses'][addNum]['stream']
855 #enabled = jsonAddresses['addresses'][addNum]['enabled']
856 if (fromAddress == address): #address entered was a found in our addressbook.
857 found = True
858 break
859
860 if (found == False):
861 print '\n The address entered is not one of yours. Please try again.\n'
862
863 if (found == True):
864 break #Address was found
865
866 else: #Only one address in address book
867 print '\n Using the only address in the addressbook to send from.\n'
868 fromAddress = jsonAddresses['addresses'][0]['address']
869
870 if (subject == ''):
871 subject = userInput("Enter your Subject.")
872 subject = subject.encode('base64')

Callers 1

UIFunction · 0.85

Calls 6

userInputFunction · 0.85
validAddressFunction · 0.85
attachmentFunction · 0.85
sendBroadcastMethod · 0.80
mainFunction · 0.70
encodeMethod · 0.45

Tested by

no test coverage detected