Search in sources :

Example 1 with P2PKHScriptSig

use of io.nuls.core.script.P2PKHScriptSig in project nuls by nuls-io.

the class AccountServiceImpl method createP2PKHScriptSig.

@Override
public P2PKHScriptSig createP2PKHScriptSig(byte[] data, Account account, String password) throws NulsException {
    P2PKHScriptSig p2PKHScriptSig = new P2PKHScriptSig();
    p2PKHScriptSig.setSignData(signData(data, account, password));
    p2PKHScriptSig.setPublicKey(account.getPubKey());
    return p2PKHScriptSig;
}
Also used : P2PKHScriptSig(io.nuls.core.script.P2PKHScriptSig)

Example 2 with P2PKHScriptSig

use of io.nuls.core.script.P2PKHScriptSig in project nuls by nuls-io.

the class HeaderHashValidator method validate.

@Override
public ValidateResult validate(BlockHeader data) {
    ValidateResult result = ValidateResult.getSuccessResult();
    NulsDigestData hash = data.getHash();
    P2PKHScriptSig scriptSig = data.getScriptSig();
    NulsDigestData cfmHash = null;
    try {
        BlockHeader newHeader = new BlockHeader();
        newHeader.parse(data.serialize());
        cfmHash = newHeader.getHash();
    } catch (Exception e) {
        Log.error(e);
    } finally {
        data.setScriptSig(scriptSig);
    }
    if (!cfmHash.getDigestHex().equals(hash.getDigestHex())) {
        result = ValidateResult.getFailedResult(ERROR_MESSAGE);
    }
    return result;
}
Also used : P2PKHScriptSig(io.nuls.core.script.P2PKHScriptSig) ValidateResult(io.nuls.core.validate.ValidateResult) NulsDigestData(io.nuls.core.chain.entity.NulsDigestData) BlockHeader(io.nuls.core.chain.entity.BlockHeader) IOException(java.io.IOException)

Example 3 with P2PKHScriptSig

use of io.nuls.core.script.P2PKHScriptSig in project nuls by nuls-io.

the class GenesisBlock method fillHeader.

private void fillHeader(Map<String, Object> jsonMap) {
    Integer height = (Integer) jsonMap.get(CONFIG_FILED_HEIGHT);
    AssertUtil.canNotEmpty(height, ErrorCode.CONFIG_ERROR);
    BlockHeader header = new BlockHeader();
    this.setHeader(header);
    header.setHeight(height);
    header.setTime(blockTime);
    header.setPreHash(NulsDigestData.EMPTY_HASH);
    header.setTxCount(this.getTxs().size());
    List<NulsDigestData> txHashList = new ArrayList<>();
    for (Transaction tx : this.getTxs()) {
        txHashList.add(tx.getHash());
    }
    header.setMerkleHash(NulsDigestData.calcMerkleDigestData(txHashList));
    BlockRoundData data = new BlockRoundData();
    data.setRoundIndex(1);
    data.setRoundStartTime(header.getTime());
    data.setConsensusMemberCount(1);
    data.setPackingIndexOfRound(1);
    try {
        header.setExtend(data.serialize());
    } catch (IOException e) {
        Log.error(e);
    }
    header.setPackingAddress(address);
    header.setHash(NulsDigestData.calcDigestData(header));
    P2PKHScriptSig p2PKHScriptSig = new P2PKHScriptSig();
    NulsSignData signData = this.signature(header.getHash().getDigestBytes());
    p2PKHScriptSig.setSignData(signData);
    p2PKHScriptSig.setPublicKey(getGenesisPubkey());
    header.setScriptSig(p2PKHScriptSig);
}
Also used : BigInteger(java.math.BigInteger) P2PKHScriptSig(io.nuls.core.script.P2PKHScriptSig) CoinBaseTransaction(io.nuls.ledger.entity.tx.CoinBaseTransaction) BlockRoundData(io.nuls.consensus.entity.block.BlockRoundData) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 4 with P2PKHScriptSig

use of io.nuls.core.script.P2PKHScriptSig 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 5 with P2PKHScriptSig

use of io.nuls.core.script.P2PKHScriptSig 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)

Aggregations

P2PKHScriptSig (io.nuls.core.script.P2PKHScriptSig)9 IOException (java.io.IOException)4 NulsException (io.nuls.core.exception.NulsException)3 ArrayList (java.util.ArrayList)3 NulsDigestData (io.nuls.core.chain.entity.NulsDigestData)2 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)2 NulsByteBuffer (io.nuls.core.utils.io.NulsByteBuffer)2 CoinBaseTransaction (io.nuls.ledger.entity.tx.CoinBaseTransaction)2 BigInteger (java.math.BigInteger)2 Account (io.nuls.account.entity.Account)1 AccountService (io.nuls.account.service.intf.AccountService)1 BlockRoundData (io.nuls.consensus.entity.block.BlockRoundData)1 BlockHeader (io.nuls.core.chain.entity.BlockHeader)1 ValidateResult (io.nuls.core.validate.ValidateResult)1 UtxoData (io.nuls.ledger.entity.UtxoData)1 UtxoInput (io.nuls.ledger.entity.UtxoInput)1 UtxoOutput (io.nuls.ledger.entity.UtxoOutput)1 Coin (io.nuls.ledger.entity.params.Coin)1 CoinTransferData (io.nuls.ledger.entity.params.CoinTransferData)1 List (java.util.List)1