Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting an API for the Virtual Machine #48

Closed
wants to merge 10 commits into from
Binary file modified mod/modAionBase.jar
Binary file not shown.
1 change: 1 addition & 0 deletions src/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
requires protobuf.java;
requires jsr305;
requires gson;
requires aion.vm.api;

exports org.aion.api;
exports org.aion.api.type;
Expand Down
8 changes: 4 additions & 4 deletions src/org/aion/api/IAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.util.List;
import org.aion.api.type.ApiMsg;
import org.aion.base.type.Address;
import org.aion.base.type.Hash256;
import org.aion.vm.api.interfaces.Address;

/**
* This interface dedicate to contact with Aion kernel for certain purpose.
Expand Down Expand Up @@ -134,9 +134,9 @@ public interface IAdmin {
* Get detailed account information, given a string of addresses.
*
* @param addresses list of addresses
* @return the interface {@link java.util.List List} of the class {@link
* org.aion.base.type.Address Address} wrapped into ApiMsg. You can retrieve through the
* method {@link ApiMsg#getObject() getObject}.
* @return the interface {@link java.util.List List} of the class {@link Address Address}
* wrapped into ApiMsg. You can retrieve through the method {@link ApiMsg#getObject()
* getObject}.
* <p>The kernel will only return the first 1000 account details that fit the query
* interval.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/org/aion/api/IChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import org.aion.api.type.ApiMsg;
import org.aion.api.type.Block;
import org.aion.api.type.Transaction;
import org.aion.base.type.Address;
import org.aion.base.type.Hash256;
import org.aion.vm.api.interfaces.Address;

/**
* This interface provides methods for fetching blockchain specific details such as blocks and
Expand Down
2 changes: 1 addition & 1 deletion src/org/aion/api/IContract.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import org.aion.api.type.ContractResponse;
import org.aion.api.type.JsonFmt;
import org.aion.api.type.TxArgs;
import org.aion.base.type.Address;
import org.aion.base.type.Hash256;
import org.aion.base.util.ByteArrayWrapper;
import org.aion.vm.api.interfaces.Address;

/**
* A Contract class that sits above the Aion Java API layer that provides the user with convenient
Expand Down
2 changes: 1 addition & 1 deletion src/org/aion/api/IContractController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Map;
import org.aion.api.sol.ISolidityArg;
import org.aion.api.type.ApiMsg;
import org.aion.base.type.Address;
import org.aion.vm.api.interfaces.Address;

/**
* This interface provides methods for deploy the contract to the Aion blockchain network, store the
Expand Down
2 changes: 1 addition & 1 deletion src/org/aion/api/ITx.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import org.aion.api.type.MsgRsp;
import org.aion.api.type.TxArgs;
import org.aion.api.type.TxReceipt;
import org.aion.base.type.Address;
import org.aion.base.type.Hash256;
import org.aion.base.util.ByteArrayWrapper;
import org.aion.vm.api.interfaces.Address;

/**
* ITx is an interface of the class Transaction. ITx assists in providing methods for transaction
Expand Down
2 changes: 1 addition & 1 deletion src/org/aion/api/IWallet.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.aion.api;

import org.aion.api.type.ApiMsg;
import org.aion.base.type.Address;
import org.aion.vm.api.interfaces.Address;

/**
* This interface is an interface for the class Wallet. Assists in account related interactions.
Expand Down
2 changes: 1 addition & 1 deletion src/org/aion/api/impl/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
import org.aion.api.type.Key;
import org.aion.api.type.KeyExport;
import org.aion.api.type.core.account.KeystoreFormat;
import org.aion.base.type.Address;
import org.aion.base.util.ByteUtil;
import org.aion.base.util.TypeConverter;
import org.aion.crypto.ECKey;
import org.aion.crypto.ECKeyFac;
import org.aion.vm.api.interfaces.Address;
import org.slf4j.Logger;

/** Created by Jay Tseng on 19/04/17. */
Expand Down
5 changes: 3 additions & 2 deletions src/org/aion/api/impl/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
import org.aion.api.type.Block;
import org.aion.api.type.BlockDetails;
import org.aion.api.type.BlockSql;
import org.aion.base.type.Address;
import org.aion.base.type.AionAddress;
import org.aion.base.type.Hash256;
import org.aion.base.util.ByteUtil;
import org.aion.vm.api.interfaces.Address;
import org.slf4j.Logger;

public class Admin implements IAdmin {
Expand Down Expand Up @@ -160,7 +161,7 @@ private List<Address> parseAddressList(String addresses) {
String[] parts = addresses.split(",");
List<Address> addressList = new ArrayList<>();
for (String part : parts) {
addressList.add(new Address(part));
addressList.add(new AionAddress(part));
}

return addressList;
Expand Down
5 changes: 3 additions & 2 deletions src/org/aion/api/impl/ApiBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
import org.aion.api.type.ApiMsg;
import org.aion.api.type.Event;
import org.aion.api.type.MsgRsp;
import org.aion.base.type.Address;
import org.aion.base.type.AionAddress;
import org.aion.base.util.ByteArrayWrapper;
import org.aion.vm.api.interfaces.Address;
import org.slf4j.Logger;
import org.zeromq.ZMQ;

Expand All @@ -26,7 +27,7 @@ public class ApiBase {
AtomicBoolean isInitialized = new AtomicBoolean(false);
// END PRIVATE MEMBERS --------------------------------------------
Address minerAddress;
Address defaultAccount = Address.EMPTY_ADDRESS();
Address defaultAccount = AionAddress.EMPTY_ADDRESS();
String url;
boolean nb = false;
int timeout = 300_000;
Expand Down
5 changes: 3 additions & 2 deletions src/org/aion/api/impl/Chain.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
import org.aion.api.type.ApiMsg;
import org.aion.api.type.ApiMsg.cast;
import org.aion.api.type.Block;
import org.aion.base.type.Address;
import org.aion.base.type.AionAddress;
import org.aion.base.type.Hash256;
import org.aion.base.util.ByteArrayWrapper;
import org.aion.base.util.ByteUtil;
import org.aion.vm.api.interfaces.Address;
import org.slf4j.Logger;

/** Created by Jay Tseng on 14/11/16. */
Expand Down Expand Up @@ -531,7 +532,7 @@ private static Block toBlock(Message.rsp_getBlock rsp) {
.difficulty(new BigInteger(rsp.getDifficulty().toByteArray()))
.extraData(ByteArrayWrapper.wrap(rsp.getExtraData().toByteArray()))
.nonce(new BigInteger(rsp.getNonce().toByteArray()))
.miner(Address.wrap(rsp.getMinerAddress().toByteArray()))
.miner(AionAddress.wrap(rsp.getMinerAddress().toByteArray()))
.nrgConsumed(rsp.getNrgConsumed())
.nrgLimit(rsp.getNrgLimit())
.txTrieRoot(Hash256.wrap(rsp.getTxTrieRoot().toByteArray()))
Expand Down
7 changes: 4 additions & 3 deletions src/org/aion/api/impl/Contract.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@
import org.aion.api.type.JsonFmt;
import org.aion.api.type.MsgRsp;
import org.aion.api.type.TxArgs;
import org.aion.base.type.Address;
import org.aion.base.type.AionAddress;
import org.aion.base.type.Hash256;
import org.aion.base.util.ByteArrayWrapper;
import org.aion.vm.api.interfaces.Address;
import org.apache.commons.collections4.map.LRUMap;
import org.slf4j.Logger;

Expand Down Expand Up @@ -70,7 +71,7 @@ public final class Contract implements IContract {

private final AionAPIImpl api;
private final String contractName;
private final org.aion.base.type.Address contractAddress;
private final Address contractAddress;
private final List<ContractAbiEntry> abiDefinition;
private final Map<String, List<ContractAbiEntry>> funcParams;
private final String abiDefStr;
Expand Down Expand Up @@ -416,7 +417,7 @@ TxArgs encodeParams(ContractAbiEntry func) {
.nrgPrice(this.txNrgPrice)
.nrgLimit(this.txNrgLimit)
.from(this.from)
.to(isConstructor ? Address.EMPTY_ADDRESS() : this.contractAddress)
.to(isConstructor ? AionAddress.EMPTY_ADDRESS() : this.contractAddress)
.data(
isConstructor
? ByteArrayWrapper.wrap(assembled.toString().getBytes())
Expand Down
2 changes: 1 addition & 1 deletion src/org/aion/api/impl/ContractController.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import org.aion.api.type.ContractDeploy;
import org.aion.api.type.DeployResponse;
import org.aion.api.type.JsonFmt;
import org.aion.base.type.Address;
import org.aion.base.type.Hash256;
import org.aion.base.util.ByteArrayWrapper;
import org.aion.vm.api.interfaces.Address;
import org.slf4j.Logger;

public final class ContractController implements IContractController {
Expand Down
4 changes: 2 additions & 2 deletions src/org/aion/api/impl/MsgExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.aion.api.type.ContractEvent;
import org.aion.api.type.Event;
import org.aion.api.type.MsgRsp;
import org.aion.base.type.Address;
import org.aion.base.type.AionAddress;
import org.aion.base.type.Hash256;
import org.aion.base.util.ByteArrayWrapper;
import org.aion.base.util.ByteUtil;
Expand Down Expand Up @@ -294,7 +294,7 @@ private void updateEvent(ByteArrayWrapper data) {
for (Message.t_EventCt cte : evt.getEcList()) {
ContractEvent.ContractEventBuilder builder =
new ContractEvent.ContractEventBuilder()
.address(Address.wrap(cte.getAddress().toByteArray()))
.address(AionAddress.wrap(cte.getAddress().toByteArray()))
.blockHash(Hash256.wrap(cte.getBlockHash().toByteArray()))
.blockNumber(cte.getBlockNumber())
.data(ByteArrayWrapper.wrap(cte.getData().toByteArray()))
Expand Down
9 changes: 5 additions & 4 deletions src/org/aion/api/impl/Tx.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
import org.aion.api.type.TxArgs;
import org.aion.api.type.TxArgs.TxArgsBuilder;
import org.aion.api.type.core.tx.AionTransaction;
import org.aion.base.type.Address;
import org.aion.base.type.AionAddress;
import org.aion.base.type.Hash256;
import org.aion.base.util.ByteArrayWrapper;
import org.aion.base.util.ByteUtil;
import org.aion.base.util.Hex;
import org.aion.crypto.ECKey;
import org.aion.crypto.ECKeyFac;
import org.aion.vm.api.interfaces.Address;
import org.slf4j.Logger;

/** Created by Jay Tseng on 15/11/16. */
Expand Down Expand Up @@ -110,7 +111,7 @@ public ApiMsg contractDeploy(ContractDeploy cd) {
Message.rsp_contractDeploy.parseFrom(rsp.getTxDeploy().toBytes());
return new ApiMsg(
new DeployResponse(
Address.wrap(msgRsp.getContractAddress().toByteArray()),
AionAddress.wrap(msgRsp.getContractAddress().toByteArray()),
Hash256.wrap(msgRsp.getTxHash().toByteArray())),
ApiMsg.cast.OTHERS);

Expand Down Expand Up @@ -688,8 +689,8 @@ public ApiMsg estimateNrg(String code) {
new TxArgsBuilder()
.data(ByteArrayWrapper.wrap(byteCode))
.from(
apiInst.defaultAccount.equals(Address.EMPTY_ADDRESS())
? Address.wrap(
apiInst.defaultAccount.equals(AionAddress.EMPTY_ADDRESS())
? AionAddress.wrap(
"0xa000000000000000000000000000000000000000000000000000000000000000")
: apiInst.defaultAccount)
.createTxArgs();
Expand Down
7 changes: 4 additions & 3 deletions src/org/aion/api/impl/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
import org.aion.api.log.AionLoggerFactory;
import org.aion.api.log.LogEnum;
import org.aion.api.type.ApiMsg;
import org.aion.base.type.Address;
import org.aion.base.type.AionAddress;
import org.aion.base.util.ByteUtil;
import org.aion.vm.api.interfaces.Address;
import org.slf4j.Logger;

/** Created by Jay Tseng on 14/11/16. */
Expand Down Expand Up @@ -45,7 +46,7 @@ public ApiMsg getAccounts() {

List<Address> account = new ArrayList<>();
for (ByteString bs : accBs) {
account.add(Address.wrap(bs.toByteArray()));
account.add(AionAddress.wrap(bs.toByteArray()));
}

if (LOGGER.isDebugEnabled()) {
Expand Down Expand Up @@ -134,7 +135,7 @@ public ApiMsg getMinerAccount() {
try {
Message.rsp_minerAddress msgRsp =
Message.rsp_minerAddress.parseFrom(ApiUtils.parseBody(rsp).getData());
this.apiInst.minerAddress = Address.wrap(msgRsp.getMinerAddr().toByteArray());
this.apiInst.minerAddress = AionAddress.wrap(msgRsp.getMinerAddr().toByteArray());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("[getMinerAccount] minerAddress: [{}]", this.apiInst.minerAddress);
}
Expand Down
Loading