コード例 #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!')
コード例 #2
0
def transfer(address, tag, message, value):
    recipient_address = address
    sender_message = message
    sender_tag = tag

    prepared_transferes = []
    api = Iota(URL_NODE, SEED)

    sender_tag = bytes(sender_tag)
    transfer_value = int(value)

    txn = \
        ProposedTransaction(
            address = Address(
                recipient_address
        ),

        message = TryteString.from_string(sender_message),
        tag = Tag(sender_tag),
        value = transfer_value,
    )

    prepared_transferes.append(txn)

    dict_raw_trytes_tx = api.prepare_transfer(prepared_transferes)
    len_tx = len(dict_raw_trytes_tx['trytes'])
    for index in range(len_tx):
        print str(dict_raw_trytes_tx['trytes'][index])

    return True
コード例 #3
0
ファイル: sendTX.py プロジェクト: NelsonPython/Air_MacClean
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")
コード例 #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)

    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
コード例 #5
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)
コード例 #6
0
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")
コード例 #7
0
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)
コード例 #8
0
    ),
    Address(
        b'NDGHOGDRXEXNFQOW9XQIYKYAUIEZMTZDQMPEQTSDHTQEKCIYYANZMGDOJBSRCNT9RBC9CJDTBVBFDQF99'
    ),
    Address(
        b'NZRHABYULAZM9KEXRQODGUZBLURTOKSGWWMOPIAJSTJFVAHNCCMJSVULRKGD9PLBMKOEGBNZRJHQSVVCA'
    ),
    Address(
        b'EECOCPAECTETNWT9ERFUJCFXQWRVXFZDWHSPSOOSLTDKKNYSVKTVZJASDV9HAYTNZSQIW99JLUYLQSFMY'
    )
]

# Prepare the original bundle
original_trytes = api.prepare_transfer(transfers=[
    ProposedTransaction(address=addys[0], value=0),
    ProposedTransaction(address=addys[1], value=0),
    ProposedTransaction(address=addys[2], value=0),
    ProposedTransaction(address=addys[3], value=0),
]).get('trytes')

gtta_response = api.get_transactions_to_approve(3)

trunk = gtta_response.get('trunkTransaction')
branch = gtta_response.get('branchTransaction')

attached_original_trytes = api.attach_to_tangle(trunk, branch,
                                                original_trytes).get('trytes')

# So we have the original bundle attached, time to construct the new one
# We need to re-attach, but take special care, so we dont use the api, rather we do it ourself

re_attached_trytes = custom_attach(attached_original_trytes, 9)
コード例 #9
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"])
コード例 #10
0
import time
import logging
import sys
sys.path.append(
    "/home/pi/.local/lib/python2.7/site-packages"
)  #path muss hinzugefügt werden damit PyOta librarys gefunden werden können

from iota import Iota, ProposedTransaction, ProposedBundle, Address, Tag, TryteString  #importe Iota-Bibliothek um die API anzusprechen
from iota.crypto.addresses import AddressGenerator

# Reciever Seed: GCUKFZRLCTBGBDKQCQY9SMJPDPLFBDJJFTXZANHDJUTCZKIQQEUHSAVOYWKPTDDNEWRGBFWDMWYYRLRUR
# returned Address at index 0 for Security Level 2
reciever_address = "LOZMZOKJWWVASYYWT999JPLDBMUSFZKMLZW9IXHTOAUOQKZMRLRAZCWECAFONWKT9HSHKHLMKAWSQFFXX"

seed = "DSPOAXMVSC99IUIVJXTIBZFATVFKTCLLJYOLAGSMFJGFXAWEB9GNTQWEDVRYHKIOQF9T9IZY9IVPKTSZK"
url = "https://potato.iotasalad.org:14265"  #fullnode url
api = Iota(url, seed)  #erstelle Iota API
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
logger = logging.getLogger(__name__)
api.adapter.set_logger(logger)

proposedTrx = ProposedTransaction(
    address=Address(reciever_address),
    value=0,
    tag=Tag("BACHELORTEST"),
    message=TryteString.from_string("This is a test transaction"))

proposedBundle = ProposedBundle([proposedTrx])
preparedBundle = api.prepare_transfer(proposedBundle)
publishedBundle = api.send_transfer(depth=3, transfers=proposedBundle)
コード例 #11
0
 def send_trytes(self):
     api = Iota(adapter="http://localhost:14265", testnet=True)
     tx_trytes = api.prepare_transfer(transfers=[self.tx])
     resp_sendTrytes = self.client.send_trytes(trytes=tx_trytes['trytes'])
コード例 #12
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)
コード例 #13
0
api = Iota(
    adapter=url,
    seed=my_seed,
    testnet=True,
)

# Addres to receive 1i
# Feel free to replace it. For example, run the code from Tutorial 4.a
# and use that newly generated address with a 'fresh' seed.
receiver = Address(
    b'VEMEG9EZGAVAEXLAPEFJ9KJDHDDNHPNS9OGMCHDGXGRDLHNZ9YGFMQ9ZYDAZJZKIMZIOPXPNIKBQDCLLY'
)

# print('Constructing transfer of 1i...')

tx = ProposedTransaction(
    address=receiver,
    value=10000,
    message=TryteString.from_unicode('I just sent you 100i, use it wisely!'),
    tag=Tag('VALUETX'),
)

input = api.get_inputs(start=0, stop=10)
print(input)

inputs = input['inputs']
tx = api.prepare_transfer(transfers=[tx], inputs=inputs)

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

print(result)