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

[WIP] Fix Account History API #252

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
<hamcrest.version>2.2</hamcrest.version>
<tyrus.client.version>1.15</tyrus.client.version>
<jackson.version>2.10.0</jackson.version>
<apache.commons.lang.version>3.9</apache.commons.lang.version>
<apache.commons.lang.version>3.8</apache.commons.lang.version>
<apache.commons.io.version>2.6</apache.commons.io.version>
<slf4j.version>1.7.26</slf4j.version>
<log4j.version>2.12.1</log4j.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public enum RequestMethod {
GET_TRANSACTION,
/** Get the full history of an account. */
GET_ACCOUNT_HISTORY,
/** Receive virtual operations for blocks. */
ENUM_VIRTUAL_OPS,
// block_api
/** */
GET_BLOCK,
Expand Down Expand Up @@ -273,6 +275,6 @@ public enum RequestMethod {
GET_ACCOUNT_BANDWIDTH,
/** */
GET_REVERSE_RATIO,

GET_LIQUIDITY_QUEUE
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
import eu.bittrade.libs.steemj.enums.SteemApiType;
import eu.bittrade.libs.steemj.exceptions.SteemCommunicationException;
import eu.bittrade.libs.steemj.exceptions.SteemResponseException;
import eu.bittrade.libs.steemj.plugins.apis.account.history.models.EnumVirtualOps;
import eu.bittrade.libs.steemj.plugins.apis.account.history.models.EnumVirtualOpsArgs;
import eu.bittrade.libs.steemj.plugins.apis.account.history.models.GetAccountHistoryArgs;
import eu.bittrade.libs.steemj.plugins.apis.account.history.models.GetAccountHistoryReturn;
import eu.bittrade.libs.steemj.plugins.apis.account.history.models.GetOpsInBlockArgs;
import eu.bittrade.libs.steemj.plugins.apis.account.history.models.GetOpsInBlockReturn;
import eu.bittrade.libs.steemj.protocol.AnnotatedSignedTransaction;
import eu.bittrade.libs.steemj.protocol.TransactionId;

/**
* This class implements the "account_history_api".
Expand Down Expand Up @@ -71,22 +74,26 @@ private AccountHistoryApi() {
* </ul>
*/
public static GetOpsInBlockReturn getOpsInBlock(CommunicationHandler communicationHandler,
GetOpsInBlockArgs getOpsInBlockArgs) throws SteemCommunicationException, SteemResponseException {
JsonRPCRequest requestObject = new JsonRPCRequest(SteemApiType.ACCOUNT_HISTORY_API,
GetOpsInBlockArgs getOpsInBlockArgs) throws SteemCommunicationException, SteemResponseException {
JsonRPCRequest requestObject = new JsonRPCRequest(SteemApiType.ACCOUNT_HISTORY_API,
RequestMethod.GET_OPS_IN_BLOCK, getOpsInBlockArgs);

return communicationHandler.performRequest(requestObject, GetOpsInBlockReturn.class).get(0);
}

/**
* Find a transaction by its <code>transactionId</code>.
* Returns the details of a transaction based on a
* <code>transactionId</code>.
*
* @deprecated According to
* https://developers.steem.io/apidefinitions/#apidefinitions-account-history-api
* this method is deprecated.
* @param communicationHandler
* A
* {@link eu.bittrade.libs.steemj.communication.CommunicationHandler
* CommunicationHandler} instance that should be used to send the
* request.
* @param transactionId
* @param getTransactionArgs
* The <code>transactionId</code> to search for.
* @return A sequence of operations included/generated within a particular
* block.
Expand All @@ -105,8 +112,9 @@ public static GetOpsInBlockReturn getOpsInBlock(CommunicationHandler communicati
* <li>If the Server returned an error object.</li>
* </ul>
*/
@Deprecated
public static AnnotatedSignedTransaction getTransaction(CommunicationHandler communicationHandler,
GetAccountHistoryArgs getTransactionArgs) throws SteemCommunicationException, SteemResponseException {
TransactionId getTransactionArgs) throws SteemCommunicationException, SteemResponseException {
JsonRPCRequest requestObject = new JsonRPCRequest(SteemApiType.ACCOUNT_HISTORY_API,
RequestMethod.GET_TRANSACTION, getTransactionArgs);

Expand Down Expand Up @@ -151,4 +159,40 @@ public static GetAccountHistoryReturn getAccountHistory(CommunicationHandler com

return communicationHandler.performRequest(requestObject, GetAccountHistoryReturn.class).get(0);
}

/**
* Get all virtual operations in a specified range of blocks..
*
* @param communicationHandler
* A
* {@link eu.bittrade.libs.steemj.communication.CommunicationHandler
* CommunicationHandler} instance that should be used to send the
* request.
* @param enumVirtualOpsArgs
* The user name of the account.
* @return A list of
* {@link eu.bittrade.libs.steemj.plugins.apis.account.history.models.AppliedOperation
* AppliedOperations}.
* @throws SteemCommunicationException
* <ul>
* <li>If the server was not able to answer the request in the
* given time (see
* {@link eu.bittrade.libs.steemj.configuration.SteemJConfig#setResponseTimeout(int)
* setResponseTimeout}).</li>
* <li>If there is a connection problem.</li>
* </ul>
* @throws SteemResponseException
* <ul>
* <li>If the SteemJ is unable to transform the JSON response
* into a Java object.</li>
* <li>If the Server returned an error object.</li>
* </ul>
*/
public static EnumVirtualOps enumVirtualOps(CommunicationHandler communicationHandler,
EnumVirtualOpsArgs enumVirtualOpsArgs) throws SteemCommunicationException, SteemResponseException {
JsonRPCRequest requestObject = new JsonRPCRequest(SteemApiType.ACCOUNT_HISTORY_API,
RequestMethod.ENUM_VIRTUAL_OPS, enumVirtualOpsArgs);

return communicationHandler.performRequest(requestObject, EnumVirtualOps.class).get(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import com.fasterxml.jackson.annotation.JsonProperty;

import eu.bittrade.libs.steemj.fc.TimePointSec;
import eu.bittrade.libs.steemj.plugins.apis.account.history.models.deserializer.OperationWrapper;
import eu.bittrade.libs.steemj.protocol.TransactionId;
import eu.bittrade.libs.steemj.protocol.operations.Operation;

/**
* This class is the java implementation of the Steem "api_operation_object"
Expand All @@ -51,7 +51,7 @@ public class AppliedOperation {
@JsonProperty("timestamp")
private TimePointSec timestamp;
@JsonProperty("op")
private Operation op;
private OperationWrapper operationWrapper;

/**
* This object is only used to wrap the JSON response in a POJO, so
Expand Down Expand Up @@ -79,27 +79,27 @@ public UInteger getBlock() {
}

/**
* Get the index of the transaction inside the block.
* Get the number of transactions inside the block.
*
* @return The transaction index in the block.
* @return The number of transactions inside the block.
*/
public UInteger getTrxInBlock() {
return trxInBlock;
}

/**
* Get the index of the operation inside the transaction.
* Get the number of operations inside the transaction.
*
* @return The operation index in the transaction.
* @return The number of operations inside the transaction.
*/
public UShort getOpInTrx() {
return opInTrx;
}

/**
* Get the index of the virtual operation inside the transaction.
* Get the number of virtual operations inside the transaction.
*
* @return The virtual operation index in the transaction.
* @return The number of virtual operations inside the transaction.
*/
public ULong getVirtualOp() {
return virtualOp;
Expand All @@ -115,12 +115,12 @@ public TimePointSec getTimestamp() {
}

/**
* Get the whole operation object.
* Get a wrapper object which stores the whole operation object.
*
* @return The operation object.
*/
public Operation getOp() {
return op;
public OperationWrapper getOperationWrapper() {
return operationWrapper;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* This file is part of SteemJ (formerly known as 'Steem-Java-Api-Wrapper')
*
* SteemJ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SteemJ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SteemJ. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.bittrade.libs.steemj.plugins.apis.account.history.models;

import java.util.List;

import org.joou.UInteger;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* This class implements the Steem "enum_virtual_ops_return" object.
*
* @author <a href="http://steemit.com/@dez1337">dez1337</a>
*/
public class EnumVirtualOps {
@JsonProperty("ops")
private List<AppliedOperation> operations;
@JsonProperty("next_block_range_begin")
private UInteger nextBlockRangeBegin;

/**
* This object is only used to wrap the JSON response in a POJO, so
* therefore this class should not be instantiated.
*/
private EnumVirtualOps() {
}

/**TODO
* @return the operations
*/
public List<AppliedOperation> getOperations() {
return operations;
}

/**TODO
* @return the nextBlockRangeBegin
*/
public UInteger getNextBlockRangeBegin() {
return nextBlockRangeBegin;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* This file is part of SteemJ (formerly known as 'Steem-Java-Api-Wrapper')
*
* SteemJ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SteemJ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SteemJ. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.bittrade.libs.steemj.plugins.apis.account.history.models;

import org.apache.commons.lang3.Validate;
import org.joou.UInteger;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* This class implements the Steem "enum_virtual_ops_args" object.
*
* @author <a href="http://steemit.com/@dez1337">dez1337</a>
*/
public class EnumVirtualOpsArgs {
@JsonProperty("block_range_begin")
private UInteger blockRangeBegin;
@JsonProperty("block_range_end")
private UInteger blockRangeEnd;

public static class Builder {
private UInteger blockRangeBegin;
private UInteger blockRangeEnd;

public Builder() {
this.blockRangeBegin = UInteger.valueOf(1);
this.blockRangeEnd = UInteger.valueOf(2);
}

public Builder startAt(UInteger startBlock) {
this.blockRangeBegin = Validate.notNull(startBlock);
return this;
}

public Builder endAt(UInteger endBlock) {
this.blockRangeEnd = Validate.notNull(endBlock);
return this;
}

public EnumVirtualOpsArgs build() {
EnumVirtualOpsArgs enumVirtualOpsArgs = new EnumVirtualOpsArgs();
enumVirtualOpsArgs.blockRangeBegin = this.blockRangeBegin;
enumVirtualOpsArgs.blockRangeEnd = this.blockRangeEnd;
return enumVirtualOpsArgs;
}
}

@JsonCreator()
private EnumVirtualOpsArgs() {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.Map;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.joou.UInteger;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
Expand All @@ -34,7 +33,7 @@
public class GetAccountHistoryReturn {
@JsonProperty("history")
@JsonDeserialize(using = AppliedOperationHashMapDeserializer.class)
private Map<UInteger, AppliedOperation> history;
private Map<Long, AppliedOperation> history;

/**
* This object is only used to wrap the JSON response in a POJO, so
Expand All @@ -51,7 +50,7 @@ private GetAccountHistoryReturn() {
*
* @return A map of operations and their id.
*/
public Map<UInteger, AppliedOperation> getHistory() {
public Map<Long, AppliedOperation> getHistory() {
return history;
}

Expand Down
Loading