예제 #1
0
def execute_api():
    request_data = request.get_data()
    print("Get request data ... %s" % (str(request_data)))

    request_command = json.loads(request_data)

    if request_command['command'] == "generate_address":
        address_result = generate_address()
        result = json.dumps(address_result, cls=IotaJSONEncoder)

    elif request_command['command'] == "get_tips":
        tips_result = get_tips(int(request_command['type']))
        result = json.dumps(tips_result, cls=IotaJSONEncoder)

    elif request_command['command'] == "send_transfer":
        if 'debug' not in request_command:
            debug = 0
        else:
            debug = int(request_command['debug'])

        dict_tips = get_tips(int(request_command['tips_type']))
        result = send_transfer(request_command['tag'],
                               request_command['message'],
                               request_command['address'],
                               int(request_command['value']), dict_tips, debug)
    else:
        result = extension_tangleid.load(request_data)

    print("Result ... %s" % (str(result)))

    return result
예제 #2
0
    def do_POST(self):

        request_path = self.path

        request_headers = self.headers
        content_length = request_headers.get("Content-length")
        length = int(content_length) if content_length else 0
        request_data = self.rfile.read(length)
        request_data = request_data.decode('utf-8')
        print("Get request data ... %s" % (str(request_data)))

        request_command = json.loads(request_data)

        if request_command['command'] == "generate_address":
            result = generate_address()
        elif request_command['command'] == "get_tips":
            result = get_tips(int(request_command['type']))
        elif request_command['command'] == "send_transfer":
            if 'debug' not in request_command:
                debug = 0
            else:
                debug = int(request_command['debug'])

            dict_tips = get_tips(int(request_command['tips_type']))
            result = send_transfer(
                request_command['tag'], request_command['message'], request_command['address'], int(
                    request_command['value']), dict_tips, debug)
        else:
            result = extension_tangleid.load(request_data)

        print("Result ... %s" % (str(result)))

        self._set_headers()
        self.wfile.write(str(result).encode('utf-8'))
예제 #3
0
def new_user(data):
    data = json.loads(data)

    # Get tips
    dict_tips = get_tips(0)

    # Set output transaction
    tag = data['uuid'] + "I"
    response = send_transfer(tag, json.dumps(data), address, 0, dict_tips, debug=0)

    return str(response)
예제 #4
0
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(0)

print 'Server start at: %s:%s' % (HOST, PORT)
print 'wait for connection...'
result = ""
while True:
    conn, addr = s.accept()
    print 'Connected by ', addr

    while True:
        data = conn.recv(1024)
        request_command = json.loads(data)

        print str(data)

        if request_command['command'] == "gen_a_address":
            result = gen_a_address()
        elif request_command['command'] == "get_tips":
            result = get_tips(int(request_command['type']))
        elif request_command['command'] == "send_transfer":
            dict_tips = get_tips(int(request_command['tips_type']))
            result = send_transfer(request_command['tag'], request_command['message'], \
                     request_command['address'], int(request_command['value']), dict_tips)

        conn.send(str(result))
        break

conn.close()