Example #1
0
class FSend:
    def __init__(self, config, index, jspath):
        self.index = index
        self.api = Iota(config.getNodeUrl(), config.getSeed())
        self.secLvl = config.getSecLvl()
        self.checksum = config.getChecksum()
        self.jspath = jspath
        self.owner = config.getOwner()

    # search for addresses with inputs
    def get_value_addresses(self):
        response = self.api.get_inputs(start=0, stop=self.index, security_level=self.secLvl)
        self.value_addresses = response['inputs']
        self.summary = response['totalBalance']
        if self.summary == 0:
            pass
        else:
            self.send_funds()

    # prepare tx and send funds
    def send_funds(self):
        tx = ProposedTransaction(
            address=Address(self.owner),
            message=TryteString.from_unicode('IOTAPay Device V1'),
            tag=Tag('IOTAPAYTRANSACTION'),
            value=self.summary
        )
        tx = self.api.prepare_transfer(transfers=[tx], inputs=self.value_addresses, change_address=self.owner)
        result = self.api.send_trytes(tx['trytes'], depth=3, min_weight_magnitude=14)
        print('Transaction with:', self.summary, 'iota sent to the tangle!')
Example #2
0
def sendTX(msg):
    '''
    PURPOSE:  send transaction to the Tangle

    INPUT:
        address from a seed different than the one in this script

    OUTPUT:
        TX to devnet
    '''
    seed = 'SEED99999999999999999999999999999999999999999999999999999999999999999999999999999'
    address = 'ADDRESS9FROM9DIFFERENT9SEED999999999999999999999999999999999999999999999999999999'
    api = Iota('https://nodes.devnet.iota.org:443', seed)
    tx = ProposedTransaction(address=Address(address),
                             message=TryteString.from_unicode(msg),
                             tag=Tag('YOURTAG'),
                             value=0)
    try:
        tx = api.prepare_transfer(transfers=[tx])
    except Exception as e:
        print("Check prepare_transfer ", e)
        raise
    try:
        result = api.send_trytes(tx['trytes'], depth=3, min_weight_magnitude=9)
    except:
        print("Check send_trytes")
Example #3
0
def on_message(client, userdata, msg):
    """ receiving data"""
    try:
        sensors = msg.payload
        sensors = json.loads(sensors.decode('utf-8'))
    except e:
        print("Check the message: ",e)

    logfile = open("enviro.csv", "a")
    print(sensors["timestamp"], ",",\
          sensors["device_name"], ",",\
          sensors["device_owner"], ",",\
          sensors["city"], ",",\
          sensors["lng"], ",",\
          sensors["lat"], ",",\
          sensors["lux"], ",",\
          sensors["rgb"], ",",\
          sensors["accel"], ",",\
          sensors["heading"], ",",\
          sensors["temperature"], ",",\
          sensors["pressure"], file=logfile)
    logfile.close()


    api = Iota('https://nodes.devnet.iota.org:443') 
    address = 'H9TJVEEAOAI9ADCFSRIKOYHNLVDIRDIIREXQUJNBIWBSINJIJXXDTPTRDOZRRSCUOLZAXVZNRHDCWVSVD'
    tx = ProposedTransaction(
        address=Address(address),
        #message=TryteString.from_unicode(sensors),
        message=TryteString.from_unicode(json.dumps(sensors)),
        tag=Tag('ENVIROPHATIII'),
        value=0
    )
    print(tx)
    try:
        tx = api.prepare_transfer(transfers=[tx])
    except:
        print("PREPARE EXCEPTION",tx)
    try:
        result = api.send_trytes(tx['trytes'], depth=3, min_weight_magnitude=9)
    except:
        print("EXCEPTION", result)

    print("\nTimestamp: ", sensors["timestamp"])
    print("Device: ", sensors["device_name"])
    print("Device owner email: ", sensors["device_owner"])
    print("Device location: ", sensors["city"], " at longitude: ", sensors["lng"], " and latitude: ", sensors["lat"])
    print("Light: ", sensors["lux"])
    print("RGB: ", sensors["rgb"])
    print("Accelerometer: ", sensors["accel"])
    print("Heading: ", sensors["heading"])
    print("Temperature: ", sensors["temperature"])
    print("Pressure: ", sensors["pressure"])

    return sensors
Example #4
0
def on_message(client, userdata, msg):
    """ receiving data"""

    try:
        sensors = msg.payload
        sensors = json.loads(sensors.decode('utf-8'))
    except e:
        print("Check the message: ", e)

    # this format stores data in CSV format in AstroPiOTA.log
    logfile = open("AstroPiOTA.csv", "a")
    print(str(sensors["timestamp"]),",",str(sensors["lng"]),",",\
        str(sensors["lat"]),",",str(sensors["device_name"]),",",str(sensors["temperature"]),",",\
        str(sensors["humidity"]),",",str(sensors["pressure"]),",",str(sensors["pitch"]),",",\
        str(sensors["roll"]),",",str(sensors["yaw"]),",",str(sensors["x"]),",",\
        str(sensors["y"]),",",str(sensors["z"]),",",str(sensors["device_owner"]),",",str(sensors["city"]),file=logfile)
    logfile.close()

    # this prints the AstroPiOTA data message
    print("\nTimestamp: ", str(sensors["timestamp"]))
    print("Device: ", sensors["device_name"])
    print("Device owner email: ", sensors["device_owner"])
    print("Device location: ", sensors["city"], " at longitude: ",
          sensors["lng"], " and latitude: ", sensors["lat"])

    print("Temperature: ", sensors["temperature"])
    print("Humidity: ", sensors["humidity"])
    print("Pressure: ", sensors["pressure"])

    print("Pitch: ", sensors["pitch"])
    print("Roll: ", sensors["roll"])
    print("Yaw: ", sensors["yaw"])

    print("Accelerometer x: ", sensors["x"])
    print("Accelerometer y: ", sensors["y"])
    print("Accelerometer z: ", sensors["z"])

    api = Iota('https://nodes.devnet.iota.org:443')
    address = '999999999999999999999999999999999999999999999999999999999999999999999999999999999'
    tx = ProposedTransaction(
        address=Address(address),
        #message=TryteString.from_unicode(sensors),
        message=TryteString.from_unicode(json.dumps(sensors)),
        tag=Tag('ASTROPIOTAIIIDEMO'),
        value=0)
    print(tx)
    try:
        tx = api.prepare_transfer(transfers=[tx])
    except:
        print("PREPARE EXCEPTION", tx)
    try:
        result = api.send_trytes(tx['trytes'], depth=3, min_weight_magnitude=9)
    except:
        print("EXCEPTION", result)
def sendTX(msg):
    seed = 'YOURSEED9999999999999999999999999999999999999999999999999999999999999999999999999'
    address = 'ADDRESS9FROM9DIFFERENT9SEED999999999999999999999999999999999999999999999999999999'
    api = Iota('https://nodes.devnet.iota.org:443', seed)
    tx = ProposedTransaction(address=Address(address),
                             message=TryteString.from_unicode(msg),
                             tag=Tag('ASTROPIOTA'),
                             value=0)
    try:
        tx = api.prepare_transfer(transfers=[tx])
    except Exceptaion as e:
        print("Check prepare_transfer ", e)
        raise
    try:
        result = api.send_trytes(tx['trytes'], depth=3, min_weight_magnitude=9)
    except:
        print("Check send_trytes")
Example #6
0
    def test_wireup(self):
        """
    Verify that the command is wired up correctly.

    The API method indeed calls the appropiate command.
    """
        with patch(
                'iota.commands.extended.send_trytes.SendTrytesCommand.__call__',
                MagicMock(return_value='You found me!')) as mocked_command:

            api = Iota(self.adapter)

            # Don't need to call with proper args here.
            response = api.send_trytes('trytes')

            self.assertTrue(mocked_command.called)

            self.assertEqual(response, 'You found me!')
1 iota will be transfered to the given address
'''

from iota import Iota
from iota import ProposedTransaction
from iota import Address
from iota import Tag
from iota import TryteString

# This is a demonstration seed, always generate your own seed!
seed = 'EDFCUGAMUKFUTSNERKXBVFTMRPGQRLFMYOHHSVCYDTZRJWULKHKRTGCEUMPD9NPFGWFTRTKLQSQRWZDMY'

# The address to send 1i
address = 'FEEDTHESHEEP999999999999999999999999999999999999999999999999999999999999999999999'

# Since we are sending value we need a seed to sign the transaction
api = Iota('https://nodes.devnet.iota.org:443', seed)

tx = ProposedTransaction(
    address=Address(address),
    message=TryteString.from_unicode('This transaction should include 1i!'),
    tag=Tag('VALUETX'),
    value=1)

tx = api.prepare_transfer(transfers=[tx])

result = api.send_trytes(tx['trytes'], depth=3, min_weight_magnitude=9)

print('Transaction sent to the tangle!')
print('https://devnet.thetangle.org/address/%s' % address)
Example #8
0
from iota import (
    __version__,
    Address,
    Iota,
    ProposedTransaction,
    Tag,
    TryteString,
)
from six import text_type

api = Iota('http://localhost:14265')
txn_2 =\
  ProposedTransaction(
    address =
      Address(
        b'FJHSSHBZTAKQNDTIKJYCZBOZDGSZANCZSWCNWUOCZXFADNOQSYAHEJPXRLOVPNOQFQXXGEGVDGICLMOXX'
      ),

    message = TryteString.from_unicode('thx fur cheezburgers'),
    tag     = Tag(b'KITTEHS'),
    value   = 0,
)

c = api.prepare_transfer([txn_2])["trytes"]

K = api.send_trytes(depth=3, trytes=c, min_weight_magnitude=9)
print('Transfer complete.')
print(c)
print('\n')
print(K["trytes"])
Example #9
0
from iota import Iota
from iota import ProposedTransaction
from iota import Address
from iota import Tag
from iota import TryteString
import sys
import json

with open('config.json', 'r') as f:
    data = json.load(f)
    url = data['url']
# returns JSON object as a dictionary
api = Iota(url, testnet=True)
address = 'ZLGVEQ9JUZZWCZXLWVNTHBDX9G9KZTJP9VEERIIFHY9SIQKYBVAHIMLHXPQVE9IXFDDXNHQINXJDRPFDXNYVAPLZAW'
message = TryteString.from_unicode('Hello world')
tx = ProposedTransaction(address=Address(address), message=message, value=0)

num = 1
if len(sys.argv) == 2:
    num = int(sys.argv[1])

for i in range(num):
    result = api.send_transfer(transfers=[tx])
    print(result['bundle'].tail_transaction.hash)
    print("tx:", tx)
    tx_trytes = api.prepare_transfer(transfers=[tx])
    resp_sendTrytes = api.send_trytes(trytes=tx_trytes['trytes'])

    print(resp_sendTrytes)