Search in sources :

Example 6 with NulsByteBuffer

use of io.nuls.kernel.utils.NulsByteBuffer in project nuls by nuls-io.

the class UnconfiredmTransactionStorageImpl method loadAllUnconfirmedList.

@Override
public Result<List<Transaction>> loadAllUnconfirmedList() {
    Result result;
    List<UnconfirmedTxPo> tmpList = new ArrayList<>();
    List<Entry<byte[], byte[]>> txs = dbService.entryList(AccountLedgerStorageConstant.DB_NAME_ACCOUNT_LEDGER_TX);
    for (Entry<byte[], byte[]> txEntry : txs) {
        try {
            UnconfirmedTxPo tmpTx = new UnconfirmedTxPo(txEntry.getValue());
            if (tmpTx != null) {
                NulsByteBuffer buffer = new NulsByteBuffer(txEntry.getKey(), 0);
                tmpTx.getTx().setHash(buffer.readHash());
                tmpList.add(tmpTx);
            }
        } catch (Exception e) {
            Log.warn("parse local tx error", e);
        }
    }
    tmpList.sort(new Comparator<UnconfirmedTxPo>() {

        @Override
        public int compare(UnconfirmedTxPo o1, UnconfirmedTxPo o2) {
            return (int) (o1.getSequence() - o2.getSequence());
        }
    });
    List<Transaction> resultList = new ArrayList<>();
    for (UnconfirmedTxPo po : tmpList) {
        resultList.add(po.getTx());
    }
    return Result.getSuccess().setData(resultList);
}
Also used : ArrayList(java.util.ArrayList) UnconfirmedTxPo(io.nuls.account.ledger.storage.po.UnconfirmedTxPo) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) NulsException(io.nuls.kernel.exception.NulsException) Result(io.nuls.kernel.model.Result) Entry(io.nuls.db.model.Entry) Transaction(io.nuls.kernel.model.Transaction) NulsByteBuffer(io.nuls.kernel.utils.NulsByteBuffer)

Example 7 with NulsByteBuffer

use of io.nuls.kernel.utils.NulsByteBuffer in project nuls by nuls-io.

the class TransactionCacheStorageServiceImpl method getTx.

@Override
public Transaction getTx(NulsDigestData hash) {
    if (hash == null) {
        return null;
    }
    byte[] hashBytes = null;
    try {
        hashBytes = hash.serialize();
    } catch (IOException e) {
        Log.error(e);
        throw new NulsRuntimeException(e);
    }
    byte[] txBytes = dbService.get(TRANSACTION_CACHE_KEY_NAME, hashBytes);
    Transaction tx = null;
    if (null != txBytes) {
        try {
            tx = TransactionManager.getInstance(new NulsByteBuffer(txBytes, 0));
        } catch (Exception e) {
            Log.error(e);
            return null;
        }
    }
    return tx;
}
Also used : Transaction(io.nuls.kernel.model.Transaction) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) IOException(java.io.IOException) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) IOException(java.io.IOException) NulsException(io.nuls.kernel.exception.NulsException) NulsByteBuffer(io.nuls.kernel.utils.NulsByteBuffer)

Example 8 with NulsByteBuffer

use of io.nuls.kernel.utils.NulsByteBuffer in project nuls by nuls-io.

the class RandomSeedsStorageServiceImpl method getSeed.

@Override
public RandomSeedPo getSeed(long height) {
    byte[] bytes = dbService.get(ConsensusStorageConstant.DB_NAME_RANDOM_SEEDS, SerializeUtils.uint64ToByteArray(height));
    if (null == bytes) {
        return null;
    }
    RandomSeedPo po = new RandomSeedPo();
    try {
        po.parse(new NulsByteBuffer(bytes, 0));
        po.setHeight(height);
    } catch (NulsException e) {
        Log.error(e);
    }
    return po;
}
Also used : RandomSeedPo(io.nuls.consensus.poc.storage.po.RandomSeedPo) NulsException(io.nuls.kernel.exception.NulsException) NulsByteBuffer(io.nuls.kernel.utils.NulsByteBuffer)

Example 9 with NulsByteBuffer

use of io.nuls.kernel.utils.NulsByteBuffer in project nuls by nuls-io.

the class RandomSeedsStorageServiceImpl method getAddressStatus.

@Override
public RandomSeedStatusPo getAddressStatus(byte[] address) {
    byte[] bytes = dbService.get(ConsensusStorageConstant.DB_NAME_RANDOM_SEEDS, address);
    if (null == bytes) {
        return null;
    }
    RandomSeedStatusPo po = new RandomSeedStatusPo();
    try {
        po.parse(new NulsByteBuffer(bytes, 0));
        po.setAddress(address);
    } catch (NulsException e) {
        Log.error(e);
    }
    return po;
}
Also used : NulsException(io.nuls.kernel.exception.NulsException) RandomSeedStatusPo(io.nuls.consensus.poc.storage.po.RandomSeedStatusPo) NulsByteBuffer(io.nuls.kernel.utils.NulsByteBuffer)

Example 10 with NulsByteBuffer

use of io.nuls.kernel.utils.NulsByteBuffer in project nuls by nuls-io.

the class TransactionCacheStorageServiceImpl method pollTx.

@Override
public Transaction pollTx() {
    byte[] startIndexBytes = Util.intToBytes(startIndex.get());
    byte[] hashBytes = dbService.get(TRANSACTION_CACHE_KEY_NAME, startIndexBytes);
    if (hashBytes == null) {
        return null;
    }
    byte[] txBytes = dbService.get(TRANSACTION_CACHE_KEY_NAME, hashBytes);
    Transaction tx = null;
    if (null != txBytes) {
        try {
            tx = TransactionManager.getInstance(new NulsByteBuffer(txBytes, 0));
        } catch (Exception e) {
            Log.error(e);
            return null;
        }
    }
    startIndex.incrementAndGet();
    return tx;
}
Also used : Transaction(io.nuls.kernel.model.Transaction) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) IOException(java.io.IOException) NulsException(io.nuls.kernel.exception.NulsException) NulsByteBuffer(io.nuls.kernel.utils.NulsByteBuffer)

Aggregations

NulsByteBuffer (io.nuls.kernel.utils.NulsByteBuffer)17 NulsException (io.nuls.kernel.exception.NulsException)14 IOException (java.io.IOException)9 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)5 Account (io.nuls.account.model.Account)4 MultiSigAccount (io.nuls.account.model.MultiSigAccount)4 Transaction (io.nuls.kernel.model.Transaction)3 ValidateResult (io.nuls.kernel.validate.ValidateResult)3 CoinDataResult (io.nuls.account.ledger.model.CoinDataResult)2 AliasPo (io.nuls.account.storage.po.AliasPo)2 AliasTransaction (io.nuls.account.tx.AliasTransaction)2 ECKey (io.nuls.core.tools.crypto.ECKey)2 VarInt (io.nuls.kernel.utils.VarInt)2 TransferTransaction (io.nuls.protocol.model.tx.TransferTransaction)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 MultipleAddressTransferModel (io.nuls.account.ledger.model.MultipleAddressTransferModel)1 TransactionDataResult (io.nuls.account.ledger.model.TransactionDataResult)1 UnconfirmedTxPo (io.nuls.account.ledger.storage.po.UnconfirmedTxPo)1 Alias (io.nuls.account.model.Alias)1