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;
}
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;
}
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);
}
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());
}
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;
}
Aggregations