Ejemplo n.º 1
0
    def test_decode(self):
        """
    Converting a sequence of trytes into a Unicode string.
    """
        trytes = TryteString(b'LH9GYEMHCF9GWHZFEELHVFOEOHNEEEWHZFUD')

        self.assertEqual(trytes.decode(), '你好,世界!')
Ejemplo n.º 2
0
    def test_decode_strip(self):
        """
    Strip trailing padding from a TryteString before converting.
    """
        # Note odd number of trytes!
        trytes = TryteString(
            b'LH9GYEMHCF9GWHZFEELHVFOEOHNEEEWHZFUD9999999999999')

        self.assertEqual(trytes.decode(), '你好,世界!')
Ejemplo n.º 3
0
    def test_decode_no_strip(self):
        """
    Prevent stripping trailing padding when converting to string.
    """
        trytes = TryteString(
            b'LH9GYEMHCF9GWHZFEELHVFOEOHNEEEWHZFUD999999999999')

        self.assertEqual(
            trytes.decode(strip_padding=False),
            '你好,世界!\x00\x00\x00\x00\x00\x00',
        )
Ejemplo n.º 4
0
def run(address, hostname, port):

    dataset = {}

    print 'Using IOTA light node %s:%s' % (hostname, port)
    print 'Finding transactions from address %s' % address

    command = {
        'command': 'findTransactions',
        'addresses': [address[:-9]]
    }

    stringified = json.dumps(command)

    request = urllib2.Request(url="%s:%s" % (hostname, port), data=stringified, headers=headers)
    returnData = urllib2.urlopen(request).read()
    jsonData = json.loads(returnData)
    if 'hashes' in jsonData:

        print 'Transactions found, retrieving last 10...'

        command = {
            'command': 'getTrytes',
            'hashes': jsonData['hashes'][-10:]
        }

        stringified = json.dumps(command)

        request = urllib2.Request(url="%s:%s" % (hostname, port), data=stringified, headers=headers)
        returnData = urllib2.urlopen(request).read()
        jsonData = json.loads(returnData)
        tx_count = 1
        if 'trytes' in jsonData:
            num_tx = len(jsonData['trytes'])
            for tryte in jsonData['trytes']:
                tx = Transaction.from_tryte_string(tryte)
                enc_message = TryteString(tx.signature_message_fragment)
                epoch = datetime.datetime.fromtimestamp(float(tx.attachment_timestamp)/1000.)
                fmt = "%Y-%m-%d %H:%M:%S"
                timestamp = epoch.strftime(fmt)
                try:
                    data = json.loads(enc_message.decode())
                except ValueError:
                    # Decoding seems to blow up every so often.
                    pass
                # These are specific to my mqtt data stream, need to make this more flexible.
                if 'topic' in data and 'mcutemp' in data:
                    dataset[timestamp] = {'device': data['topic'], 'temp': data['mcutemp'], 'tx': tx.hash}
                    print 'Fetching transaction %s of %s ...' % (tx_count, num_tx)
                    tx_count += 1
        sorted_data = OrderedDict(sorted(dataset.items(), key=lambda x: parse(x[0])))
        for value in sorted(sorted_data.keys(), reverse=True):
            print '%s %s' % (value, sorted_data[value])
Ejemplo n.º 5
0
def verify_tangle(iota, tasks):
    txn_list = iota.find_transactions()

    txn_all_msg = []

    # TODO: check value
    for txn in iota.get_info_transactions(txn_list):
        confirmed_t, addr_t, value_t, tag_t, msg_t = txn

        t = TryteString(tag_t)
        tag = t.decode()

        if tasks.check_tag(tag):
            m = TryteString(msg_t)
            msg = m.decode()

            print 'Found task: ', tag

            tasks.add_task(tag, msg)
        else:
            print 'No new tasks...'
Ejemplo n.º 6
0
def trytes_to_ascii(trytes):
	message = ''
	value=''
	timestamp=''
	tag=''
	for m in range(2,2188):
		message = TryteString(message + trytes[m])		
	for l in range(2270,2297):
		value = TryteString(value + trytes[l])
	for n in range(2594,2621):
		tag = TryteString(tag + trytes[n])
	for o in range(2324,2333):
		timestamp = TryteString(timestamp + trytes[o])
	return message.decode(),tag,int(int_from_trits(value.as_trits())),int(int_from_trits(timestamp.as_trits()))
Ejemplo n.º 7
0
def get_message(txHash):

    print 'Fetching TX details...\n'

    command = {'command': 'getTrytes', 'hashes': [tx_hash]}

    stringified = json.dumps(command)

    headers = {'content-type': 'application/json', 'X-IOTA-API-Version': '1'}

    request = urllib2.Request(url="https://iota-3.de:14267",
                              data=stringified,
                              headers=headers)
    returnData = urllib2.urlopen(request).read()

    jsonData = json.loads(returnData)

    txtrytes = jsonData['trytes'][0][0:2187]

    trytes = TryteString(bytes(txtrytes))
    message = trytes.decode()

    return message
Ejemplo n.º 8
0
 def to_text(data):
     data = TryteString.decode(data)
     return str(data)