Ejemplo n.º 1
0
def get_current_user_kin_balance(user_id):
    '''get the current kin balance for the user with the given user_id.'''
    # determine the user's public address from pre-existing outgoing txs
    user_outgoing_txs = Transaction.query.filter(
        Transaction.user_id == user_id).filter(
            Transaction.incoming_tx == False).all()
    if len(user_outgoing_txs) == 0:
        return 0  # user should not have any Kins
    else:
        return stellar.get_kin_balance(user_outgoing_txs[0].remote_address)
Ejemplo n.º 2
0
def bvalance_api():
    '''endpoint used to populate the server with goods'''
    if not config.DEBUG:
        limit_to_local_host()
    balance = {}
    balance['kin'] = stellar.get_kin_balance(config.STELLAR_PUBLIC_ADDRESS)
    balance['xlm'] = stellar.get_xlm_balance(config.STELLAR_PUBLIC_ADDRESS)
    if balance[kin] is not None and balance['xlm'] is not None:
        return jsonify(status='ok', balance=balance)
    else:
        return jsonify(status='error'), status.HTTP_500_INTERNAL_SERVER_ERROR
Ejemplo n.º 3
0
def balance_api():
    """endpoint used to get the current balance of the seed and channels"""
    if not config.DEBUG:
        limit_to_localhost()

    base_seed, channel_seeds = ssm.get_stellar_credentials()
    balance = {'base_seed': {}, 'channel_seeds': {}}

    from stellar_base.keypair import Keypair
    balance['base_seed']['kin'] = stellar.get_kin_balance(
        Keypair.from_seed(base_seed).address().decode())
    balance['base_seed']['xlm'] = stellar.get_xlm_balance(
        Keypair.from_seed(base_seed).address().decode())
    index = 0
    for channel in channel_seeds:
        # seeds only need to carry XLMs
        balance['channel_seeds'][index] = {'xlm': 0}
        balance['channel_seeds'][index]['xlm'] = stellar.get_xlm_balance(
            Keypair.from_seed(channel).address().decode())
        index = index + 1

    return jsonify(status='ok', balance=balance)
Ejemplo n.º 4
0
if not base_seed:
    print('could not get base seed - aborting')
    sys.exit(-1)

if channel_seeds is None:
    print('could not get channels seeds - aborting')
    sys.exit(-1)

app.kin_sdk = SDK(secret_key=base_seed,
                  horizon_endpoint_uri=config.STELLAR_HORIZON_URL,
                  network=config.STELLAR_NETWORK,
                  channel_secret_keys=channel_seeds)

# get (and print) the current balance for the account:
print('the current KIN balance: %s' %
      stellar.get_kin_balance(config.STELLAR_PUBLIC_ADDRESS))
# get (and print) the current balance for the account:
print('the current XLM balance: %s' %
      stellar.get_xlm_balance(config.STELLAR_PUBLIC_ADDRESS))

app.config['SQLALCHEMY_DATABASE_URI'] = config.DB_CONNSTR
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False
db = SQLAlchemy(app)

# TODO remove this on production
admin = Admin(app, name='KinApp', template_mode='bootstrap3')
from kinappserver.models import User, UserAppData, UserTaskResults, Task, Transaction, Offer, Order, Good
from flask_admin.contrib import sqla

Ejemplo n.º 5
0
    NETWORKS[network] = config.STELLAR_NETWORK
else:
    print('starting the sdk on the public testnet')
    network = config.STELLAR_NETWORK

app.kin_sdk = kin.SDK(secret_key=base_seed,
                      horizon_endpoint_uri=config.STELLAR_HORIZON_URL,
                      network=network,
                      channel_secret_keys=channel_seeds,
                      kin_asset=kin_asset)

# get (and print) the current balance for the account:
from stellar_base.keypair import Keypair
log.info(
    'the current KIN balance on the base-seed: %s' %
    stellar.get_kin_balance(Keypair.from_seed(base_seed).address().decode()))
# get (and print) the current balance for the account:
log.info(
    'the current XLM balance on the base-seed: %s' %
    stellar.get_xlm_balance(Keypair.from_seed(base_seed).address().decode()))

for channel in channel_seeds:
    address = Keypair.from_seed(channel).address().decode()
    print('the current XLM balance on channel (%s): %s' %
          (address, stellar.get_xlm_balance(address)))

# init encryption util
key, iv = ssm.get_encrpytion_creds()
app.encryption = AESCipher(key, iv)