Files

frontEnd.src
  • blockchain = include_lib("/lib/blockchain.so")
  • if not blockchain then exit("Error: Missing blockchain.so library in the /lib")
  • YOUR_COIN = "1337coin" // edit this
  • OWNER_WALLETS = ["lock", "000111"] // you can edit this but it will break the script
  • YOUR_COIN = "coin" // edit this
  • OWNER_WALLETS = ["lock", "000111"] // these are the users that can run the backend server if you edit it you need to match the it with back end
  • DEFAULT_CREDENTIALS = "admin" // you may edit this too
  • SUBWALLET_PREPEND = "sub" // this should match with the back end
  • SUBWALLET_PASS = "123" // this should match with the back end
  • if params.len == 0 then
  • print("<b>this script requires the use of create coin you should delete your old coin, you can create it again later.</b>"+char(10))
  • print("<b>to register</b>")
  • print("coin_registration wallet_id wallet_pass")
  • print("<b>to delete your old coin</b>")
  • print("coin_registration --delete-my-old-coin coin_name coin_user coin_pass")
  • print("<b>to delete the coin created by this script in case you did interrupted the script</b>")
  • print("coin_registration --reset wallet_id wallet_pass")
  • exit
  • end if
  • if params[0] == "--delete-my-old-coin" and params.len == 4 then
  • out = blockchain.delete_coin(params[1], params[2], params[3])
  • exit(out)
  • end if
  • if params[0] == "--reset" and params.len == 3 then
  • wallet = login_wallet(params[1], params[2])
  • for coin_name in wallet.list_global_coins
  • out = blockchain.delete_coin(coin_name, DEFAULT_CREDENTIALS, DEFAULT_CREDENTIALS)
  • print(out)
  • end for
  • exit
  • end if
  • wallet_id = params[0]
  • wallet_pass = params[1]
  • wallet = login_wallet(params[0], params[1])
  • if typeof(wallet) == "string" then exit(wallet)
  • // check for the back end
  • get_owner_offer = function(OWNER_WALLET)
  • offers = wallet.get_global_offers(YOUR_COIN)
  • //print(wallet.get_global_offers(YOUR_COIN))
  • if wallet.get_global_offers(YOUR_COIN).indexes.indexOf(OWNER_WALLET) == null then
  • return null
  • else
  • return offers[OWNER_WALLET][2]
  • end if
  • end function
  • backend_active = [false]
  • get_backend_status = function()
  • for OWNER_WALLET in OWNER_WALLETS
  • last_flag = get_owner_offer(OWNER_WALLET)
  • for i in range(0, 5)
  • wait(0.05)
  • flag = get_owner_offer(OWNER_WALLET)
  • if flag != last_flag then
  • backend_active[0] = true
  • break
  • end if
  • end for
  • if backend_active[0] == true then break
  • end for
  • end function
  • while true
  • get_backend_status
  • if backend_active[0] == false then
  • print("<color=red>back end is off</color>")
  • else
  • print("<color=yellow>back end is running</color>")
  • break
  • end if
  • end while
  • // check if you have a subwallet already
  • has_subwallet = function(wallet)
  • out = wallet.buy_coin(YOUR_COIN, 1,99999)
  • if out.indexOf("You need to be registered") != null then
  • return false
  • else
  • return true
  • end if
  • wallet.cancel_pending_trade(YOUR_COIN)
  • end function
  • if has_subwallet(wallet) == true then
  • print("<color=red>you already have a subwallet in this coin</color>")
  • exit
  • else
  • end if
  • // register
  • if user_input("continue with the registration? [y/n]: ") == "n" then exit()
  • pin = wallet.get_pin
  • user = DEFAULT_CREDENTIALS
  • pass = DEFAULT_CREDENTIALS
  • print("created coin: " + pin + " " + user + " " + pass)
  • out = blockchain.create_coin(pin, user, pass)
  • if typeof(out) == "string" then exit(out)
  • coin = blockchain.get_coin(pin, user, pass)
  • if typeof(coin) == "string" then exit(coin)
  • random_subwallet = str(floor(rnd * 99999))
  • out = coin.create_subwallet(wallet_id, pin, random_subwallet, "admin")
  • if typeof(out) == "string" then exit(out)
  • out = wallet.buy_coin(pin, 1, 1)
  • print(wallet_id + " " + pin)
  • if typeof(out) == "string" and out.indexOf("pending until") == null then exit(out)
  • print("registration started do not kill the process")
  • for i in range(0,10)
  • wait(0.9)
  • if has_subwallet(wallet) == true then
  • print("<color=yellow>Account created sub_wallet_id: "+SUBWALLET_PREPEND+wallet_id+" password: "+SUBWALLET_PASS+"</color>")
  • blockchain.delete_coin(pin,user,pass)
  • exit
  • end if
  • end for
  • print("<color=red>Account not created for some reason</color>")
  • blockchain.delete_coin(pin,user,pass)
backEnd.src
  • // you should have a sub wallet in your coin
  • blockchain = include_lib("/lib/blockchain.so")
  • if not blockchain then exit("Error: Missing blockchain.so library in the /lib")
  • if params.len == 0 then exit("usage: backend wallet_id wallet_pass OR backend reset wallet_id wallet_pass")
  • my_coin = blockchain.get_coin("1337coin", "Plu70", "f")
  • my_coin = blockchain.get_coin("coin", "user", "pass")
  • SUBWALLET_PREPEND = "sub" // this should match with the front end
  • SUBWALLET_PASS = "123" // this should match with the front end
  • // delete all the wallets
  • if params[0] == "reset" then
  • //for subwallet in my_coin.get_subwallets()
  • //print(subwallet)
  • //print(subwallet.get_info)
  • //end for
  • wallet = login_wallet(params[1], params[2])
  • my_coin.delete_subwallet(SUBWALLET_PREPEND+params[1])
  • my_coin.create_subwallet(params[1], wallet.get_pin, SUBWALLET_PREPEND+params[1], SUBWALLET_PASS)
  • my_coin.get_subwallet(SUBWALLET_PREPEND+params[1]).add_coins(1)
  • exit
  • end if
  • wallet = login_wallet(params[0], params[1])
  • // set running flag
  • tick_control = [false]
  • tick = function()
  • if tick_control[0] == true then
  • value = 999999
  • tick_control[0] = false
  • else
  • value = 999998
  • tick_control[0] = true
  • end if
  • wallet.cancel_pending_trade("1337coin")
  • out = wallet.sell_coin("1337coin", 1, value)
  • wallet.cancel_pending_trade("coin")
  • out = wallet.sell_coin("coin", 1, value)
  • if typeof(out) == "string" and out.indexOf("pending until") == null then exit("<color=red>"+out+" you may use the reset param to setup</color>")
  • wait(0.1)
  • wallet.cancel_pending_trade("1337coin")
  • wallet.cancel_pending_trade("coin")
  • end function
  • // register users
  • while true
  • tick
  • for coin_name in wallet.list_global_coins
  • users = wallet.get_global_offers(coin_name).indexes
  • for user in users
  • //if coin_name.len != 5 then continue
  • sub_wallet = my_coin.create_subwallet(user, coin_name, SUBWALLET_PREPEND+user, SUBWALLET_PASS)
  • if sub_wallet == 1 then
  • print("new account created: sub"+user+" 123")
  • else
  • //print("<color=red>"+sub_wallet+"</color> "+user+" "+coin_name)
  • end if
  • end for
  • end for
  • end while