6565import eu .bittrade .libs .steemj .base .models .PublicKey ;
6666import eu .bittrade .libs .steemj .base .models .RewardFund ;
6767import eu .bittrade .libs .steemj .base .models .ScheduledHardfork ;
68+ import eu .bittrade .libs .steemj .base .models .SignedBlock ;
6869import eu .bittrade .libs .steemj .base .models .SignedBlockWithInfo ;
6970import eu .bittrade .libs .steemj .base .models .SignedTransaction ;
7071import eu .bittrade .libs .steemj .base .models .Tag ;
9697import eu .bittrade .libs .steemj .exceptions .SteemInvalidTransactionException ;
9798import eu .bittrade .libs .steemj .exceptions .SteemResponseException ;
9899import eu .bittrade .libs .steemj .exceptions .SteemTransformationException ;
100+ import eu .bittrade .libs .steemj .plugins .network .broadcast .api .NetworkBroadcastApi ;
101+ import eu .bittrade .libs .steemj .plugins .network .broadcast .model .BroadcastTransactionSynchronousReturn ;
99102import eu .bittrade .libs .steemj .util .CondenserUtils ;
100103import eu .bittrade .libs .steemj .util .SteemJUtils ;
101104
@@ -163,10 +166,14 @@ public SteemJ() throws SteemCommunicationException, SteemResponseException {
163166 // #########################################################################
164167
165168 /**
166- * Broadcast a transaction on the Steem blockchain.
169+ * Broadcast a transaction on the Steem blockchain. This method will
170+ * validate the transaction and return immediately. Please notice that this
171+ * does not mean that the operation has been accepted and has been
172+ * processed. If you want to make sure that this is the case use the
173+ * {@link #broadcastTransactionSynchronous(SignedTransaction)} method.
167174 *
168175 * @param transaction
169- * A transaction object that has been signed .
176+ * The {@link SignedTransaction} object to broadcast .
170177 * @throws SteemCommunicationException
171178 * <ul>
172179 * <li>If the server was not able to answer the request in the
@@ -181,17 +188,68 @@ public SteemJ() throws SteemCommunicationException, SteemResponseException {
181188 * into a Java object.</li>
182189 * <li>If the Server returned an error object.</li>
183190 * </ul>
191+ * @throws SteemInvalidTransactionException
192+ * In case the provided transaction is not valid.
184193 */
185194 public void broadcastTransaction (SignedTransaction transaction )
186- throws SteemCommunicationException , SteemResponseException {
187- JsonRPCRequest requestObject = new JsonRPCRequest ();
188- requestObject .setApiMethod (RequestMethods .BROADCAST_TRANSACTION );
189- requestObject .setSteemApi (SteemApiType .NETWORK_BROADCAST_API );
195+ throws SteemCommunicationException , SteemResponseException , SteemInvalidTransactionException {
196+ NetworkBroadcastApi .broadcastTransaction (communicationHandler , transaction );
197+ }
190198
191- Object [] parameters = { transaction };
192- requestObject .setAdditionalParameters (parameters );
199+ /**
200+ * Broadcast a transaction on the Steem blockchain. This method will
201+ * validate the transaction and return after it has been accepted and
202+ * applied.
203+ *
204+ * @param transaction
205+ * The {@link SignedTransaction} object to broadcast.
206+ * @return A {@link BroadcastTransactionSynchronousReturn} object providing
207+ * information about the block in which the transaction has been
208+ * applied.
209+ * @throws SteemCommunicationException
210+ * <ul>
211+ * <li>If the server was not able to answer the request in the
212+ * given time (see
213+ * {@link eu.bittrade.libs.steemj.configuration.SteemJConfig#setResponseTimeout(int)
214+ * setResponseTimeout}).</li>
215+ * <li>If there is a connection problem.</li>
216+ * </ul>
217+ * @throws SteemResponseException
218+ * <ul>
219+ * <li>If the SteemJ is unable to transform the JSON response
220+ * into a Java object.</li>
221+ * <li>If the Server returned an error object.</li>
222+ * </ul>
223+ * @throws SteemInvalidTransactionException
224+ * In case the provided transaction is not valid.
225+ */
226+ public BroadcastTransactionSynchronousReturn broadcastTransactionSynchronous (SignedTransaction transaction )
227+ throws SteemCommunicationException , SteemResponseException , SteemInvalidTransactionException {
228+ return NetworkBroadcastApi .broadcastTransactionSynchronous (communicationHandler , transaction );
229+ }
193230
194- communicationHandler .performRequest (requestObject , Object .class );
231+ /**
232+ * Broadcast a whole block.
233+ *
234+ * @param signedBlock
235+ * The {@link SignedBlock} object to broadcast.
236+ * @throws SteemCommunicationException
237+ * <ul>
238+ * <li>If the server was not able to answer the request in the
239+ * given time (see
240+ * {@link eu.bittrade.libs.steemj.configuration.SteemJConfig#setResponseTimeout(int)
241+ * setResponseTimeout}).</li>
242+ * <li>If there is a connection problem.</li>
243+ * </ul>
244+ * @throws SteemResponseException
245+ * <ul>
246+ * <li>If the SteemJ is unable to transform the JSON response
247+ * into a Java object.</li>
248+ * <li>If the Server returned an error object.</li>
249+ * </ul>
250+ */
251+ public void broadcastBlock (SignedBlock signedBlock ) throws SteemCommunicationException , SteemResponseException {
252+ NetworkBroadcastApi .broadcastBlock (communicationHandler , signedBlock );
195253 }
196254
197255 // #########################################################################
0 commit comments