Skip to content

Commit ce8d530

Browse files
committed
Move and add objects related to the chain_api (Work on #182)
1 parent 5638d82 commit ce8d530

File tree

83 files changed

+319
-125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+319
-125
lines changed

core/src/main/java/eu/bittrade/libs/steemj/SteemJ.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import eu.bittrade.libs.steemj.base.models.Permlink;
3434
import eu.bittrade.libs.steemj.base.models.Price;
3535
import eu.bittrade.libs.steemj.base.models.ScheduledHardfork;
36-
import eu.bittrade.libs.steemj.base.models.SignedTransaction;
36+
import eu.bittrade.libs.steemj.chain.SignedTransaction;
3737
import eu.bittrade.libs.steemj.communication.CommunicationHandler;
3838
import eu.bittrade.libs.steemj.communication.jrpc.JsonRPCRequest;
3939
import eu.bittrade.libs.steemj.configuration.SteemJConfig;

core/src/main/java/eu/bittrade/libs/steemj/base/models/SignedTransaction.java renamed to core/src/main/java/eu/bittrade/libs/steemj/chain/SignedTransaction.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package eu.bittrade.libs.steemj.base.models;
1+
package eu.bittrade.libs.steemj.chain;
22

33
import java.io.ByteArrayOutputStream;
44
import java.io.IOException;
@@ -23,6 +23,10 @@
2323
import eu.bittrade.crypto.core.CryptoUtils;
2424
import eu.bittrade.crypto.core.ECKey;
2525
import eu.bittrade.crypto.core.Sha256Hash;
26+
import eu.bittrade.libs.steemj.base.models.Authority;
27+
import eu.bittrade.libs.steemj.base.models.BlockId;
28+
import eu.bittrade.libs.steemj.base.models.FutureExtensions;
29+
import eu.bittrade.libs.steemj.base.models.Transaction;
2630
import eu.bittrade.libs.steemj.configuration.SteemJConfig;
2731
import eu.bittrade.libs.steemj.enums.PrivateKeyType;
2832
import eu.bittrade.libs.steemj.enums.ValidationType;

core/src/main/java/eu/bittrade/libs/steemj/enums/RequestMethods.java

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public enum RequestMethods {
2121
GET_BLOCK,
2222
/** */
2323
GET_BLOCK_HEADER,
24+
// chain_api
25+
/** */
26+
PUSH_BLOCK,
27+
/** */
28+
PUSH_TRANSACTION,
2429
// condenser_api
2530
/** */
2631
GET_STATE,
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,52 @@
11
package eu.bittrade.libs.steemj.plugins.apis.chain;
22

3+
import eu.bittrade.libs.steemj.chain.SignedTransaction;
4+
import eu.bittrade.libs.steemj.communication.CommunicationHandler;
5+
import eu.bittrade.libs.steemj.communication.jrpc.JsonRPCRequest;
6+
import eu.bittrade.libs.steemj.enums.RequestMethods;
7+
import eu.bittrade.libs.steemj.enums.SteemApiType;
8+
import eu.bittrade.libs.steemj.exceptions.SteemCommunicationException;
9+
import eu.bittrade.libs.steemj.exceptions.SteemResponseException;
10+
import eu.bittrade.libs.steemj.plugins.apis.chain.models.PushBlockArgs;
11+
import eu.bittrade.libs.steemj.plugins.apis.chain.models.PushBlockReturn;
12+
import eu.bittrade.libs.steemj.plugins.apis.chain.models.PushTransactionReturn;
13+
14+
/**
15+
* This class implements the "chain_api".
16+
*
17+
* @author <a href="http://steemit.com/@dez1337">dez1337</a>
18+
*/
319
public class ChainApi {
4-
/*
5-
DECLARE_API(
6-
(push_block)
7-
/**
8-
* Attempts to push the transaction into the pending queue
9-
*
10-
* When called to push a locally generated transaction, set the skip_block_size_check bit on the skip argument. This
11-
* will allow the transaction to be pushed even if it causes the pending block size to exceed the maximum block size.
12-
* Although the transaction will probably not propagate further now, as the peers are likely to have their pending
13-
* queues full as well, it will be kept in the queue to be propagated later when a new block flushes out the pending
14-
* queues.
15-
*/
16-
/*
17-
(push_transaction) )
18-
*/
20+
/** Add a private constructor to hide the implicit public one. */
21+
private ChainApi() {
22+
}
23+
24+
public static PushBlockReturn pushBlock(CommunicationHandler communicationHandler, PushBlockArgs pushBlockArgs)
25+
throws SteemCommunicationException, SteemResponseException {
26+
JsonRPCRequest requestObject = new JsonRPCRequest();
27+
requestObject.setApiMethod(RequestMethods.PUSH_BLOCK);
28+
requestObject.setSteemApi(SteemApiType.CHAIN_API);
29+
requestObject.setAdditionalParameters(pushBlockArgs);
30+
31+
return communicationHandler.performRequest(requestObject, PushBlockReturn.class).get(0);
32+
}
33+
34+
/**
35+
* Attempts to push the transaction into the pending queue
36+
*
37+
* When called to push a locally generated transaction, set the skip_block_size_check bit on the skip argument. This
38+
* will allow the transaction to be pushed even if it causes the pending block size to exceed the maximum block size.
39+
* Although the transaction will probably not propagate further now, as the peers are likely to have their pending
40+
* queues full as well, it will be kept in the queue to be propagated later when a new block flushes out the pending
41+
* queues.
42+
*/
43+
public static PushTransactionReturn pushTransaction(CommunicationHandler communicationHandler, SignedTransaction signedTransaction)
44+
throws SteemCommunicationException, SteemResponseException {
45+
JsonRPCRequest requestObject = new JsonRPCRequest();
46+
requestObject.setApiMethod(RequestMethods.PUSH_TRANSACTION);
47+
requestObject.setSteemApi(SteemApiType.CHAIN_API);
48+
requestObject.setAdditionalParameters(signedTransaction);
49+
50+
return communicationHandler.performRequest(requestObject, PushTransactionReturn.class).get(0);
51+
}
1952
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package eu.bittrade.libs.steemj.plugins.apis.chain.models;
2+
3+
import javax.annotation.Nullable;
4+
5+
import org.apache.commons.lang3.builder.ToStringBuilder;
6+
7+
import com.fasterxml.jackson.annotation.JsonProperty;
8+
9+
import eu.bittrade.libs.steemj.protocol.SignedBlock;
10+
import eu.bittrade.libs.steemj.util.SteemJUtils;
11+
12+
/**
13+
* This class is the java implementation of the Steem "push_block_args" object.
14+
*
15+
* @author <a href="http://steemit.com/@dez1337">dez1337</a>
16+
*/
17+
public class PushBlockArgs {
18+
@JsonProperty("block")
19+
private SignedBlock block;
20+
@JsonProperty("currently_syncing")
21+
private boolean currentlySyncing;
22+
23+
/**
24+
*
25+
* @param block
26+
* @param currentlySyncing
27+
*/
28+
public PushBlockArgs(@JsonProperty("block") SignedBlock block,
29+
@Nullable @JsonProperty("currently_syncing") boolean currentlySyncing) {
30+
this.setBlock(block);
31+
this.setCurrentlySyncing(currentlySyncing);
32+
}
33+
34+
/**
35+
* @return the block
36+
*/
37+
public SignedBlock getBlock() {
38+
return block;
39+
}
40+
41+
/**
42+
* @param block
43+
* the block to set
44+
*/
45+
public void setBlock(SignedBlock block) {
46+
this.block = SteemJUtils.setIfNotNull(block, "The block needs to be provided.");
47+
}
48+
49+
/**
50+
* @return the currentlySyncing
51+
*/
52+
public boolean isCurrentlySyncing() {
53+
return currentlySyncing;
54+
}
55+
56+
/**
57+
* @param currentlySyncing
58+
* the currentlySyncing to set
59+
*/
60+
public void setCurrentlySyncing(boolean currentlySyncing) {
61+
this.currentlySyncing = SteemJUtils.setIfNotNull(currentlySyncing, false);
62+
}
63+
64+
@Override
65+
public String toString() {
66+
return ToStringBuilder.reflectionToString(this);
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package eu.bittrade.libs.steemj.plugins.apis.chain.models;
2+
3+
import org.apache.commons.lang3.builder.ToStringBuilder;
4+
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import com.google.common.base.Optional;
7+
8+
/**
9+
* This class is the java implementation of the Steem "push_block_return"
10+
* object.
11+
*
12+
* @author <a href="http://steemit.com/@dez1337">dez1337</a>
13+
*/
14+
public class PushBlockReturn {
15+
@JsonProperty("success")
16+
private boolean success;
17+
@JsonProperty("error")
18+
private String error;
19+
20+
/**
21+
* This object is only used to wrap the JSON response in a POJO, so
22+
* therefore this class should not be instantiated.
23+
*/
24+
private PushBlockReturn() {
25+
}
26+
27+
/**
28+
* @return the success
29+
*/
30+
public boolean isSuccess() {
31+
return success;
32+
}
33+
34+
/**
35+
* @return the error
36+
*/
37+
public Optional<String> getError() {
38+
return Optional.fromNullable(error);
39+
}
40+
41+
@Override
42+
public String toString() {
43+
return ToStringBuilder.reflectionToString(this);
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package eu.bittrade.libs.steemj.plugins.apis.chain.models;
2+
3+
import org.apache.commons.lang3.builder.ToStringBuilder;
4+
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import com.google.common.base.Optional;
7+
8+
/**
9+
* This class is the java implementation of the Steem "push_transaction_return"
10+
* object.
11+
*
12+
* @author <a href="http://steemit.com/@dez1337">dez1337</a>
13+
*/
14+
public class PushTransactionReturn {
15+
@JsonProperty("success")
16+
private boolean success;
17+
@JsonProperty("error")
18+
private String error;
19+
20+
/**
21+
* This object is only used to wrap the JSON response in a POJO, so
22+
* therefore this class should not be instantiated.
23+
*/
24+
private PushTransactionReturn() {
25+
}
26+
27+
/**
28+
* @return the success
29+
*/
30+
public boolean isSuccess() {
31+
return success;
32+
}
33+
34+
/**
35+
* @return the error
36+
*/
37+
public Optional<String> getError() {
38+
return Optional.fromNullable(error);
39+
}
40+
41+
@Override
42+
public String toString() {
43+
return ToStringBuilder.reflectionToString(this);
44+
}
45+
}

core/src/main/java/eu/bittrade/libs/steemj/plugins/apis/network/broadcast/api/NetworkBroadcastApi.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package eu.bittrade.libs.steemj.plugins.apis.network.broadcast.api;
22

3-
import eu.bittrade.libs.steemj.base.models.SignedTransaction;
3+
import eu.bittrade.libs.steemj.chain.SignedTransaction;
44
import eu.bittrade.libs.steemj.communication.CommunicationHandler;
55
import eu.bittrade.libs.steemj.communication.jrpc.JsonRPCRequest;
66
import eu.bittrade.libs.steemj.enums.RequestMethods;

0 commit comments

Comments
 (0)