Ejemplo n.º 1
0
def create_account():
    # Prepare for new account name
    data = suggest_brain_key()
    data["account_name"] = ACCOUNT_PREFIX + RandomString(length=12, chars="d")

    # Create account
    bts_obj = BitShares(node=BITSHARES_NODE,
                        keys=REGISTRAR["private_key"],
                        nobroadcast=NOBROADCAST,
                        bundle=False,
                        debug=True)
    account = bts_obj.create_account(account_name=data["account_name"],
                                     registrar=REGISTRAR["account_name"],
                                     referrer=REGISTRAR["account_name"],
                                     password=data["private_key"],
                                     storekeys=False)
    bts_obj.clear()

    print(" * Created new account: " + str(data))
    print(account)
    print()
Ejemplo n.º 2
0
def tapv2(name, owner, active, memo, referrer):
    # prevent massive account registration
    if request.remote_addr != "127.0.0.1" and \
            models.Accounts.exists(request.remote_addr):
        return api_error("Only one account per IP")

    # Check if account name is cheap name
    if (not re.search(r"[0-9-]", name) and
            re.search(r"[aeiouy]", name)):
        return api_error("Only cheap names allowed!")

    bitshares = BitShares(
        config.witness_url,
        nobroadcast=config.nobroadcast,
        keys=[config.wif]
    )

    try:
        Account(name, bitshares_instance=bitshares)
        return api_error("Account exists")
    except:
        pass

    # Registrar
    registrar = config.registrar
    try:
        registrar = Account(registrar, bitshares_instance=bitshares)
    except:
        return api_error("Unknown registrar: %s" % registrar)

    # Referrer
    if not referrer:
        referrer = config.default_referrer
    try:
        referrer = Account(referrer, bitshares_instance=bitshares)
    except:
        return api_error("Unknown referrer: %s" % referrer)
    referrer_percent = config.referrer_percent

    # Create new account
    try:
        bitshares.create_account(
            name,
            registrar=registrar["id"],
            referrer=referrer["id"],
            referrer_percent=referrer_percent,
            owner_key=owner,
            active_key=active,
            memo_key=memo,
            proxy_account=config.get("proxy", None),
            additional_owner_accounts=config.get(
                "additional_owner_accounts", []),
            additional_active_accounts=config.get(
                "additional_active_accounts", []),
            additional_owner_keys=config.get(
                "additional_owner_keys", []),
            additional_active_keys=config.get(
                "additional_active_keys", []),
        )
    except Exception as e:
        log.error(traceback.format_exc())
        return api_error(str(e))

    models.Accounts(name, request.remote_addr)

    return jsonify({
        "status": "Account created",
        "account": {
            "name": name,
            "owner_key": owner,
            "active_key": active,
            "memo_key": memo,
        }})
Ejemplo n.º 3
0
def tapbasic(referrer):

    # test is request has 'account' key
    if not request.json or 'account' not in request.json:
        abort(400)
    account = request.json.get('account', {})

    # make sure all keys are present
    if any([
            key not in account
            for key in ["active_key", "memo_key", "owner_key", "name"]
    ]):
        abort(400)

    # prevent massive account registration
    if request.headers.get('X-Real-IP'):
        ip = request.headers.get('X-Real-IP')
    else:
        ip = request.remote_addr
    log.info("Request from IP: " + ip)
    if ip != "127.0.0.1" and models.Accounts.exists(ip):
        return api_error("Only one account per IP")

    # Check if account name is cheap name
    if (not re.search(r"[0-9-]", account["name"])
            and re.search(r"[aeiouy]", account["name"])):
        return api_error("Only cheap names allowed!")

    # This is not really needed but added to keep API-compatibility with Rails Faucet
    account.update({"id": None})

    bitshares = BitShares(config.witness_url,
                          nobroadcast=config.nobroadcast,
                          keys=[config.wif])

    try:
        Account(account["name"], bitshares_instance=bitshares)
        return api_error("Account exists")
    except:
        pass

    # Registrar
    registrar = account.get("registrar", config.registrar) or config.registrar
    try:
        registrar = Account(registrar, bitshares_instance=bitshares)
    except:
        return api_error("Unknown registrar: %s" % registrar)

    # Referrer
    referrer = account.get("referrer",
                           config.default_referrer) or config.default_referrer
    try:
        referrer = Account(referrer, bitshares_instance=bitshares)
    except:
        return api_error("Unknown referrer: %s" % referrer)
    referrer_percent = account.get("referrer_percent", config.referrer_percent)

    # Proxy
    proxy_account = None
    allow_proxy = account.get("allow_proxy", True)
    if allow_proxy:
        proxy_account = config.get("proxy", None)

    # Create new account
    try:
        bitshares.create_account(
            account["name"],
            registrar=registrar["id"],
            referrer=referrer["id"],
            referrer_percent=referrer_percent,
            owner_key=account["owner_key"],
            active_key=account["active_key"],
            memo_key=account["memo_key"],
            proxy_account=proxy_account,
            additional_owner_accounts=config.get("additional_owner_accounts",
                                                 []),
            additional_active_accounts=config.get("additional_active_accounts",
                                                  []),
            additional_owner_keys=config.get("additional_owner_keys", []),
            additional_active_keys=config.get("additional_active_keys", []),
        )
    except Exception as e:
        log.error(traceback.format_exc())
        return api_error(str(e))

    models.Accounts(account["name"], ip)

    balance = registrar.balance(config.core_asset)
    if balance and balance.amount < config.balance_mailthreshold:
        log.critical(
            "The faucet's balances is below {}".format(
                config.balance_mailthreshold), )

    return jsonify({
        "account": {
            "name": account["name"],
            "owner_key": account["owner_key"],
            "active_key": account["active_key"],
            "memo_key": account["memo_key"],
            "referrer": referrer["name"]
        }
    })
Ejemplo n.º 4
0
def tapbasic(referrer):
    # test is request has 'account' key
    if not request.json or 'account' not in request.json:
        abort(400)
    account = request.json.get('account', {})

    # make sure all keys are present
    required_files = set((config.get("require_fields", []) or []) +
                         ["active_key", "memo_key", "owner_key", "name"])
    for required in required_files:
        if str(required) not in account:
            return api_error("Please provide '{}'".format(required))

    # prevent massive account registration
    if request.headers.get('X-Real-IP'):
        ip = request.headers.get('X-Real-IP')
    else:
        ip = request.remote_addr
    if (config.get("restrict_ip", True) and ip != "127.0.0.1"
            and models.Accounts.exists(ip)):
        return api_error("Only one account per IP")

    # Check if account name is cheap name
    if (config.get("disable_premium_names", True)
            and is_premiumname(account["name"])):
        return api_error("Only cheap names allowed!")

    # This is not really needed but added to keep API-compatibility with Rails Faucet
    account.update({"id": None})

    bitshares = BitShares(config.witness_url,
                          nobroadcast=config.nobroadcast,
                          keys=[config.wif])

    # See if the account to register already exists
    if not is_test_account(account["name"]):
        try:
            Account(account["name"], bitshares_instance=bitshares)
            return api_error("Account exists")
        except:
            pass

    # Registrar
    registrar = account.get("registrar", config.registrar) or config.registrar
    try:
        registrar = Account(registrar, bitshares_instance=bitshares)
    except:
        return api_error("Unknown registrar: %s" % registrar)

    # Referrer
    referrer = account.get("referrer",
                           config.default_referrer) or config.default_referrer
    try:
        referrer = Account(referrer, bitshares_instance=bitshares)
    except:
        return api_error("Unknown referrer: %s" % referrer)
    referrer_percent = account.get("referrer_percent", config.referrer_percent)

    # Make sure to not broadcast this testing account
    if not bitshares.nobroadcast:
        if is_test_account(account["name"]):
            bitshares.nobroadcast = True
        else:
            bitshares.nobroadcast = False

    if "email" in account and account["email"]:
        try:
            models.Accounts.validate_email(account["email"])
        except Exception as e:
            return api_error(str(e))

    # Create new account
    try:
        tx = bitshares.create_account(
            account["name"],
            registrar=registrar["id"],
            referrer=referrer["id"],
            referrer_percent=referrer_percent,
            owner_key=account["owner_key"],
            active_key=account["active_key"],
            memo_key=account["memo_key"],
            proxy_account=config.get("proxy", None),
            additional_owner_accounts=config.get("additional_owner_accounts",
                                                 []),
            additional_active_accounts=config.get("additional_active_accounts",
                                                  []),
            additional_owner_keys=config.get("additional_owner_keys", []),
            additional_active_keys=config.get("additional_active_keys", []),
        )
    except Exception as e:
        log.error(traceback.format_exc())
        return api_error(str(e))

    if not is_test_account(account["name"]):
        models.Accounts(account=account["name"],
                        full_name=account.get("real_name", None),
                        email=account.get("email", None),
                        ip=ip)

    reply = {
        "account": {
            "name": account["name"],
            "owner_key": account["owner_key"],
            "active_key": account["active_key"],
            "memo_key": account["memo_key"],
            "referrer": referrer["name"]
        }
    }

    if is_test_account(account["name"]):
        tx.pop("signatures", None)
        reply.update({"tx": tx})

    return jsonify(reply)
Ejemplo n.º 5
0
Archivo: views.py Proyecto: xeroc/tapin
def tapbasic(referrer):
    # test is request has 'account' key
    if not request.json or 'account' not in request.json:
        abort(400)
    account = request.json.get('account', {})

    # make sure all keys are present
    required_files = set(
        (config.get("require_fields", []) or []) +
        ["active_key", "memo_key", "owner_key", "name"]
    )
    for required in required_files:
        if str(required) not in account:
            return api_error("Please provide '{}'".format(required))

    # prevent massive account registration
    if request.headers.get('X-Real-IP'):
        ip = request.headers.get('X-Real-IP')
    else:
        ip = request.remote_addr
    if (
        config.get("restrict_ip", True) and
        ip != "127.0.0.1" and
        models.Accounts.exists(ip)
    ):
        return api_error("Only one account per IP")

    # Check if account name is cheap name
    if (
        config.get("disable_premium_names", True) and
        is_premiumname(account["name"])
    ):
        return api_error("Only cheap names allowed!")

    # This is not really needed but added to keep API-compatibility with Rails Faucet
    account.update({"id": None})

    bitshares = BitShares(
        config.witness_url,
        nobroadcast=config.nobroadcast,
        keys=[config.wif]
    )

    # See if the account to register already exists
    if not is_test_account(account["name"]):
        try:
            Account(account["name"], bitshares_instance=bitshares)
            return api_error("Account exists")
        except:
            pass

    # Registrar
    registrar = account.get("registrar", config.registrar) or config.registrar
    try:
        registrar = Account(registrar, bitshares_instance=bitshares)
    except:
        return api_error("Unknown registrar: %s" % registrar)

    # Referrer
    referrer = account.get("referrer", config.default_referrer) or config.default_referrer
    try:
        referrer = Account(referrer, bitshares_instance=bitshares)
    except:
        return api_error("Unknown referrer: %s" % referrer)
    referrer_percent = account.get("referrer_percent", config.referrer_percent)

    # Make sure to not broadcast this testing account
    if not bitshares.nobroadcast:
        if is_test_account(account["name"]):
            bitshares.nobroadcast = True
        else:
            bitshares.nobroadcast = False

    if "email" in account and account["email"]:
        try:
            models.Accounts.validate_email(account["email"])
        except Exception as e:
            return api_error(str(e))

    # Create new account
    try:
        tx = bitshares.create_account(
            account["name"],
            registrar=registrar["id"],
            referrer=referrer["id"],
            referrer_percent=referrer_percent,
            owner_key=account["owner_key"],
            active_key=account["active_key"],
            memo_key=account["memo_key"],
            proxy_account=config.get("proxy", None),
            additional_owner_accounts=config.get("additional_owner_accounts", []),
            additional_active_accounts=config.get("additional_active_accounts", []),
            additional_owner_keys=config.get("additional_owner_keys", []),
            additional_active_keys=config.get("additional_active_keys", []),
        )
    except Exception as e:
        log.error(traceback.format_exc())
        return api_error(str(e))

    if not is_test_account(account["name"]):
        models.Accounts(
            account=account["name"],
            full_name=account.get("real_name", None),
            email=account.get("email", None),
            ip=ip
        )

    reply = {"account": {
        "name": account["name"],
        "owner_key": account["owner_key"],
        "active_key": account["active_key"],
        "memo_key": account["memo_key"],
        "referrer": referrer["name"]
    }}

    if is_test_account(account["name"]):
        tx.pop("signatures", None)
        reply.update({"tx": tx})

    return jsonify(reply)
Ejemplo n.º 6
0
    account = Account(a, bitshares_instance=testnet)
    for b in account.balances:
        t.append([str(a), str(b)])
    print_table(t)

testnet.wallet.unlock("P5J5vtQDEyFRMPyqgtTv6guw7W7nYKzHnqsqn8B2ALYpY")

print_tx(
    testnet.create_account("mutual-insurance-fund-993",
                           registrar="vel-ma",
                           referrer="vel-ma",
                           referrer_percent=50,
                           owner_key=None,
                           active_key=None,
                           memo_key=None,
                           owner_account="vel-ma",
                           active_account=None,
                           password="******",
                           additional_owner_keys=[],
                           additional_active_keys=[],
                           additional_owner_accounts=["vel-ma", "oatrick1995"],
                           additional_active_accounts=[],
                           proxy_account="proxy-to-self",
                           storekeys=True))

testnet.broadcast()

##allow - change threashold
foreign_account = format(
    PasswordKey("mutual-insurance-fund-993", "somethingstupid",
                "active").get_public(), "TEST")
print_tx(
Ejemplo n.º 7
0
def main(debug, config, wallet_password, password, broadcast, parent_account,
         account_name):
    """ Use this script to create new account. By default, a random password will be
        generated. By default, transaction will not be broadcasted (dry-run mode).
    """
    # create logger
    if debug == True:
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.INFO)
    handler = logging.StreamHandler()
    formatter = logging.Formatter("%(asctime)s %(levelname)s: %(message)s")
    handler.setFormatter(formatter)
    log.addHandler(handler)

    # parse config
    conf = yaml.safe_load(config)

    b = not broadcast
    bitshares = BitShares(node=conf['node_bts'], nobroadcast=b)
    account = Account(parent_account, bitshares_instance=bitshares)

    # Wallet unlock
    try:
        bitshares.unlock(wallet_password)
    except WrongMasterPasswordException:
        log.critical('Wrong wallet password provided')
        sys.exit(1)

    # random password
    if password:
        password = password
    else:
        password = generate_password()

    print('password: {}\n'.format(password))

    key = dict()
    for key_type in key_types:
        # PasswordKey object
        k = PasswordKey(account_name, password, role=key_type)

        privkey = k.get_private_key()
        print('{} private: {}'.format(
            key_type, str(privkey)))  # we need explicit str() conversion!

        # pubkey with default prefix GPH
        pubkey = k.get_public_key()

        # pubkey with correct prefix
        key[key_type] = format(pubkey, bitshares.prefix)
        print('{} public: {}\n'.format(key_type, key[key_type]))

    try:
        bitshares.create_account(
            account_name,
            registrar=parent_account,
            referrer=account['id'],
            referrer_percent=0,
            password=password,
            storekeys=broadcast,
        )
    except MissingKeyError:
        log.critical(
            'No key for {} in storage, use `uptick addkey` to add'.format(
                parent_account))
        sys.exit(1)
Ejemplo n.º 8
0
def tapv2(name, owner, active, memo, referrer):
    # prevent massive account registration
    if request.remote_addr != "127.0.0.1" and \
            models.Accounts.exists(request.remote_addr):
        return api_error("Only one account per IP")

    # Check if account name is cheap name
    if (not re.search(r"[0-9-]", name) and re.search(r"[aeiouy]", name)):
        return api_error("Only cheap names allowed!")

    bitshares = BitShares(config.witness_url,
                          nobroadcast=config.nobroadcast,
                          keys=[config.wif])

    try:
        Account(name, bitshares_instance=bitshares)
        return api_error("Account exists")
    except:
        pass

    # Registrar
    registrar = config.registrar
    try:
        registrar = Account(registrar, bitshares_instance=bitshares)
    except:
        return api_error("Unknown registrar: %s" % registrar)

    # Referrer
    if not referrer:
        referrer = config.default_referrer
    try:
        referrer = Account(referrer, bitshares_instance=bitshares)
    except:
        return api_error("Unknown referrer: %s" % referrer)
    referrer_percent = config.referrer_percent

    # Create new account
    try:
        bitshares.create_account(
            name,
            registrar=registrar["id"],
            referrer=referrer["id"],
            referrer_percent=referrer_percent,
            owner_key=owner,
            active_key=active,
            memo_key=memo,
            proxy_account=config.get("proxy", None),
            additional_owner_accounts=config.get("additional_owner_accounts",
                                                 []),
            additional_active_accounts=config.get("additional_active_accounts",
                                                  []),
            additional_owner_keys=config.get("additional_owner_keys", []),
            additional_active_keys=config.get("additional_active_keys", []),
        )
    except Exception as e:
        log.error(traceback.format_exc())
        return api_error(str(e))

    models.Accounts(name, request.remote_addr)

    return jsonify({
        "status": "Account created",
        "account": {
            "name": name,
            "owner_key": owner,
            "active_key": active,
            "memo_key": memo,
        }
    })