Skip to content

Commit

Permalink
separate use of Address interface vs AionAddress implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandraRoatis committed Jan 23, 2019
1 parent 11632c7 commit de932d9
Show file tree
Hide file tree
Showing 98 changed files with 2,101 additions and 1,907 deletions.
2 changes: 1 addition & 1 deletion aion_api
Submodule aion_api updated 39 files
+5 −5 src/org/aion/api/IAdmin.java
+13 −13 src/org/aion/api/IChain.java
+7 −7 src/org/aion/api/IContract.java
+20 −20 src/org/aion/api/IContractController.java
+9 −9 src/org/aion/api/ITx.java
+12 −12 src/org/aion/api/IWallet.java
+3 −3 src/org/aion/api/impl/Account.java
+4 −3 src/org/aion/api/impl/Admin.java
+3 −2 src/org/aion/api/impl/ApiBase.java
+8 −7 src/org/aion/api/impl/Chain.java
+8 −7 src/org/aion/api/impl/Contract.java
+13 −13 src/org/aion/api/impl/ContractController.java
+6 −5 src/org/aion/api/impl/Tx.java
+6 −5 src/org/aion/api/impl/Wallet.java
+5 −3 src/org/aion/api/impl/internal/ApiUtils.java
+5 −5 src/org/aion/api/sol/ISolidityArg.java
+5 −5 src/org/aion/api/tools/ApiDemo.java
+10 −8 src/org/aion/api/tools/Erc20Demo.java
+9 −9 src/org/aion/api/tools/PerfBench.java
+5 −5 src/org/aion/api/type/AccountDetails.java
+5 −5 src/org/aion/api/type/Block.java
+5 −5 src/org/aion/api/type/BlockDetails.java
+5 −5 src/org/aion/api/type/ContractDeploy.java
+5 −5 src/org/aion/api/type/ContractEvent.java
+5 −5 src/org/aion/api/type/ContractEventFilter.java
+4 −4 src/org/aion/api/type/DeployResponse.java
+5 −5 src/org/aion/api/type/Key.java
+4 −4 src/org/aion/api/type/KeyExport.java
+9 −9 src/org/aion/api/type/Transaction.java
+9 −8 src/org/aion/api/type/TxArgs.java
+13 −13 src/org/aion/api/type/TxDetails.java
+4 −4 src/org/aion/api/type/TxLog.java
+13 −13 src/org/aion/api/type/TxReceipt.java
+6 −7 src/org/aion/api/type/core/tx/AbstractTransaction.java
+15 −9 src/org/aion/api/type/core/tx/AionTransaction.java
+46 −45 test/org/aion/api/test/BaseAPITests.java
+29 −26 test/org/aion/api/test/ContractTests.java
+4 −4 test/org/aion/api/test/MyToken.java
+17 −15 test/org/aion/api/test/SimpleBench.java
2 changes: 1 addition & 1 deletion aion_vm_api
3 changes: 2 additions & 1 deletion modAion/src/org/aion/zero/api/BlockConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.aion.base.type.AionAddress;
import org.aion.mcf.blockchain.IBlockConstants;
import org.aion.mcf.types.AbstractBlockHeader;
import org.aion.vm.api.interfaces.Address;

public class BlockConstants implements IBlockConstants {

Expand Down Expand Up @@ -178,7 +179,7 @@ public long getClockDriftBufferTime() {
*
* @return {@code address} of the sk owning this pair. Also referred to as the owner's address.
*/
public AionAddress getTokenBridgingAddress() {
public Address getTokenBridgingAddress() {
return AionAddress.ZERO_ADDRESS();
}

Expand Down
11 changes: 6 additions & 5 deletions modAion/src/org/aion/zero/types/A0BlockHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.aion.mcf.types.AbstractBlockHeader;
import org.aion.rlp.RLP;
import org.aion.rlp.RLPList;
import org.aion.vm.api.interfaces.Address;
import org.aion.zero.exceptions.HeaderStructureException;
import org.json.JSONObject;

Expand Down Expand Up @@ -205,7 +206,7 @@ public A0BlockHeader(
byte version,
long number,
byte[] parentHash,
AionAddress coinbase,
Address coinbase,
byte[] logsBloom,
byte[] difficulty,
byte[] extraData,
Expand All @@ -215,7 +216,7 @@ public A0BlockHeader(
byte[] nonce,
byte[] solution) {
this.version = version;
this.coinbase = coinbase;
this.coinbase = (AionAddress) coinbase;
this.parentHash = parentHash;
this.logsBloom = logsBloom;
this.difficulty = difficulty;
Expand Down Expand Up @@ -558,11 +559,11 @@ public static class Builder {
* Some constants for fallbacks, these are not rigorously defined this;
* TODO: define these with explanations in the future
*/
protected AionAddress EMPTY_ADDRESS = AionAddress.EMPTY_ADDRESS();
protected Address EMPTY_ADDRESS = AionAddress.EMPTY_ADDRESS();

protected byte version;
protected byte[] parentHash;
protected AionAddress coinbase;
protected Address coinbase;
protected byte[] stateRoot;
protected byte[] txTrieRoot;
protected byte[] receiptTrieRoot;
Expand Down Expand Up @@ -620,7 +621,7 @@ public Builder withParentHash(byte[] parentHash) throws HeaderStructureException
return this;
}

public Builder withCoinbase(AionAddress coinbase) throws HeaderStructureException {
public Builder withCoinbase(Address coinbase) throws HeaderStructureException {
if (isFromUnsafeSource) {
if (coinbase == null)
throw new HeaderStructureException(
Expand Down
2 changes: 1 addition & 1 deletion modAion/src/org/aion/zero/types/AionTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public ISignature getSignature() {
return signature;
}

public AionAddress getContractAddress() {
public Address getContractAddress() {
if (!this.isContractCreationTransaction()) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions modAion/src/org/aion/zero/types/IAionBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import java.math.BigInteger;
import java.util.List;
import org.aion.base.type.AionAddress;
import org.aion.base.type.IBlock;
import org.aion.vm.api.interfaces.Address;

/** aion block interface. */
public interface IAionBlock extends IBlock<AionTransaction, A0BlockHeader> {

AionAddress getCoinbase();
Address getCoinbase();

long getTimestamp();

Expand Down
11 changes: 6 additions & 5 deletions modAion/test/org/aion/types/AionTransactionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.aion.base.type.AionAddress;
import org.aion.crypto.ECKeyFac;
import org.aion.mcf.vm.types.DataWord;
import org.aion.vm.api.interfaces.Address;
import org.aion.zero.types.AionTransaction;
import org.apache.commons.lang3.RandomUtils;
import org.junit.Test;
Expand All @@ -30,7 +31,7 @@ private void assertTransactionEquals(AionTransaction tx, AionTransaction tx2) {
@Test
public void testSerializationZero() {
byte[] nonce = RandomUtils.nextBytes(16);
AionAddress to = AionAddress.wrap(RandomUtils.nextBytes(32));
Address to = AionAddress.wrap(RandomUtils.nextBytes(32));
byte[] value = RandomUtils.nextBytes(16);
byte[] data = RandomUtils.nextBytes(64);
long nrg = 0;
Expand All @@ -48,7 +49,7 @@ public void testSerializationZero() {
@Test
public void testClone() {
byte[] nonce = RandomUtils.nextBytes(16);
AionAddress to = AionAddress.wrap(RandomUtils.nextBytes(32));
Address to = AionAddress.wrap(RandomUtils.nextBytes(32));
byte[] value = RandomUtils.nextBytes(16);
byte[] data = RandomUtils.nextBytes(64);
long nrg = RandomUtils.nextLong(0, Long.MAX_VALUE);
Expand All @@ -67,7 +68,7 @@ public void testClone() {
public void testTransactionCost() {
byte[] nonce = DataWord.ONE.getData();
byte[] from = RandomUtils.nextBytes(20);
byte[] to = RandomUtils.nextBytes(AionAddress.SIZE);
byte[] to = RandomUtils.nextBytes(Address.SIZE);
byte[] value = DataWord.ONE.getData();
byte[] data = RandomUtils.nextBytes(128);
long nrg = new DataWord(1000L).longValue();
Expand All @@ -86,8 +87,8 @@ public void testTransactionCost() {
@Test
public void testTransactionCost2() {
byte[] nonce = DataWord.ONE.getData();
byte[] from = RandomUtils.nextBytes(AionAddress.SIZE);
AionAddress to = AionAddress.EMPTY_ADDRESS();
byte[] from = RandomUtils.nextBytes(Address.SIZE);
Address to = AionAddress.EMPTY_ADDRESS();
byte[] value = DataWord.ONE.getData();
byte[] data = RandomUtils.nextBytes(128);
long nrg = new DataWord(1000L).longValue();
Expand Down
6 changes: 4 additions & 2 deletions modAionBase/src/org/aion/base/type/IBlockHeader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.aion.base.type;

import org.aion.vm.api.interfaces.Address;

/** @author jay */
public interface IBlockHeader {

Expand All @@ -22,14 +24,14 @@ public interface IBlockHeader {

byte[] getEncoded();

AionAddress getCoinbase();
Address getCoinbase();

long getTimestamp();

long getNumber();

// Setter
void setCoinbase(AionAddress _cb);
void setCoinbase(Address _cb);

void setStateRoot(byte[] _strt);

Expand Down
26 changes: 18 additions & 8 deletions modAionBase/test/org/aion/base/type/AddressTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public void testCompare() {
for (int b = 3; b < 6; b++) {
try {
int temp = AionAddress.wrap(addrHex[b]).compareTo(AionAddress.wrap(addrHex[b + 1]));
boolean same = AionAddress.wrap(addrHex[b]).equals(AionAddress.wrap(addrHex[b + 1]));
boolean same =
AionAddress.wrap(addrHex[b]).equals(AionAddress.wrap(addrHex[b + 1]));
boolean negative = temp < 0;
System.out.println("Test " + b + " & " + (b + 1) + " >> " + temp);
assertFalse(same);
Expand All @@ -130,7 +131,8 @@ public void testCompare() {
for (int b = 6; b > 3; b--) {
try {
int temp = AionAddress.wrap(addrHex[b]).compareTo(AionAddress.wrap(addrHex[b - 1]));
boolean same = AionAddress.wrap(addrHex[b]).equals(AionAddress.wrap(addrHex[b - 1]));
boolean same =
AionAddress.wrap(addrHex[b]).equals(AionAddress.wrap(addrHex[b - 1]));
boolean positive = temp > 0;
System.out.println("Test " + b + " & " + (b - 1) + " >> " + temp);
assertFalse(same);
Expand All @@ -144,7 +146,8 @@ public void testCompare() {
for (int b = 3; b < 6; b++) {
try {
int temp = AionAddress.wrap(addrByte[b]).compareTo(addrByte[b + 1]);
boolean same = AionAddress.wrap(addrByte[b]).equals(AionAddress.wrap(addrByte[b + 1]));
boolean same =
AionAddress.wrap(addrByte[b]).equals(AionAddress.wrap(addrByte[b + 1]));
boolean negative = temp < 0;
System.out.println("Test " + b + " & " + (b + 1) + " >> " + temp);
assertFalse(same);
Expand All @@ -156,7 +159,8 @@ public void testCompare() {
for (int b = 6; b > 3; b--) {
try {
int temp = AionAddress.wrap(addrByte[b]).compareTo(addrByte[b - 1]);
boolean same = AionAddress.wrap(addrByte[b]).equals(AionAddress.wrap(addrByte[b - 1]));
boolean same =
AionAddress.wrap(addrByte[b]).equals(AionAddress.wrap(addrByte[b - 1]));
boolean positive = temp > 0;
System.out.println("Test " + b + " & " + (b - 1) + " >> " + temp);
assertFalse(same);
Expand All @@ -169,8 +173,11 @@ public void testCompare() {
System.out.println("\nArray address test:");
for (int b = 3; b < 6; b++) {
try {
int temp = AionAddress.wrap(addrArray[b]).compareTo(AionAddress.wrap(addrArray[b + 1]));
boolean same = AionAddress.wrap(addrArray[b]).equals(AionAddress.wrap(addrArray[b + 1]));
int temp =
AionAddress.wrap(addrArray[b])
.compareTo(AionAddress.wrap(addrArray[b + 1]));
boolean same =
AionAddress.wrap(addrArray[b]).equals(AionAddress.wrap(addrArray[b + 1]));
boolean negative = temp < 0;
System.out.println("Test " + b + " & " + (b + 1) + " >> " + temp);
assertFalse(same);
Expand All @@ -181,8 +188,11 @@ public void testCompare() {
}
for (int b = 6; b > 3; b--) {
try {
int temp = AionAddress.wrap(addrArray[b]).compareTo(AionAddress.wrap(addrArray[b - 1]));
boolean same = AionAddress.wrap(addrArray[b]).equals(AionAddress.wrap(addrArray[b - 1]));
int temp =
AionAddress.wrap(addrArray[b])
.compareTo(AionAddress.wrap(addrArray[b - 1]));
boolean same =
AionAddress.wrap(addrArray[b]).equals(AionAddress.wrap(addrArray[b - 1]));
boolean positive = temp > 0;
System.out.println("Test " + b + " & " + (b - 1) + " >> " + temp);
assertFalse(same);
Expand Down
6 changes: 3 additions & 3 deletions modAionImpl/src/org/aion/zero/impl/A0BCConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.aion.zero.impl;

import org.aion.base.type.AionAddress;
import org.aion.vm.api.interfaces.Address;
import org.aion.zero.impl.core.energy.AbstractEnergyStrategyLimit;

public interface A0BCConfig {
Expand All @@ -11,7 +11,7 @@ public interface A0BCConfig {
*
* @return {@code coinbase} a 32-bytes address
*/
AionAddress getCoinbase();
Address getCoinbase();

/**
* Retrieve the currently set extra data for this particular node, blocks mined with this node
Expand All @@ -28,7 +28,7 @@ public interface A0BCConfig {
*/
boolean getExitOnBlockConflict();

AionAddress getMinerCoinbase();
Address getMinerCoinbase();

/** Retrieves the number indicating how many blocks between each flush */
int getFlushInterval();
Expand Down
18 changes: 9 additions & 9 deletions modAionImpl/src/org/aion/zero/impl/AionBlockchainImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public class AionBlockchainImpl implements IAionBlockchain {

private boolean fork = false;

private AionAddress minerCoinbase;
private Address minerCoinbase;
private byte[] minerExtraData;

private Stack<State> stateStack = new Stack<>();
Expand All @@ -160,7 +160,7 @@ private static A0BCConfig generateBCConfig(CfgAion cfgAion) {
ChainConfiguration config = new ChainConfiguration();
return new A0BCConfig() {
@Override
public AionAddress getCoinbase() {
public Address getCoinbase() {
return cfgAion.getGenesis().getCoinbase();
}

Expand All @@ -176,7 +176,7 @@ public boolean getExitOnBlockConflict() {
}

@Override
public AionAddress getMinerCoinbase() {
public Address getMinerCoinbase() {
return AionAddress.wrap(cfgAion.getConsensus().getMinerAddress());
}

Expand Down Expand Up @@ -1053,7 +1053,7 @@ private AionBlockSummary processBlock(AionBlock block) {
} else {
return new AionBlockSummary(
block,
new HashMap<AionAddress, BigInteger>(),
new HashMap<Address, BigInteger>(),
new ArrayList<AionTxReceipt>(),
new ArrayList<AionTxExecSummary>());
}
Expand Down Expand Up @@ -1107,7 +1107,7 @@ private RetValidPreBlock generatePreBlock(IAionBlock block) {
}
}

Map<AionAddress, BigInteger> rewards = addReward(block, summaries);
Map<Address, BigInteger> rewards = addReward(block, summaries);

track.flush();

Expand Down Expand Up @@ -1165,7 +1165,7 @@ private AionBlockSummary applyBlock(IAionBlock block) {

summaries.add(summary);
}
Map<AionAddress, BigInteger> rewards = addReward(block, summaries);
Map<Address, BigInteger> rewards = addReward(block, summaries);

long totalTime = System.nanoTime() - saveTime;
chainStats.addBlockExecTime(totalTime);
Expand All @@ -1178,10 +1178,10 @@ private AionBlockSummary applyBlock(IAionBlock block) {
*
* @param block object containing the header and uncles
*/
private Map<AionAddress, BigInteger> addReward(
private Map<Address, BigInteger> addReward(
IAionBlock block, List<AionTxExecSummary> summaries) {

Map<AionAddress, BigInteger> rewards = new HashMap<>();
Map<Address, BigInteger> rewards = new HashMap<>();
BigInteger minerReward =
this.chainConfiguration.getRewardsCalculator().calculateReward(block.getHeader());
rewards.put(block.getCoinbase(), minerReward);
Expand Down Expand Up @@ -1355,7 +1355,7 @@ public void setExitOn(long exitOn) {
}

@Override
public AionAddress getMinerCoinbase() {
public Address getMinerCoinbase() {
return minerCoinbase;
}

Expand Down
Loading

0 comments on commit de932d9

Please sign in to comment.