Exemple #1
0
 def get_supply(asset):
     if asset == 'BTC':
         return  backend.get_btc_supply(normalize=False)
     elif asset == 'XCP':
         return util.xcp_supply(db)
     else:
         return util.asset_supply(db, asset)
Exemple #2
0
 def get_supply(asset):
     if asset == 'BTC':
         return backend.get_btc_supply(normalize=False)
     elif asset == 'XCP':
         return util.xcp_supply(db)
     else:
         return util.asset_supply(db, asset)
Exemple #3
0
 def get_supply(asset):
     if asset == config.BTC:
         return backend.get_btc_supply(normalize=False)
     elif asset == config.XCP:
         return util.xcp_supply(self.db)
     else:
         asset = util.resolve_subasset_longname(self.db, asset)
         return util.asset_supply(self.db, asset)
Exemple #4
0
 def get_supply(asset):
     if asset == 'BTC':
         return backend.get_btc_supply(normalize=False)
     elif asset == 'XCP':
         return util.xcp_supply(db)
     else:
         asset = util.resolve_subasset_longname(db, asset)
         return util.asset_supply(db, asset)
Exemple #5
0
        def get_asset_info(assets):
            logger.warning("Deprecated method: `get_asset_info`")
            if not isinstance(assets, list):
                raise APIError("assets must be a list of asset names, even if it just contains one entry")
            assetsInfo = []
            for asset in assets:
                asset = util.resolve_subasset_longname(self.db, asset)

                # BTC and XCP.
                if asset in [config.BTC, config.XCP]:
                    if asset == config.BTC:
                        supply = backend.get_btc_supply(normalize=False)
                    else:
                        supply = util.xcp_supply(self.db)

                    assetsInfo.append({
                        'asset': asset,
                        'asset_longname': None,
                        'owner': None,
                        'divisible': True,
                        'listed': True,
                        'reassignable': True,
                        'vendable': False if asset == config.BTC else True,
                        'locked': False,
                        'supply': supply,
                        'description': '',
                        'issuer': None
                    })
                    continue

                # User‐created asset.
                cursor = self.db.cursor()
                issuances = list(cursor.execute('''SELECT * FROM issuances WHERE (status = ? AND asset = ?) ORDER BY block_index ASC''', ('valid', asset)))
                if not issuances:
                    continue #asset not found, most likely
                else:
                    last_issuance = issuances[-1]
                locked = False
                for e in issuances:
                    if e['locked']: locked = True
                assetsInfo.append({
                    'asset': asset,
                    'asset_longname': last_issuance['asset_longname'],
                    'owner': last_issuance['issuer'],
                    'divisible': bool(last_issuance['divisible']),
                    'listed': bool(last_issuance['listed']),
                    'reassignable': bool(last_issuance['reassignable']),
                    'vendable': bool(last_issuance['vendable']),
                    'locked': locked,
                    'supply': util.asset_supply(self.db, asset),
                    'description': last_issuance['description'],
                    'issuer': last_issuance['issuer']})
            return assetsInfo
Exemple #6
0
        def get_asset_info(assets):
            logger.warning("Deprecated method: `get_asset_info`")
            if not isinstance(assets, list):
                raise APIError("assets must be a list of asset names, even if it just contains one entry")
            assetsInfo = []
            for asset in assets:

                # BTC and XCP.
                if asset in [config.BTC, config.XCP]:
                    if asset == config.BTC:
                        supply = backend.get_btc_supply(normalize=False)
                    else:
                        supply = util.xcp_supply(db)

                    assetsInfo.append({
                        'asset': asset,
                        'owner': None,
                        'divisible': True,
                        'locked': False,
                        'supply': supply,
                        'description': '',
                        'issuer': None
                    })
                    continue

                # User‐created asset.
                cursor = db.cursor()
                issuances = list(cursor.execute('''SELECT * FROM issuances WHERE (status = ? AND asset = ?) ORDER BY block_index ASC''', ('valid', asset)))
                cursor.close()
                if not issuances:
                    continue #asset not found, most likely
                else:
                    last_issuance = issuances[-1]
                locked = False
                for e in issuances:
                    if e['locked']: locked = True
                assetsInfo.append({
                    'asset': asset,
                    'owner': last_issuance['issuer'],
                    'divisible': bool(last_issuance['divisible']),
                    'locked': locked,
                    'supply': util.asset_supply(db, asset),
                    'description': last_issuance['description'],
                    'issuer': last_issuance['issuer']})
            return assetsInfo
Exemple #7
0
 def get_xcp_supply():
     return util.xcp_supply(db)
Exemple #8
0
 def get_xcp_supply():
     logger.warning("Deprecated method: `get_xcp_supply`")
     return util.xcp_supply(db)
Exemple #9
0
 def get_xcp_supply():
     logger.warning("Deprecated method: `get_xcp_supply`")
     return util.xcp_supply(self.db)
def apply_transaction(db, tx, block):

    ### Make fees proportional to money supply. ###
    # Set initial values. Calculate price multiplier.
    # Multiply prices by multiplier, then by 100; make global variables.
    prices = {
              'GDEFAULT': 1,
              'GMEMORY': 1,
              'GSTORAGE': 100,
              'GTXDATA': 5,
              'GTXCOST': 500
             }
    if config.TESTNET:
        supply = 2600001 * config.UNIT
    else:
        supply = util.xcp_supply(db)
    MULTIPLIER = fractions.Fraction(supply, 2700000 * config.UNIT) * MULTIPLIER_CONSTANT_FACTOR
    for key in prices.keys():
        prices[key] = fractions.Fraction(prices[key]) * MULTIPLIER
        prices[key] = math.floor(prices[key].__round__(2))
        prices[key] = max(prices[key], 1)
        assert prices[key] > 0
        exec('''global {}; {} = prices['{}']'''.format(key, key, key))

    # (3) the gas limit is no smaller than the intrinsic gas,
    # g0, used by the transaction;
    intrinsic_gas_used = GTXDATA * len(tx.data) + GTXCOST
    if tx.startgas < intrinsic_gas_used:
        raise InsufficientStartGas(tx.startgas, intrinsic_gas_used)

    # (4) the sender account balance contains at least the
    # cost, v0, required in up-front payment.
    total_cost = tx.value + tx.gasprice * tx.startgas
    if block.get_balance(tx.sender) < total_cost:
        raise InsufficientBalance(block.get_balance(tx.sender), total_cost)

    pblogger.log('TX NEW', tx=tx.hex_hash(), tx_dict=tx.to_dict())
    # log('TX NEW', tx_dict)
    # start transacting #################
    block.increment_nonce(tx.sender)

    # buy startgas
    success = block.transfer_value(tx, tx.sender, None,
                                   tx.gasprice * tx.startgas)
    assert success

    message_gas = tx.startgas - intrinsic_gas_used
    message = Message(tx.sender, tx.to, tx.value, message_gas, tx.data)


    primary_result = None

    # Postqueue
    block.postqueue_delete()
    block.postqueue_insert(message)
    while block.postqueue_get():
        message = block.postqueue_pop()
        # MESSAGE
        if tx.to and tx.to != CREATE_CONTRACT_ADDRESS:
            result, gas_remained, data = apply_msg_send(db, block, tx, message)
        else:  # CREATE
            result, gas_remained, data = create_contract(db, block, tx, message)
        if not primary_result:
            primary_result = result, gas_remained, data

    result, gas_remained, data = primary_result

    assert gas_remained >= 0

    pblogger.log("TX APPLIED", result=result, gas_remained=gas_remained,
                 data=util.hexlify(bytes(data)))
    # if pblogger.log_block:
    #     pblogger.log('BLOCK', block=block.to_dict(with_state=True, full_transactions=True))


    if not result:  # 0 = OOG failure in both cases
        pblogger.log('TX FAILED', reason='out of gas', startgas=tx.startgas, gas_remained=gas_remained)
        output = OUT_OF_GAS
    else:
        pblogger.log('TX SUCCESS')
        assert gas_remained == int(gas_remained)
        gas_remained = int(gas_remained)
        # sell remaining gas
        block.transfer_value(
            tx, None, tx.sender, tx.gasprice * gas_remained)
        if tx.to:
            # output = ''.join(map(chr, data))
            output = bytes(data)
        else:
            output = result
    # block.commit_state()

    # Kill suicidal contract.
    for s in block.suicides_get():
        block.del_account(s['contract_id'])
    block.suicides_delete()
    # success = output is not OUT_OF_GAS
    # return success, output if success else ''
    if output == OUT_OF_GAS:
        success = False
        output = ''
    else:
        success = True
    return success, output, gas_remained
Exemple #11
0
def apply_transaction(db, tx, block):

    ### Make fees proportional to money supply. ###
    # Set initial values. Calculate price multiplier.
    # Multiply prices by multiplier, then by 100; make global variables.
    prices = {
        'GDEFAULT': 1,
        'GMEMORY': 1,
        'GSTORAGE': 100,
        'GTXDATA': 5,
        'GTXCOST': 500
    }
    if config.TESTNET:
        supply = 2600001 * config.UNIT
    else:
        supply = util.xcp_supply(db)
    MULTIPLIER = fractions.Fraction(
        supply, 2700000 * config.UNIT) * MULTIPLIER_CONSTANT_FACTOR
    for key in prices.keys():
        prices[key] = fractions.Fraction(prices[key]) * MULTIPLIER
        prices[key] = math.floor(prices[key].__round__(2))
        prices[key] = max(prices[key], 1)
        assert prices[key] > 0
        exec('''global {}; {} = prices['{}']'''.format(key, key, key))

    # (3) the gas limit is no smaller than the intrinsic gas,
    # g0, used by the transaction;
    intrinsic_gas_used = GTXDATA * len(tx.data) + GTXCOST
    if tx.startgas < intrinsic_gas_used:
        raise InsufficientStartGas(tx.startgas, intrinsic_gas_used)

    # (4) the sender account balance contains at least the
    # cost, v0, required in up-front payment.
    total_cost = tx.value + tx.gasprice * tx.startgas
    if block.get_balance(tx.sender) < total_cost:
        raise InsufficientBalance(block.get_balance(tx.sender), total_cost)

    pblogger.log('TX NEW', tx=tx.hex_hash(), tx_dict=tx.to_dict())
    # log('TX NEW', tx_dict)
    # start transacting #################
    block.increment_nonce(tx.sender)

    # buy startgas
    success = block.transfer_value(tx, tx.sender, None,
                                   tx.gasprice * tx.startgas)
    assert success

    message_gas = tx.startgas - intrinsic_gas_used
    message = Message(tx.sender, tx.to, tx.value, message_gas, tx.data)

    primary_result = None

    # Postqueue
    block.postqueue_delete()
    block.postqueue_insert(message)
    while block.postqueue_get():
        message = block.postqueue_pop()
        # MESSAGE
        if tx.to and tx.to != CREATE_CONTRACT_ADDRESS:
            result, gas_remained, data = apply_msg_send(db, block, tx, message)
        else:  # CREATE
            result, gas_remained, data = create_contract(
                db, block, tx, message)
        if not primary_result:
            primary_result = result, gas_remained, data

    result, gas_remained, data = primary_result

    assert gas_remained >= 0

    pblogger.log("TX APPLIED",
                 result=result,
                 gas_remained=gas_remained,
                 data=util.hexlify(bytes(data)))
    # if pblogger.log_block:
    #     pblogger.log('BLOCK', block=block.to_dict(with_state=True, full_transactions=True))

    if not result:  # 0 = OOG failure in both cases
        pblogger.log('TX FAILED',
                     reason='out of gas',
                     startgas=tx.startgas,
                     gas_remained=gas_remained)
        output = OUT_OF_GAS
    else:
        pblogger.log('TX SUCCESS')
        assert gas_remained == int(gas_remained)
        gas_remained = int(gas_remained)
        # sell remaining gas
        block.transfer_value(tx, None, tx.sender, tx.gasprice * gas_remained)
        if tx.to:
            # output = ''.join(map(chr, data))
            output = bytes(data)
        else:
            output = result
    # block.commit_state()

    # Kill suicidal contract.
    for s in block.suicides_get():
        block.del_account(s['contract_id'])
    block.suicides_delete()
    # success = output is not OUT_OF_GAS
    # return success, output if success else ''
    if output == OUT_OF_GAS:
        success = False
        output = ''
    else:
        success = True
    return success, output, gas_remained