13
13
import eu .bittrade .libs .steemj .SteemJ ;
14
14
import eu .bittrade .libs .steemj .base .models .AccountName ;
15
15
import eu .bittrade .libs .steemj .base .models .AppliedOperation ;
16
- import eu .bittrade .libs .steemj .base .models .GlobalProperties ;
17
16
import eu .bittrade .libs .steemj .base .models .Permlink ;
18
- import eu .bittrade .libs .steemj .base .models .SignedTransaction ;
19
17
import eu .bittrade .libs .steemj .base .models .Vote ;
20
18
import eu .bittrade .libs .steemj .base .models .VoteState ;
21
19
import eu .bittrade .libs .steemj .base .models .operations .AccountCreateOperation ;
22
- import eu .bittrade .libs .steemj .base .models .operations .Operation ;
23
- import eu .bittrade .libs .steemj .base .models .operations .VoteOperation ;
20
+ import eu .bittrade .libs .steemj .base .models .operations .CommentOperation ;
24
21
import eu .bittrade .libs .steemj .configuration .SteemJConfig ;
25
22
import eu .bittrade .libs .steemj .enums .PrivateKeyType ;
26
23
import eu .bittrade .libs .steemj .exceptions .SteemCommunicationException ;
@@ -45,8 +42,11 @@ public static void main(String args[]) {
45
42
// Change the default settings if needed.
46
43
SteemJConfig myConfig = SteemJConfig .getInstance ();
47
44
myConfig .setResponseTimeout (100000L );
45
+ myConfig .setDefaultAccount (new AccountName ("steemj" ));
48
46
49
47
try {
48
+ // SteemJ already comes with a configured EndPoint, but if you want
49
+ // to connect to another one, you can simply configure it here:
50
50
myConfig .setWebSocketEndpointURI (new URI ("wss://seed.bitcoiner.me" ), false );
51
51
} catch (URISyntaxException e ) {
52
52
throw new RuntimeException ("The given URI is not valid." , e );
@@ -57,10 +57,10 @@ public static void main(String args[]) {
57
57
SteemJ steemJ = new SteemJ ();
58
58
59
59
List <ImmutablePair <PrivateKeyType , String >> privateKeys = new ArrayList <>();
60
- privateKeys .add (new ImmutablePair <>(PrivateKeyType .POSTING , "YOURPRIVATEPOSTINGKEY " ));
61
- privateKeys .add (new ImmutablePair <>(PrivateKeyType .ACTIVE , "YOURPRIVATEACTIVEKEY " ));
60
+ privateKeys .add (new ImmutablePair <>(PrivateKeyType .POSTING , "YOUR-PRIVATE-POSTING-KEY " ));
61
+ privateKeys .add (new ImmutablePair <>(PrivateKeyType .ACTIVE , "YOUR-PRIVATE-ACTIVE-KEY " ));
62
62
63
- myConfig .getPrivateKeyStorage ().addAccount (new AccountName ( "dez1337" ), privateKeys );
63
+ myConfig .getPrivateKeyStorage ().addAccount (myConfig . getDefaultAccount ( ), privateKeys );
64
64
65
65
// Let's have a look at the account history of dez1337
66
66
Map <Integer , AppliedOperation > accountHistory = steemJ .getAccountHistory (new AccountName ("dez1337" ), 100 ,
@@ -71,32 +71,60 @@ public static void main(String args[]) {
71
71
LOGGER .info ("The account {} has been created by {}." , "dez1337" , accountCreateOperation .getCreator ());
72
72
}
73
73
74
- // Perform a transaction
75
- AccountName voter = new AccountName ("dez1337" );
76
- AccountName author = new AccountName ("dez1337" );
77
- Permlink permlinkOfAPost = new Permlink ("steem-java-api-learned-to-speak-graphene-update-5" );
78
- Short votingWeight = 10000 ;
79
- VoteOperation voteOperation = new VoteOperation (voter , author , permlinkOfAPost , votingWeight );
80
-
81
- ArrayList <Operation > operations = new ArrayList <>();
82
- operations .add (voteOperation );
83
-
84
- // Get the current RefBlockNum and RefBlockPrefix from the global
85
- // properties.
86
- GlobalProperties globalProperties = steemJ .getDynamicGlobalProperties ();
87
-
88
- SignedTransaction signedTransaction = new SignedTransaction (globalProperties .getHeadBlockId (), operations ,
89
- null );
90
-
91
- try {
92
- signedTransaction .sign ();
93
- } catch (SteemInvalidTransactionException e ) {
94
- LOGGER .error ("A propblem occured while signing your Transaction." , e );
95
- }
96
- steemJ .broadcastTransaction (signedTransaction );
97
-
98
- LOGGER .info ("The HEX representation of this transaction it {}." ,
99
- steemJ .getTransactionHex (signedTransaction ));
74
+ /*
75
+ * Upvote the post
76
+ * "steem-java-api-learned-to-speak-graphene-update-5" written by
77
+ * "dez1337" using 100% of the defaultAccounts voting power.
78
+ */
79
+ steemJ .vote (new AccountName ("dez1337" ), new Permlink ("steem-java-api-learned-to-speak-graphene-update-5" ),
80
+ (short ) 100 );
81
+
82
+ /*
83
+ * Remove the vote made earlier.
84
+ */
85
+ steemJ .cancelVote (new AccountName ("dez1337" ),
86
+ new Permlink ("steem-java-api-learned-to-speak-graphene-update-5" ));
87
+
88
+ // Let the default account ("steemj") follow "cyriana"
89
+ steemJ .follow (new AccountName ("cyriana" ));
90
+
91
+ // Let the default account ("steemj") unfollow "cyriana"
92
+ steemJ .unfollow (new AccountName ("cyriana" ));
93
+
94
+ /*
95
+ * Write a new post.
96
+ *
97
+ * Title = "Test of SteemJ 0.4.0"
98
+ * Content = "Test using SteemJ 0. ..... "
99
+ * Tags = "test", "dontvote"
100
+ *
101
+ */
102
+ CommentOperation myNewPost = steemJ .createPost ("Test of SteemJ 0.4.0" ,
103
+ "Test using SteemJ 0.4.0 by @dez1337 with a link to "
104
+ + "https://github.com/marvin-we/steem-java-api-wrapper "
105
+ + "and an image ." ,
106
+ new String [] { "test" , "dontvote" });
107
+ LOGGER .info (
108
+ "SteemJ has generated some additional values for my new post. One good example is the permlink {} that I may need later on." ,
109
+ myNewPost .getPermlink ().getLink ());
110
+
111
+ /*
112
+ * Write a new comment.
113
+ *
114
+ * Author of the post to reply to = "steemj"
115
+ * Permlink of the post to reply to = "testofsteemj040"
116
+ * Title = "Test of SteemJ 0.4.0"
117
+ * Content = "Test using SteemJ 0. ..... "
118
+ * Tags = "test"
119
+ *
120
+ */
121
+ steemJ .createComment (new AccountName ("steemj" ), new Permlink ("testofsteemj040" ),
122
+ "Example comment without a link but with a @user ." , new String [] { "test" });
123
+
124
+ /*
125
+ * Delete the newly created post.
126
+ */
127
+ steemJ .deletePostOrComment (myNewPost .getParentPermlink ());
100
128
101
129
// Get the current Price
102
130
LOGGER .info ("The current price in the internal market is {}." ,
@@ -128,7 +156,9 @@ public static void main(String args[]) {
128
156
e .getError ().getSteemErrorDetails ().getData ().getCode (),
129
157
e .getError ().getSteemErrorDetails ().getMessage ());
130
158
} catch (SteemCommunicationException e ) {
131
- LOGGER .error ("Error!" , e );
159
+ LOGGER .error ("A communication error occured!" , e );
160
+ } catch (SteemInvalidTransactionException e ) {
161
+ LOGGER .error ("There was a problem to sign a transaction." , e );
132
162
}
133
163
}
134
164
0 commit comments