|
1 | 1 | package eu.bittrade.libs.steemj.plugins.apis.chain;
|
2 | 2 |
|
| 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 | + */ |
3 | 19 | 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 | + } |
19 | 52 | }
|
0 commit comments