Пример #1
0
def create_music_tokens():
    global admin_account

    #
    # Need to create/use an account to create the token.
    #
    api = nexus.sdk_init("admin-admin", "password", "1234")
    admin_account = api
    login = api.nexus_users_login_user()
    if (login.has_key("error")):
        create = api.nexus_users_create_user()
        if (create.has_key("error")):
            if (api.nexus_users_login_user().has_key("error")):
                print "Account create for 'admin' failed, exit"
                exit(1)
            #endif
        #endif
        print "Created user account 'admin'"
        sleep()
        login = api.nexus_users_login_user()
    #endif
    print "User account 'admin' logged in"

    #
    # Create the token if it does not exist.
    #
    get = api.nexus_tokens_get_token_by_name("music-token")
    if (get.has_key("error")):
        create = api.nexus_tokens_create_token("music-token", 1000)
        if (create.has_key("error")):
            r = create["error"]["message"]
            print "tokens/create token failed, {}".format(r)
            exit(1)
        #endif
        print "Created 1000 music tokens"
        sleep()
    #endif

    #
    # Move some tokens to the 'admin' account. Create a token account first.
    #
    admin = "admin-admin"
    get = api.nexus_tokens_get_account_by_name(admin)
    if (get.has_key("error") == False):
        b = get["result"]["balance"]
        print "Token account 'admin' exists, balance is {} tokens".format(b)
    else:
        create = api.nexus_tokens_create_account(admin, "music-token")
        if (create.has_key("error")):
            r = create["error"]["message"]
            print "tokens/create token account failed, {}".format(r)
            exit(1)
        #endif
        sleep()
        debit = api.nexus_tokens_debit_token_by_name("music-token", admin, 100)
        if (debit.has_key("error")):
            r = debit["error"]["message"]
            print "tokens/debit failed for 'admin', {}".format(r)
            exit(1)
Пример #2
0
def login():
    global contexts

    user = bottle.request.forms.get("username")
    pw = bottle.request.forms.get("password")
    pin = bottle.request.forms.get("pin")
    action = bottle.request.forms.get("action")
    create_account = (action == "Create User Account")

    if (user == ""):
        msg = "{} failed for empty username".format(action)
        return (show_html.format(bold(msg)))
    #endif

    api = nexus.sdk_init(user, pw, pin)
    if (create_account):
        status = api.nexus_users_create_user()
        if (status.has_key("error")):
            reason = status["error"]["message"]
            msg = "User account creation failed for username '{}', {}". \
                format(user, reason)
            return (show_html.format(bold(msg)))
        #endif
    #endif

    sleep()

    status = api.nexus_users_login_user()
    if (status.has_key("error")):
        reason = status["error"]["message"]
        msg = "Login failed for username '{}', {}".format(user, reason)
        return (show_html.format(bold(msg)))
    #endif

    genesis = status["result"]["genesis"]
    sid = status["result"]["session"]
    contexts[sid] = api

    f = allocate_qrcode(genesis, "genid")
    sl = get_sigchain_length(api)

    claims = check_notifications(api, sid)

    output = login_html.format(f, user, genesis, sl, claims, sid, sid, sid,
                               sid, sid, sid)
    return (output)
Пример #3
0
def login():
    global contexts

    user = bottle.request.forms.get("username")
    pw = bottle.request.forms.get("password")
    pin = bottle.request.forms.get("pin")
    action = bottle.request.forms.get("action")
    create_account = (action.find("Create") != -1)

    if (user == ""):
        create_login = "******" if create_account else "Login"
        msg = "{} failed for empty username".format(create_login)
        return (show_html(msg))
    #endif

    api = nexus.sdk_init(user, pw, pin)

    #
    # When we create a user account, create a token account so user can send
    # and receive tokens.
    #
    if (create_account):
        status = api.nexus_users_create_user()
        if (status.has_key("error")):
            r = status["error"]["message"]
            msg = "Account create failed for user '{}', {}".format(user, r)
            return (show_html(msg))
        #endif
        sleep()
    #endif

    #
    # Log into new account or existing account.
    #
    status = api.nexus_users_login_user()
    if (status.has_key("error")):
        r = status["error"]["message"]
        msg = "Login failed for user '{}', {}".format(user, r)
        return (show_html(msg))
    #endif
    sid = status["result"]["session"]
    sleep()

    contexts[sid] = api
    output = display_user(sid, api)
    return (output)
Пример #4
0
    json = primer1.nexus_tokens_get_account_by_name("primer2")
    if (json.has_key("error") == False):
        balance = json["result"]["balance"]
        print "  'primer2' token account balance {}".format(balance)
    #endif


#enddef

#------------------------------------------------------------------------------

#
# Initialize with SDK.
#
print "Initialize Nexus SDK ...".ljust(width),
primer1 = nexus_sdk.sdk_init("primer1", "primer-password", "1234")
primer2 = nexus_sdk.sdk_init("primer2", "primer-password", "1234")
temp_primer = nexus_sdk.sdk_init("temp-primer", "primer-password", "1234")
print "succeeded"

asset = token = None

if (do_users): users(primer1, primer2)
if (do_supply): supply_chain(primer1, primer2)
if (do_assets): assets(primer1, primer2)
if (do_tokens): tokens(primer1, primer2)

print ""
print "All Done!"
exit(0)
Пример #5
0
def login():
    global contexts

    user = bottle.request.forms.get("username")
    pw = bottle.request.forms.get("password")
    pin = bottle.request.forms.get("pin")
    action = bottle.request.forms.get("action")
    create_account = (action.find("Create") != -1)

    if (user == ""):
        msg = "{} failed for empty username".format(action)
        return (show_html(msg))
    #endif

    if (user == "admin"):
        user_prefix = "admin-"
    else:
        if (action.find("Student") != -1): user_prefix = "student-"
        if (action.find("Teacher") != -1): user_prefix = "teacher-"
        if (action.find("University") != -1): user_prefix = "college-"
    #endif

    api = nexus.sdk_init(user_prefix + user, pw, pin)

    #
    # When we create a user account, create a token account so user can send
    # and receive tokens.
    #
    if (create_account):
        status = api.nexus_users_create_user()
        if (status.has_key("error")):
            r = status["error"]["message"]
            msg = "Account create failed for user '{}', {}".format(user, r)
            return (show_html(msg))
        #endif
        sleep()
    #endif

    #
    # Log into new account or existing account.
    #
    status = api.nexus_users_login_user()
    if (status.has_key("error")):
        r = status["error"]["message"]
        msg = "Login failed for user '{}', {}".format(user, r)
        return (show_html(msg))
    #endif
    sid = status["result"]["session"]
    sleep()

    #
    # If new account, create award token account and scholarship token account.
    #
    if (create_account):
        ta = api.username + "-atoken"
        tn = "admin-admin:award-token"
        status = api.nexus_tokens_create_account(ta, tn)
        if (status.has_key("error")):
            r = status["error"]["message"]
            msg = "Token Account create failed for user '{}', {}".format(
                user, r)
            return (show_html(msg))
        #endif
        cache_user(ta, status["result"]["address"])
        sleep(3)

        ta = api.username + "-stoken"
        tn = "admin-admin:scholarship-token"
        status = api.nexus_tokens_create_account(ta, tn)
        if (status.has_key("error")):
            r = status["error"]["message"]
            msg = "Token Account create failed for {}', {}".format(ta, r)
            return (show_html(msg))
        #endif
        cache_user(ta, status["result"]["address"])
        sleep()

        #
        # If this is a university account, cache some scholarship data. And
        # move some scholarship-tokens to its token account
        #
        if (api.username.find("college-") != -1):
            create_scholarship(user)
            move_scholarship_tokens(api)
        #endif
    #endif

    contexts[sid] = api
    output = display_user(sid, api)
    return (output)
Пример #6
0
def init():
    global admin_account

    print "Checking admin account for award/scholarship token creation ..."

    #
    # Need to create/use an account to create the token.
    #
    api = nexus.sdk_init("admin-admin", "password", "1234")
    admin_account = api
    login = api.nexus_users_login_user()
    if (login.has_key("error")):
        create = api.nexus_users_create_user()
        if (create.has_key("error")):
            if (api.nexus_users_login_user().has_key("error")):
                print "Account create for 'admin' failed, exit"
                exit(1)
            #endif
        #endif
        print "Created user account 'admin'"
        sleep()
        login = api.nexus_users_login_user()
    #endif
    print "User account 'admin' logged in"

    #
    # Create the award token if it does not exist.
    #
    tn = "award-token"
    supply = 1000000
    get = api.nexus_tokens_get_token_by_name(tn)
    if (get.has_key("error")):
        create = api.nexus_tokens_create_token(tn, supply, 3)
        if (create.has_key("error")):
            r = create["error"]["message"]
            print "tokens/create token {} failed, {}".format(tn, r)
            exit(1)
        #endif
        cache_user(api.username + "-atoken", create["result"]["address"])
        print "Created {} award tokens".format(supply)
        sleep()
    else:
        s = get["result"]["maxsupply"]
        b = get["result"]["balance"]
        print "Token-Name '{}' exists, supply {}, balance {}". \
            format(tn, s, b)
    #endif

    #
    # Create the scholarship token if it does not exist.
    #
    tn = "scholarship-token"
    supply = 1000
    get = api.nexus_tokens_get_token_by_name(tn)
    if (get.has_key("error")):
        create = api.nexus_tokens_create_token(tn, supply, 3)
        if (create.has_key("error")):
            r = create["error"]["message"]
            print "tokens/create token {} failed, {}".format(tn, r)
            exit(1)
        #endif
        cache_user(api.username + "-stoken", create["result"]["address"])
        print "Created {} scholarship tokens".format(supply)
    else:
        s = get["result"]["maxsupply"]
        b = get["result"]["balance"]
        print "Token-Name '{}' exists, supply {}, balance {}". \
            format(tn, s, b)
Пример #7
0

def print_transactions(j):
    if (j == None): return
    for tx in j:
        print "  tx {}".format(tx["hash"])


#enddef

#------------------------------------------------------------------------------

detail = "detail" in sys.argv

print "Initialize SDK for user sdk-test-user1 ...",
user1 = nexus_sdk.sdk_init("sdk-test-user1", "sdk-test", "1234")
print "done"
print "Initialize SDK for user sdk-test-user2 ...",
user2 = nexus_sdk.sdk_init("sdk-test-user2", "sdk-test", "1234")
print "done"
print ""

#
# Make calls to accounts API for both users.
#
j = call_api("Create user account sdk-test-user1", user1.nexus_accounts_create)
j = call_api("Create user account sdk-test-user2", user2.nexus_accounts_create)

j = call_api("Login user sdk-test-user1", user1.nexus_accounts_login)
if (j): print "  genesis {}".format(j["genesis"])
j = call_api("Login user sdk-test-user2", user2.nexus_accounts_login)
Пример #8
0
def login():
    global contexts

    user = bottle.request.forms.get("username")
    pw = bottle.request.forms.get("password")
    pin = bottle.request.forms.get("pin")
    action = bottle.request.forms.get("action")
    create_account = (action.find("Create") != -1)

    if (user == ""):
        msg = "{} failed for empty username".format(action)
        return (show_html(msg))
    #endif

    if (user == "admin"):
        user_prefix = "admin-"
    else:
        if (action.find("Artist") != -1): user_prefix = "artist-"
        if (action.find("Label") != -1): user_prefix = "label-"
        if (action.find("Distributor") != -1): user_prefix = "distributor-"
        if (action.find("Buyer") != -1): user_prefix = "buyer-"
    #endif

    api = nexus.sdk_init(user_prefix + user, pw, pin)

    #
    # When we create a user account, create a token account so user can send
    # and receive tokens. We will debit by default 100 music-tokens from the
    # admin token account.
    #
    if (create_account):
        status = api.nexus_users_create_user()
        if (status.has_key("error")):
            r = status["error"]["message"]
            msg = "Account create failed for user '{}', {}".format(user, r)
            return (show_html(msg))
        #endif
        sleep()
    #endif

    #
    # Log into new account or existing account.
    #
    status = api.nexus_users_login_user()
    if (status.has_key("error")):
        r = status["error"]["message"]
        msg = "Login failed for user '{}', {}".format(user, r)
        return (show_html(msg))
    #endif
    genesis = status["result"]["genesis"]
    sid = status["result"]["session"]
    sleep()

    #
    # If new account, create a token account and debit some tokens from admin
    # token account.
    #
    admin = admin_account
    if (create_account):
        tn = "admin-admin:music-token"
        status = api.nexus_tokens_create_account(api.username, tn)
        if (status.has_key("error")):
            r = status["error"]["message"]
            msg = "Token Account create failed for user '{}', {}".format(
                user, r)
            return (show_html(msg))
        #endif
        sleep()

        ta = api.username + ":" + api.username
        status = admin.nexus_tokens_debit_token_by_name(tn, ta, 100)
        if (status.has_key("error")):
            r = status["error"]["message"]
            msg = "Token Account debit failed for user '{}', {}".format(
                user, r)
            return (show_html(msg))
        #endif

        txid = wait_for_debit_notifcation(api)
        if (txid == None):
            msg = "Timeout waiting for debit notification for user {}". \
                format(user)
            return (show_html(msg))
        #endif

        txid = status["result"]["txid"]
        status = api.nexus_tokens_credit_account_by_name(
            api.username, 100, txid)
        if (status.has_key("error")):
            r = status["error"]["message"]
            msg = "tokens/credit failed for '{}', {}".format(user, r)
            return (show_html(msg))
        #endif
    #endif

    contexts[sid] = api
    sl = get_sigchain_length(api)
    user_type = api.username.split("-")[0]
    user_type = user_type_to_html[user_type]
    output = display_user(api, user, user_type, genesis, sl)
    output += show_transactions(api) + "<hr>"
    return (output)
Пример #9
0
    print "failed, {}".format(msg)
    if (msg == "Connection refused"):
        print "Abnormal exit"
        exit(1)
    #endif


#enddef

#------------------------------------------------------------------------------

#
# Initialize with SDK.
#
print "Initialize Nexus SDK ...".ljust(width),
primer = nexus_sdk.sdk_init("primer", "primer-password", "1234")
new_owner = nexus_sdk.sdk_init("new-owner", "primer-password", "1234")
print "succeeded"

#
# Call API accounts/create if not already logged in.
#
print "Create username 'primer' ...".ljust(width),
json = primer.nexus_accounts_create()
api_print(json)
#print json
print "Create username 'new-owner' ...".ljust(width),
json = new_owner.nexus_accounts_create()
api_print(json)
#print json