Exemplo n.º 1
0
 def test_deserialize_non_first_from_json(self):
     json_ser = '{"i": "1000", "t": "w]8f<vRG}fayY4]vRG}fayYm#vRG}fayYnc", "c": 1}'
     segment = TxTennaSegment.deserialize_from_json(json_ser)
     assert segment.payload_id == "1000"
     assert segment.sequence_num == 1
     assert segment.segment_count is None
     assert segment.testnet is False
     assert segment.payload == "w]8f<vRG}fayY4]vRG}fayYm#vRG}fayYnc"
Exemplo n.º 2
0
    def handle_cbor_message(self, sender_gid, protocol_msg):

        # TODO: 1a) concatonate segments and send as new transaction to block explorer 
        # TODO: 1b) send acknowledgement back to Signal Mesh as a text message
        # TODO: 2a) monitor for transaction to be confirmed in a block
        # TODO: 2b) send blockchain confirmation back to Signal Mesh as a text message

        txtenna_json = self.cbor_to_txtenna_json(protocol_msg)
        segment = TxTennaSegment.deserialize_from_json(txtenna_json)
        self.segment_storage.put(segment)
        network = self.segment_storage.get_network(segment.payload_id)

        ## process incoming transaction confirmation from another server
        if (segment.block != None):
            if (segment.block > 0):
                print("\nTransaction " + segment.payload_id + " confirmed in block " + str(segment.block))
            elif (segment.block is 0):
                print("\nTransaction " + segment.payload_id + " added to the the mem pool")
        elif (network is 'd'):
            ## process message data
            if (self.segment_storage.is_complete(segment.payload_id)):
                filename = self.segment_storage.get_transaction_id(segment.payload_id)
                t = Thread(target=self.receive_message_from_gateway, args=(filename,))
                t.start()
        else:
            ## process incoming tx segment
            if not self.local_bitcoind :
                headers = {u'content-type': u'application/json'}
                url = "https://api.samouraiwallet.com/v2/txtenna/segments" ## default txtenna-server
                r = requests.post(url, headers= headers, data=txtenna_json)
                print(r.text)

            if (self.segment_storage.is_complete(segment.payload_id)):
                # sender_gid = message.sender.gid_val
                tx_id = self.segment_storage.get_transaction_id(segment.payload_id)

                ## check for confirmed transaction in a new thread
                if (self.local_bitcoind) :
                    t = Thread(target=self.confirm_bitcoin_tx_local, args=(tx_id, sender_gid))
                else :
                    t = Thread(target=self.confirm_bitcoin_tx_online, args=(tx_id, sender_gid, network))
                t.start()
Exemplo n.º 3
0
    def handle_message(self, message):
        """ handle a txtenna message received over the mesh network

        Usage: handle_message message
        """
        payload = str(message.payload.message)
        print("received transaction payload: " + payload)

        segment = TxTennaSegment.deserialize_from_json(payload)
        self.segment_storage.put(segment)
        network = self.segment_storage.get_network(segment.payload_id)

        ## process incoming transaction confirmation from another server
        if (segment.block > 0):
            print("\nTransaction " + segment.payload_id + " confirmed in block " + str(segment.block))
        elif (segment.block is 0):
            print("\nTransaction " + segment.payload_id + " added to the the mem pool")
        elif (network is 'd'):
            ## process message data
            if (self.segment_storage.is_complete(segment.payload_id)):
                filename = self.segment_storage.get_transaction_id(segment.payload_id)
                t = Thread(target=self.receive_message_from_gateway, args=(filename,))
                t.start()
        else:
            ## process incoming tx segment
            if not self.local :
                headers = {u'content-type': u'application/json'}
                url = "https://api.samouraiwallet.com/v2/txtenna/segments" ## default txtenna-server
                r = requests.post(url, headers= headers, data=payload)
                print(r.text)

            if (self.segment_storage.is_complete(segment.payload_id)):
                sender_gid = message.sender.gid_val
                tx_id = self.segment_storage.get_transaction_id(segment.payload_id)

                ## check for confirmed transaction in a new thread
                if (self.local) :
                    t = Thread(target=self.confirm_bitcoin_tx_local, args=(tx_id, sender_gid))
                else :
                    t = Thread(target=self.confirm_bitcoin_tx_online, args=(tx_id, sender_gid, network))
                t.start()
Exemplo n.º 4
0
 def test_deserialize_invalid_segment_raises_exception(self):
     json_ser = '{"i": "1000", "t": "w]8f<vRG}fayY4]vRG}fayYm#vRG}fayYnc", "s": 1, "h": "123abc", "c": 1}'
     with pytest.raises(AttributeError):
         TxTennaSegment.deserialize_from_json(json_ser)