use of org.aion.types.AionAddress in project aion by aionnetwork.
the class AionTxExecSummary method toString.
@Override
public String toString() {
StringBuilder s = new StringBuilder();
s.append(receipt.toString()).append("\n");
s.append("value= ").append(value).append("\n");
s.append("deletedAccounts [");
if (!deletedAccounts.isEmpty()) {
s.append("\n");
for (AionAddress a : deletedAccounts) {
s.append(" ").append(a).append("\n");
}
}
s.append("]\n");
return s.toString();
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class AionTransaction method create.
/**
* Factory method used by most of the kernel to create AionTransactions
*/
public static AionTransaction create(ECKey key, byte[] nonce, AionAddress destination, byte[] value, byte[] data, long energyLimit, long energyPrice, byte type, byte[] beaconHash) {
byte[] timeStamp = ByteUtil.longToBytes(TimeInstant.now().toEpochMicro());
byte[] transactionHashWithoutSignature = HashUtil.h256(TxUtil.rlpEncodeWithoutSignature(nonce, destination, value, data, timeStamp, energyLimit, energyPrice, type, beaconHash));
ISignature signature = key.sign(transactionHashWithoutSignature);
byte[] rlpEncoding = TxUtil.rlpEncode(nonce, destination, value, data, timeStamp, energyLimit, energyPrice, type, signature, beaconHash);
byte[] transactionHash = HashUtil.h256(rlpEncoding);
return new AionTransaction(nonce, new AionAddress(key.getAddress()), destination, value, data, energyLimit, energyPrice, type, timeStamp, transactionHashWithoutSignature, signature, rlpEncoding, transactionHash, beaconHash);
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class AionTransaction method createGivenTimestamp.
/**
* Factory method used by some tests to create multiple transactions with the same timestamp
*/
public static AionTransaction createGivenTimestamp(ECKey key, byte[] nonce, AionAddress destination, byte[] value, byte[] data, long energyLimit, long energyPrice, byte type, byte[] timeStamp, byte[] beaconHash) {
byte[] transactionHashWithoutSignature = HashUtil.h256(TxUtil.rlpEncodeWithoutSignature(nonce, destination, value, data, timeStamp, energyLimit, energyPrice, type, beaconHash));
ISignature signature = key.sign(transactionHashWithoutSignature);
byte[] rlpEncoding = TxUtil.rlpEncode(nonce, destination, value, data, timeStamp, energyLimit, energyPrice, type, signature, beaconHash);
byte[] transactionHash = HashUtil.h256(rlpEncoding);
return new AionTransaction(nonce, new AionAddress(key.getAddress()), destination, value, data, energyLimit, energyPrice, type, timeStamp, transactionHashWithoutSignature, signature, rlpEncoding, transactionHash, beaconHash);
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class InvokableTxUtil method decode.
public static InternalTransaction decode(byte[] encodingWithVersion, AionAddress callingAddress, long energyPrice, long energyLimit) {
// Right now we only have version 0, so if it is not 0, return null
if (encodingWithVersion[0] != 0) {
return null;
}
byte[] rlpEncoding = Arrays.copyOfRange(encodingWithVersion, 1, encodingWithVersion.length);
try {
SharedRLPList decodedTxList = RLP.decode2SharedList(rlpEncoding);
RLPElement element = decodedTxList.get(0);
if (!element.isList()) {
throw new IllegalArgumentException("The rlp decode error, the decoded item should be a list");
}
SharedRLPList tx = (SharedRLPList) element;
BigInteger nonce = new BigInteger(1, tx.get(RLP_META_TX_NONCE).getRLPData());
BigInteger value = new BigInteger(1, tx.get(RLP_META_TX_VALUE).getRLPData());
byte[] data = tx.get(RLP_META_TX_DATA).getRLPData();
AionAddress destination;
try {
destination = new AionAddress(tx.get(RLP_META_TX_TO).getRLPData());
} catch (Exception e) {
destination = null;
}
AionAddress executor;
try {
executor = new AionAddress(tx.get(RLP_META_TX_EXECUTOR).getRLPData());
} catch (Exception e) {
executor = null;
}
if (executor != null && !executor.equals(AddressUtils.ZERO_ADDRESS) && !executor.equals(callingAddress)) {
return null;
}
byte[] sigs = tx.get(RLP_META_TX_SIG).getRLPData();
ISignature signature;
AionAddress sender;
if (sigs != null) {
// Singature Factory will decode the signature based on the algo
// presetted in main() entry.
ISignature is = SignatureFac.fromBytes(sigs);
if (is != null) {
signature = is;
sender = new AionAddress(is.getAddress());
} else {
return null;
}
} else {
return null;
}
return createFromRlp(nonce, sender, destination, value, data, executor, energyLimit, energyPrice, signature, encodingWithVersion);
} catch (Exception e) {
LOG.error("Invokable tx -> unable to decode rlpEncoding. " + e);
return null;
}
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class AionBlockchainImpl method isValid.
public boolean isValid(BlockHeader header) {
/*
* The block header should already be validated at this point by P2P or mining,
* but we are including the validation in case future import paths forget to add it.
*/
if (!this.headerValidator.validate(header, LOG)) {
return false;
}
Block[] threeGenParents = repository.getBlockStore().getThreeGenerationBlocksByHashWithInfo(header.getParentHash());
Block parentBlock = threeGenParents[0];
if (parentBlock == null) {
return false;
}
Block grandparentBlock = threeGenParents[1];
Block greatGrandparentBlock = threeGenParents[2];
if (header.getSealType() == Seal.PROOF_OF_WORK) {
if (forkUtility.isUnityForkActive(header.getNumber())) {
if (grandparentBlock == null || greatGrandparentBlock == null) {
return false;
}
return unityParentBlockHeaderValidator.validate(header, parentBlock.getHeader(), LOG, null) && unityGreatGrandParentBlockHeaderValidator.validate(grandparentBlock.getHeader(), greatGrandparentBlock.getHeader(), header, LOG);
} else {
return preUnityParentBlockHeaderValidator.validate(header, parentBlock.getHeader(), LOG, null) && preUnityGrandParentBlockHeaderValidator.validate(parentBlock.getHeader(), grandparentBlock == null ? null : grandparentBlock.getHeader(), header, LOG);
}
} else if (header.getSealType() == Seal.PROOF_OF_STAKE) {
if (!forkUtility.isUnityForkActive(header.getNumber())) {
LOG.warn("Trying to import a Staking block when the Unity fork is not active.");
return false;
}
if (grandparentBlock == null) {
LOG.warn("Staking block {} cannot find its grandparent", header.getNumber());
return false;
}
if (forkUtility.isUnityForkBlock(parentBlock.getNumber())) {
BigInteger expectedDiff = calculateFirstPoSDifficultyAtBlock(parentBlock);
if (!expectedDiff.equals(header.getDifficultyBI())) {
return false;
}
grandparentBlock = new GenesisStakingBlock(expectedDiff);
} else if (forkUtility.isNonceForkBlock(parentBlock.getNumber())) {
BigInteger expectedDiff = calculateFirstPoSDifficultyAtBlock(parentBlock);
if (!expectedDiff.equals(header.getDifficultyBI())) {
return false;
}
}
BigInteger stake = null;
try {
stake = getStakingContractHelper().getEffectiveStake(new AionAddress(AddressSpecs.computeA0Address(((StakingBlockHeader) header).getSigningPublicKey())), ((StakingBlockHeader) header).getCoinbase(), parentBlock);
} catch (Exception e) {
LOG.error("Shutdown due to a fatal error encountered while getting the effective stake.", e);
System.exit(SystemExitCodes.FATAL_VM_ERROR);
}
boolean result = unityParentBlockHeaderValidator.validate(header, parentBlock.getHeader(), LOG, stake);
if (result) {
if (forkUtility.isSignatureSwapForkActive(header.getNumber())) {
result = vrfProofValidator.validate(parentBlock.getHeader(), grandparentBlock.getHeader(), header, LOG) && difficultyValidateAfterSeedNonceFork(grandparentBlock.getHeader(), greatGrandparentBlock.getHeader(), header);
} else if (forkUtility.isNonceForkActive(header.getNumber())) {
result = nonceSeedValidator.validate(grandparentBlock.getHeader(), parentBlock.getHeader(), header, LOG) && difficultyValidateAfterSeedNonceFork(grandparentBlock.getHeader(), greatGrandparentBlock.getHeader(), header);
} else {
result = unityGreatGrandParentBlockHeaderValidator.validate(grandparentBlock.getHeader(), greatGrandparentBlock.getHeader(), header, LOG);
}
}
return result;
} else {
LOG.debug("Invalid header seal type!");
return false;
}
}
Aggregations