def utxo_cache(db_manager):
    cache = UTXOCache(
        initKeyValueStorage(KeyValueStorageType.Memory, None,
                            "utxoInMemoryStore"))
    db_manager.register_new_store(UTXO_CACHE_LABEL, cache)
    yield cache
    if cache.un_committed:
        cache.reject_batch()
Exemple #2
0
 def spend_input(state,
                 utxo_cache: UTXOCache,
                 address,
                 seq_no,
                 is_committed=False):
     state_key = TokenStaticHelper.create_state_key(address, seq_no)
     state.remove(state_key)
     utxo_cache.spend_output(Output(address, seq_no, None),
                             is_committed=is_committed)
Exemple #3
0
 def add_new_output(state,
                    utxo_cache: UTXOCache,
                    output: Output,
                    is_committed=False):
     address = output.address
     seq_no = output.seqNo
     amount = output.amount
     state_key = TokenStaticHelper.create_state_key(address, seq_no)
     state.set(state_key, str(amount).encode())
     utxo_cache.add_output(output, is_committed=is_committed)
 def spend_input(state,
                 utxo_cache: UTXOCache,
                 address,
                 seq_no,
                 is_committed=False,
                 remove_spent=True):
     state_key = TokenStaticHelper.create_state_key(address, seq_no)
     if remove_spent:
         state.remove(state_key)
     else:
         state.set(state_key, b'')
     utxo_cache.spend_output(Output(address, seq_no, None),
                             is_committed=is_committed)
Exemple #5
0
def fees_authorizer(fees):
    authorizer = FeesAuthorizer(
        config_state=PruningState(KeyValueStorageInMemory()),
        utxo_cache=UTXOCache(KeyValueStorageInMemory()))
    authorizer.calculate_fees_from_req = lambda *args, **kwargs: fees.get(
        NYM_FEES_ALIAS)
    return authorizer
 def sum_inputs(utxo_cache: UTXOCache,
                request: Request,
                is_committed=False) -> int:
     try:
         inputs = request.operation[INPUTS]
         return utxo_cache.sum_inputs(inputs, is_committed=is_committed)
     except UTXOError as ex:
         raise InvalidFundsError(request.identifier, request.reqId,
                                 '{}'.format(ex))
Exemple #7
0
def init_storages(node):
    # Token ledger and state init
    if TOKEN_LEDGER_ID not in node.ledger_ids:
        node.ledger_ids.append(TOKEN_LEDGER_ID)
    token_state = init_token_state(node)
    token_ledger = init_token_ledger(node)
    node.db_manager.register_new_database(TOKEN_LEDGER_ID, token_ledger,
                                          token_state)
    init_token_database(node)

    # UTXO store init
    node.db_manager.register_new_store(
        UTXO_CACHE_LABEL,
        UTXOCache(
            initKeyValueStorage(node.config.utxoCacheStorage,
                                node.dataLocation,
                                node.config.utxoCacheDbName)))
Exemple #8
0
def utxo_cache(parametrised_storage) -> UTXOCache:
    cache = UTXOCache(parametrised_storage)
    yield cache
    cache.reject_batch()
def utxo_cache(parametrised_storage) -> UTXOCache:
    cache = UTXOCache(parametrised_storage)
    yield cache
    if cache.un_committed:
        cache.reject_batch()
Exemple #10
0
def get_utxo_cache(data_dir, name, config):
    return UTXOCache(initKeyValueStorage(
        config.utxoCacheStorage, data_dir, name))