Search in sources :

Example 11 with DataAccount

use of com.jd.blockchain.ledger.core.DataAccount in project jdchain-core by blockchain-jd-com.

the class UncommittedLedgerQueryService method getDataEntries.

@Override
public TypedKVEntry[] getDataEntries(String address, int fromIndex, int count) {
    DataAccountSet dataAccountSet = transactionContext.getDataset().getDataAccountSet();
    DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address));
    QueryArgs queryArgs = QueryUtils.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataset().getDataCount());
    SkippingIterator<DataEntry<String, TypedValue>> iterator = ((IteratorDataset) dataAccount.getDataset()).kvIterator();
    iterator.skip(queryArgs.getFrom());
    TypedKVEntry[] typedKVEntries = iterator.next(queryArgs.getCount(), TypedKVEntry.class, entry -> new TypedKVData(entry.getKey(), entry.getVersion(), entry.getValue()));
    return typedKVEntries;
}
Also used : DataAccount(com.jd.blockchain.ledger.core.DataAccount) DataEntry(utils.DataEntry) TypedKVEntry(com.jd.blockchain.ledger.TypedKVEntry) TypedKVData(com.jd.blockchain.ledger.TypedKVData) QueryArgs(utils.query.QueryArgs) IteratorDataset(com.jd.blockchain.ledger.core.IteratorDataset) DataAccountSet(com.jd.blockchain.ledger.core.DataAccountSet)

Example 12 with DataAccount

use of com.jd.blockchain.ledger.core.DataAccount in project jdchain-core by blockchain-jd-com.

the class UncommittedLedgerQueryService method getDataEntries.

@Override
public TypedKVEntry[] getDataEntries(String address, KVInfoVO kvInfoVO) {
    List<String> keyList = new ArrayList<>();
    List<Long> versionList = new ArrayList<>();
    if (kvInfoVO != null) {
        for (KVDataVO kvDataVO : kvInfoVO.getData()) {
            for (Long version : kvDataVO.getVersion()) {
                keyList.add(kvDataVO.getKey());
                versionList.add(version);
            }
        }
    }
    String[] keys = keyList.toArray(new String[keyList.size()]);
    Long[] versions = versionList.toArray(new Long[versionList.size()]);
    if (keys.length == 0) {
        return null;
    }
    if (versions.length == 0) {
        return null;
    }
    if (keys.length != versions.length) {
        throw null;
    }
    DataAccount dataAccount = transactionContext.getDataset().getDataAccountSet().getAccount(address);
    TypedKVEntry[] entries = new TypedKVEntry[keys.length];
    long ver = -1L;
    for (int i = 0; i < entries.length; i++) {
        ver = versions[i];
        if (ver < 0) {
            entries[i] = new TypedKVData(keys[i], -1, null);
        } else {
            if (dataAccount.getDataset().getDataCount() == 0 || dataAccount.getDataset().getValue(keys[i], ver) == null) {
                // is the address is not exist; the result is null;
                entries[i] = new TypedKVData(keys[i], -1, null);
            } else {
                BytesValue value = dataAccount.getDataset().getValue(keys[i], ver);
                entries[i] = new TypedKVData(keys[i], ver, value);
            }
        }
    }
    return entries;
}
Also used : ArrayList(java.util.ArrayList) KVDataVO(com.jd.blockchain.ledger.KVDataVO) BytesValue(com.jd.blockchain.ledger.BytesValue) DataAccount(com.jd.blockchain.ledger.core.DataAccount) TypedKVEntry(com.jd.blockchain.ledger.TypedKVEntry) TypedKVData(com.jd.blockchain.ledger.TypedKVData)

Example 13 with DataAccount

use of com.jd.blockchain.ledger.core.DataAccount in project jdchain-core by blockchain-jd-com.

the class ContractLedgerQueryService method getDataEntries.

@Override
public TypedKVEntry[] getDataEntries(String address, KVInfoVO kvInfoVO) {
    List<String> keyList = new ArrayList<>();
    List<Long> versionList = new ArrayList<>();
    if (kvInfoVO != null) {
        for (KVDataVO kvDataVO : kvInfoVO.getData()) {
            for (Long version : kvDataVO.getVersion()) {
                keyList.add(kvDataVO.getKey());
                versionList.add(version);
            }
        }
    }
    String[] keys = keyList.toArray(new String[keyList.size()]);
    Long[] versions = versionList.toArray(new Long[versionList.size()]);
    if (keys.length == 0) {
        return null;
    }
    if (versions.length == 0) {
        return null;
    }
    if (keys.length != versions.length) {
        throw null;
    }
    DataAccount dataAccount = ledgerQuery.getDataAccountSet().getAccount(address);
    TypedKVEntry[] entries = new TypedKVEntry[keys.length];
    long ver = -1L;
    for (int i = 0; i < entries.length; i++) {
        ver = versions[i];
        if (ver < 0) {
            entries[i] = new TypedKVData(keys[i], -1, null);
        } else {
            if (dataAccount.getDataset().getDataCount() == 0 || dataAccount.getDataset().getValue(keys[i], ver) == null) {
                // is the address is not exist; the result is null;
                entries[i] = new TypedKVData(keys[i], -1, null);
            } else {
                BytesValue value = dataAccount.getDataset().getValue(keys[i], ver);
                entries[i] = new TypedKVData(keys[i], ver, value);
            }
        }
    }
    return entries;
}
Also used : ArrayList(java.util.ArrayList) KVDataVO(com.jd.blockchain.ledger.KVDataVO) BytesValue(com.jd.blockchain.ledger.BytesValue) DataAccount(com.jd.blockchain.ledger.core.DataAccount) TypedKVEntry(com.jd.blockchain.ledger.TypedKVEntry) TypedKVData(com.jd.blockchain.ledger.TypedKVData)

Example 14 with DataAccount

use of com.jd.blockchain.ledger.core.DataAccount in project jdchain-core by blockchain-jd-com.

the class DataAccountRegisterOperationHandle method doProcess.

@Override
protected void doProcess(DataAccountRegisterOperation op, LedgerTransactionContext transactionContext, TransactionRequestExtension requestContext, LedgerQuery ledger, OperationHandleContext handleContext, EventManager manager) {
    // TODO: 请求者应该提供数据账户的公钥签名,以更好地确保注册人对该地址和公钥具有合法使用权;
    // 权限校验;
    SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy();
    securityPolicy.checkEndpointPermission(LedgerPermission.REGISTER_DATA_ACCOUNT, MultiIDsPolicy.AT_LEAST_ONE);
    // 操作账本;
    BlockchainIdentity bid = op.getAccountID();
    DataAccount account = ((DataAccountSetEditor) (transactionContext.getDataset().getDataAccountSet())).register(bid.getAddress(), bid.getPubKey(), null);
    account.setPermission(new AccountDataPermission(AccountType.DATA, requestContext.getEndpointAddresses().toArray(new Bytes[0])));
}
Also used : DataAccount(com.jd.blockchain.ledger.core.DataAccount) SecurityPolicy(com.jd.blockchain.ledger.SecurityPolicy) BlockchainIdentity(com.jd.blockchain.ledger.BlockchainIdentity) AccountDataPermission(com.jd.blockchain.ledger.AccountDataPermission) DataAccountSetEditor(com.jd.blockchain.ledger.core.DataAccountSetEditor)

Example 15 with DataAccount

use of com.jd.blockchain.ledger.core.DataAccount in project jdchain-core by blockchain-jd-com.

the class LedgerQueryController method getDataEntries.

@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }, path = GET_LATEST_KV_SEQUENCE)
@Override
public TypedKVEntry[] getDataEntries(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address, @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
    LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
    LedgerBlock block = ledger.getLatestBlock();
    DataAccountSet dataAccountSet = ledger.getDataAccountSet(block);
    DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address));
    if (dataAccount == null) {
        return null;
    }
    QueryArgs queryArgs = QueryUtils.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataset().getDataCount());
    fromIndex = queryArgs.getFrom();
    count = queryArgs.getCount();
    SkippingIterator<DataEntry<String, TypedValue>> iterator = ((IteratorDataset) dataAccount.getDataset()).kvIterator();
    iterator.skip(fromIndex);
    TypedKVEntry[] typedKVEntries = iterator.next(count, TypedKVEntry.class, new Mapper<DataEntry<String, TypedValue>, TypedKVEntry>() {

        @Override
        public TypedKVEntry from(DataEntry<String, TypedValue> entry) {
            return entry == null ? null : new TypedKVData(entry.getKey(), entry.getVersion(), entry.getValue());
        }
    });
    return typedKVEntries;
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) LedgerQuery(com.jd.blockchain.ledger.core.LedgerQuery) DataAccount(com.jd.blockchain.ledger.core.DataAccount) DataEntry(utils.DataEntry) TypedKVEntry(com.jd.blockchain.ledger.TypedKVEntry) TypedKVData(com.jd.blockchain.ledger.TypedKVData) QueryArgs(utils.query.QueryArgs) IteratorDataset(com.jd.blockchain.ledger.core.IteratorDataset) DataAccountSet(com.jd.blockchain.ledger.core.DataAccountSet) TypedValue(com.jd.blockchain.ledger.TypedValue) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataAccount (com.jd.blockchain.ledger.core.DataAccount)16 TypedKVData (com.jd.blockchain.ledger.TypedKVData)11 BytesValue (com.jd.blockchain.ledger.BytesValue)10 TypedKVEntry (com.jd.blockchain.ledger.TypedKVEntry)9 LedgerBlock (com.jd.blockchain.ledger.LedgerBlock)6 DataAccountSet (com.jd.blockchain.ledger.core.DataAccountSet)6 LedgerQuery (com.jd.blockchain.ledger.core.LedgerQuery)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 KVDataVO (com.jd.blockchain.ledger.KVDataVO)3 IteratorDataset (com.jd.blockchain.ledger.core.IteratorDataset)3 ArrayList (java.util.ArrayList)3 DataEntry (utils.DataEntry)3 QueryArgs (utils.query.QueryArgs)3 HashDigest (com.jd.blockchain.crypto.HashDigest)2 BlockchainKeypair (com.jd.blockchain.ledger.BlockchainKeypair)2 DataVersionConflictException (com.jd.blockchain.ledger.DataVersionConflictException)2 SecurityPolicy (com.jd.blockchain.ledger.SecurityPolicy)2 LedgerEditor (com.jd.blockchain.ledger.core.LedgerEditor)2 LedgerManager (com.jd.blockchain.ledger.core.LedgerManager)2 LedgerRepository (com.jd.blockchain.ledger.core.LedgerRepository)2