Search in sources :

Example 1 with NulsByteBuffer

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

the class GetBlocksHashParam method main.

public static void main(String[] args) throws Exception {
    GetBlocksHashParam param = new GetBlocksHashParam();
    param.parse(new NulsByteBuffer(Hex.decode("ffff1d50746101000000000100000100")));
}
Also used : NulsByteBuffer(io.nuls.core.utils.io.NulsByteBuffer)

Example 2 with NulsByteBuffer

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

the class TxSignValidator method validate.

@Override
public ValidateResult validate(Transaction tx) {
    byte[] scriptSig = tx.getScriptSig();
    tx.setScriptSig(null);
    NulsDigestData nulsDigestData;
    try {
        nulsDigestData = NulsDigestData.calcDigestData(tx.serialize());
    } catch (Exception e) {
        return ValidateResult.getFailedResult(ErrorCode.DATA_ERROR);
    } finally {
        tx.setScriptSig(scriptSig);
    }
    if (!Arrays.equals(nulsDigestData.getDigestBytes(), tx.getHash().getDigestBytes())) {
        return ValidateResult.getFailedResult(ErrorCode.DATA_ERROR);
    }
    P2PKHScriptSig p2PKHScriptSig = null;
    try {
        p2PKHScriptSig = new NulsByteBuffer(scriptSig).readNulsData(new P2PKHScriptSig());
    } catch (NulsException e) {
        return ValidateResult.getFailedResult(ErrorCode.SIGNATURE_ERROR);
    }
    return p2PKHScriptSig.verifySign(tx.getHash());
}
Also used : P2PKHScriptSig(io.nuls.core.script.P2PKHScriptSig) NulsException(io.nuls.core.exception.NulsException) NulsDigestData(io.nuls.core.chain.entity.NulsDigestData) NulsException(io.nuls.core.exception.NulsException) NulsByteBuffer(io.nuls.core.utils.io.NulsByteBuffer)

Example 3 with NulsByteBuffer

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

the class ConsensusTool method fromPojo.

public static final BlockHeader fromPojo(BlockHeaderPo po) throws NulsException {
    if (null == po) {
        return null;
    }
    BlockHeader header = new BlockHeader();
    header.setHash(NulsDigestData.fromDigestHex(po.getHash()));
    header.setMerkleHash(NulsDigestData.fromDigestHex(po.getMerkleHash()));
    header.setPackingAddress(po.getConsensusAddress());
    header.setTxCount(po.getTxCount());
    header.setPreHash(NulsDigestData.fromDigestHex(po.getPreHash()));
    header.setTime(po.getCreateTime());
    header.setHeight(po.getHeight());
    header.setExtend(po.getExtend());
    header.setSize(po.getSize());
    header.setScriptSig((new NulsByteBuffer(po.getScriptSig()).readNulsData(new P2PKHScriptSig())));
    return header;
}
Also used : P2PKHScriptSig(io.nuls.core.script.P2PKHScriptSig) NulsByteBuffer(io.nuls.core.utils.io.NulsByteBuffer)

Example 4 with NulsByteBuffer

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

the class TransactionManager method getInstance.

public static Transaction getInstance(NulsByteBuffer byteBuffer) throws Exception {
    int txType = (int) new NulsByteBuffer(byteBuffer.getPayloadByCursor()).readVarInt();
    Class<? extends Transaction> txClass = getTxClass(txType);
    if (null == txClass) {
        throw new NulsRuntimeException(ErrorCode.FAILED, "transaction type not exist!");
    }
    Transaction tx = byteBuffer.readNulsData(txClass.getConstructor().newInstance());
    return tx;
}
Also used : Transaction(io.nuls.core.chain.entity.Transaction) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) NulsByteBuffer(io.nuls.core.utils.io.NulsByteBuffer)

Example 5 with NulsByteBuffer

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

the class UtxoTransferTool method toTransaction.

public static Transaction toTransaction(TransactionPo po) throws Exception {
    Transaction tx = TransactionManager.getInstanceByType(po.getType());
    tx.setHash(new NulsDigestData(Hex.decode(po.getHash())));
    tx.setTime(po.getCreateTime());
    tx.setBlockHeight(po.getBlockHeight());
    tx.setFee(Na.valueOf(po.getFee()));
    tx.setIndex(po.getTxIndex());
    tx.setSize(po.getSize());
    tx.setScriptSig(po.getScriptSig());
    if (StringUtils.isNotBlank(po.getRemark())) {
        tx.setRemark(po.getRemark().getBytes(NulsContext.DEFAULT_ENCODING));
    }
    if (null != po.getTxData()) {
        tx.setTxData(tx.parseTxData(new NulsByteBuffer(po.getTxData())));
    }
    transferCoinData(tx, po.getInputs(), po.getOutputs());
    tx.setStatus(TxStatusEnum.CONFIRMED);
    return tx;
}
Also used : Transaction(io.nuls.core.chain.entity.Transaction) AbstractCoinTransaction(io.nuls.ledger.entity.tx.AbstractCoinTransaction) LockNulsTransaction(io.nuls.ledger.entity.tx.LockNulsTransaction) NulsDigestData(io.nuls.core.chain.entity.NulsDigestData) NulsByteBuffer(io.nuls.core.utils.io.NulsByteBuffer)

Aggregations

NulsByteBuffer (io.nuls.core.utils.io.NulsByteBuffer)9 NulsDigestData (io.nuls.core.chain.entity.NulsDigestData)3 Transaction (io.nuls.core.chain.entity.Transaction)3 NulsException (io.nuls.core.exception.NulsException)3 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)3 P2PKHScriptSig (io.nuls.core.script.P2PKHScriptSig)2 AbstractCoinTransaction (io.nuls.ledger.entity.tx.AbstractCoinTransaction)2 LockNulsTransaction (io.nuls.ledger.entity.tx.LockNulsTransaction)2 ValidateResult (io.nuls.core.validate.ValidateResult)1 TransferTransaction (io.nuls.ledger.entity.tx.TransferTransaction)1 TransactionEvent (io.nuls.ledger.event.TransactionEvent)1 IOException (java.io.IOException)1