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

Add getNrgPrice Java API call. #24

Merged
merged 3 commits into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/org/aion/api/ITx.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ public interface ITx {
*/
ApiMsg eventRegister(List<String> evt, ContractEventFilter ef, Address address);

/**
* getNrgPrice returns a Long value representing the recommended energy price.
* @return the recommended energy price as a long value wrapped into ApiMsg.
* You can retrieve through {@link ApiMsg#getObject() getObject}.
*/
ApiMsg getNrgPrice();


// void removeAllEvents();
//
Expand Down
28 changes: 28 additions & 0 deletions src/org/aion/api/impl/Tx.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@
import com.google.gson.reflect.TypeToken;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import java.math.BigInteger;
import org.aion.api.ITx;
import org.aion.api.impl.internal.ApiUtils;
import org.aion.api.impl.internal.Message;
import org.aion.api.impl.internal.Message.Funcs;
import org.aion.api.impl.internal.Message.Retcode;
import org.aion.api.impl.internal.Message.Servs;
import org.aion.api.log.AionLoggerFactory;
import org.aion.api.log.LogEnum;
import org.aion.api.type.*;
import org.aion.api.type.ApiMsg.cast;
import org.aion.api.type.core.tx.AionTransaction;
import org.aion.base.type.Address;
import org.aion.base.type.Hash256;
Expand Down Expand Up @@ -737,6 +742,29 @@ public ApiMsg eventDeregister(List<String> evt, Address address) {
}
}

public ApiMsg getNrgPrice() {
if (!this.apiInst.isConnected()) {
return new ApiMsg(-1003);
}

byte[] reqHead = ApiUtils.toReqHeader(ApiUtils.PROTOCOL_VER, Servs.s_tx, Funcs.f_getNrgPrice);

byte[] rsp = this.apiInst.nbProcess(reqHead);
int code = this.apiInst.validRspHeader(rsp);
if (code != 1) {
return new ApiMsg(code);
}

try {
return new ApiMsg(Message.rsp_getNrgPrice.parseFrom(ApiUtils.parseBody(rsp).getData()).getNrgPrice(), cast.LONG);
} catch (InvalidProtocolBufferException e) {
if (LOGGER.isErrorEnabled()) {
LOGGER.error("[getNrgPrice] {}", ErrId.getErrString(-104L) + e.getMessage());
}
return new ApiMsg(-104, e.getMessage(), cast.OTHERS);
}
}

//public ApiMsg queryEvents(ContractEventFilter ef, Address address) {
//
// if ( ef == null || address == null) {
Expand Down
Loading