SteemJ V0.3.4 has been released ~ Use the Steem API in your Java Project

in #steemdev7 years ago

SteemJ v0.3.4 finally allows you to share post/comment rewards with another Steem account.

SteemJV2Logo


Previous 0.3.x releases: v0.3.3 v0.3.2 v0.3.1 v0.3.0

SteemJ v0.3.4 has been released

Hello Steemians!

I am pleased to announce the last 0.3.x release of SteemJ: Version 0.3.4. Based on this success, we can finally look forward to version 0.4.0 for which some big improvements like a TransactionBuilder are planned.

This release fixes the remaining issues and increases the overall quality of the project once again.

At this point: Once again a huge Thank you! to everyone submitting issues at GitHub - Everyone of you is making this project better and better.

As SteemJ is made for third-party apps the most interesting change should be the CommentOptionsExtension fix. You may know that it is possible to add this type of Extension to a CommentOptionsOperation since HF 0.18.0. This Extension allows you to define that a specific account gets a specfic percentage of the reward too. If your app allows users to write posts or comments, this can be one way to earn something with your app.

I’ve just read some comments on the Steemit Chat from users who were wondering how to use this feature, so to avoid this pain for you SteemJ users, here is a small sample:

        CommentOptionsOperation commentOptionsOperation = new CommentOptionsOperation();
        commentOptionsOperation.setAuthor(new AccountName("dez1337"));
        commentOptionsOperation.setPermlink("steemj-v0-2-4-has-been-released-update-9");
        commentOptionsOperation.setAllowVotes(true);
        commentOptionsOperation.setAllowCurationRewards(true);
        commentOptionsOperation.setPercentSteemDollars((short) 10000);

        BeneficiaryRouteType beneficiaryRouteType = new BeneficiaryRouteType();
        beneficiaryRouteType.setAccount(new AccountName("steemJ"));
        beneficiaryRouteType.setWeight((short) 500);

        ArrayList<BeneficiaryRouteType> beneficiaryRouteTypes = new ArrayList<>();
        beneficiaryRouteTypes.add(beneficiaryRouteType);

        CommentPayoutBeneficiaries commentPayoutBeneficiaries = new CommentPayoutBeneficiaries();
        commentPayoutBeneficiaries.setBeneficiaries(beneficiaryRouteTypes);

        CommentOptionsExtension commentOptionsExtension = new CommentOptionsExtension(commentPayoutBeneficiaries);

        ArrayList<CommentOptionsExtension> commentOptionsExtensions = new ArrayList<>();
        commentOptionsExtensions.add(commentOptionsExtension);

        commentOptionsOperation.setExtensions(commentOptionsExtensions);

        ArrayList<Operation> operations = new ArrayList<>();
        operations.add(commentOptionsOperation);

        transaction.setOperations(operations);
        transaction.sign();

For sure, this is still quite complex to achieve, but it is working! SteemJ 0.4.x will hopefully provide some easier ways to add a CommentOptionsExtension to a transcation.

As always, let’s have a look at the current code quality before moving to the detailed changelog.

Code Quality

SonarQube

The code coverage slightly increased, because some new test cases have been added to avoid that the reported problems occur again in future versions. Beside that some TODOs could have been removed so that the number of Code Smells went down to 144.

What is new?

Below you can find all changes made in this release.

Functional Updates

  • The following issues have been fixed:
  • #5 Add JavaDoc to the follow_api.
  • #62 Unable to add CommentPayoutBeneficiaries Extension to CommentOptionsOperation .
  • #42 Implement core id types (e.g. block_id_type) to offer additional functionalities and a more accurate parsing.
  • #30 Fix CommentOptionsExtension parsing.
  • #61 Unable to use insecure websockets connection.
  • #68 Deserialization problem in case of 'total_pow' field is -1 (Testnet)

Code Quality Improvements

  • Additional integration tests have been added.

Documentation

General information

What is SteemJ?

SteemJ is a project that allows you to communicate with a Steem node using Java. So far, the project supports most of the API calls and is also able to broadcast most of the common operation types. Further information can be found on GitHub.

https://github.com/marvin-we/steem-java-api-wrapper

How to add it to your project?

SteemJ binaries are pushed into the maven central repository and can be integrated with a bunch of build management tools like Maven. The Wiki provides a lot of examples for the most common build tools. If you do not use a build management tool you can download the binaries as described here.

Contribute

The project became quite big and there is still a lot to do. If you want to support the project simply clone the git repository and submit a pull request. I would really appreciate it =).

git clone https://github.com/marvin-we/steem-java-api-wrapper.git

Get in touch!

Most of my projects are pretty time consuming and I always try to provide some useful stuff to the community. What keeps me going for that is your feedback and your support. For that reason I would love to get some Feedback from you <3. Just contact me here on Steemit or ping me on GitHub.


If you want to stay up to date or just like the stuff I am doing it would be great if you could press the button below =).



follow me

Thanks for reading and best regards,
@dez1337

steemdevsteemopen-sourceprogrammingsteemit

Sort:  

This piece of code teaching how to create a new transaction is not working anymore:

[...]
Transaction transaction = new Transaction();
// The expiration date defines how long the transaction is valid. This field is optional and SteemJ will automatically use the current system time and an offset.
transaction.setExpirationDate("2016-04-06T08:29:27UTC");
// Define in which block the transaction should be added. In most cases this is the next available block which can be asked using the following lines:
GlobalProperties globalProperties = steemApiWrapper.getDynamicGlobalProperties();
int refBlockNum = (globalProperties.getHeadBlockNumber() & 0xFFFF);
transaction.setRefBlockNum(refBlockNum);
transaction.setRefBlockPrefix(globalProperties.getHeadBlockId());
// There is also the option to add extensions to a transaction which are currently not used by Steem and therefore not supported by SteemJ.
// transaction.setExtensions(extensions);

// A Transaction accepts one or more Operations which have to be provided as an ArrayList.
ArrayList<Operation> operations = new ArrayList<>();
[...]

Hay @discernente,

thank you for pointing this out and sorry for the late reply. I've updated the sample at GitHub. The following snippet should work again:

[...]
Transaction transaction = new Transaction();
// The expiration date defines how long the transaction is valid. This field is optional and SteemJ will automatically use the current system time and an offset.
transaction.setExpirationDate("2016-04-06T08:29:27UTC");
// Define in which block the transaction should be added. In most cases this is the next available block which can be asked using the following lines:
GlobalProperties globalProperties = steemApiWrapper.getDynamicGlobalProperties();

transaction.setRefBlockPrefix(globalProperties.getHeadBlockId().getHashValue());
transaction.setRefBlockNum(globalProperties.getHeadBlockId().getNumberFromHash());

// There is also the option to add extensions to a transaction which are currently not used by Steem and therefore not supported by SteemJ.
// transaction.setExtensions(extensions);

// A Transaction accepts one or more Operations which have to be provided as an ArrayList.
ArrayList<Operation> operations = new ArrayList<>();
[...]

Ok, thank you. Now this piece of code is running fine, but I found another error while trying to run the method "getActiveVotes:

Exception in thread "main" eu.bittrade.libs.steemj.exceptions.SteemTransformationException: Could not transform the response into an object.
at eu.bittrade.libs.steemj.communication.CommunicationHandler.performRequest(CommunicationHandler.java:173)
at eu.bittrade.libs.steemj.SteemJ.getActiveVotes(SteemJ.java:311)

Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "author" (class eu.bittrade.libs.steemj.base.models.error.SteemData), not marked as ignorable (8 known properties: "call.method", "posting", "what", "call.params", "type", "name", "id", "api"])
at [Source: (String)"{"id":9,"error":{"code":1,"message":"13 N5boost16exception_detail10clone_implINS0_19error_info_injectorISt12out_of_rangeEEEE: unknown key\nunknown key: \n {"author":"discernente","permlink":"https://steemit.com/chart/@discernente/bitscreener-a-good-cryptocurrencies-free-real-time-charts-screener","what":"unknown key"}\n th_a database.cpp:385 get_comment\n\n {"call.method":"call","call.params":["database_api","get_active_votes",["discernente","https://steemit.co"[truncated 1007 chars]; line: 1, column: 976] (through reference chain: eu.bittrade.libs.steemj.base.models.error.SteemError["error"]->eu.bittrade.libs.steemj.base.models.error.SteemErrorDetails["data"]->eu.bittrade.libs.steemj.base.models.error.SteemErrorData["stack"]->java.lang.Object[][0]->eu.bittrade.libs.steemj.base.models.error.SteemStack["data"]->eu.bittrade.libs.steemj.base.models.error.SteemData["author"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:60)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:822)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1148)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1547)

After having a closer look I guess the problem is that you've used the whole link instead of only providing the permlink part. So instead of

https://steemit.com/chart/@discernente/bitscreener-a-good-cryptocurrencies-free-real-time-charts-screener

use:

bitscreener-a-good-cryptocurrencies-free-real-time-charts-screener

ok thank you

Thank you once again - This may be connected to the new Steem version 0.19.2 - I've created #72 at GitHub for this :)

Nice feed @dez1337 thanks for sharing

It looks very interesting your project, I will follow you to continue reading

You have my support @dez1337. I don't code but I understand the usefulless of SteemJ and how it can help Java developers build great app on Steem. Keep on!

Hay @pnc,

thank you for your support - It really motivates me :)

Very interesting information sir. good post. 100% like and resteem

Nice read. This might be a bit off topic but when will steem add DM and notifications?

Hay @littleboy,

if you are talking about notifications I sadly can't answer your question :( - For Steem in general you currently have the possibilty to get informed by every new block like explained in this sample.

Thank you and best regards! :)

Congratulations @dez1337! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Congratulations @dez1337! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of comments received

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Coin Marketplace

STEEM 0.21
TRX 0.26
JST 0.039
BTC 95625.14
ETH 3355.68
USDT 1.00
SBD 3.05