Skip to content

Commit 1c67c90

Browse files
committed
Fix #155 ; Fix #153 ; Work on #95 ; Work on #76 ; Work on #5
1 parent dd9cd71 commit 1c67c90

131 files changed

Lines changed: 990 additions & 1121 deletions

File tree

Some content is hidden

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

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

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
import org.slf4j.LoggerFactory;
2121

2222
import com.fasterxml.jackson.annotation.JsonCreator;
23-
import com.fasterxml.jackson.annotation.JsonProperty;
2423
import com.fasterxml.jackson.annotation.JsonIgnore;
25-
import com.google.common.annotations.VisibleForTesting;
24+
import com.fasterxml.jackson.annotation.JsonProperty;
2625

2726
import eu.bittrade.libs.steemj.base.models.operations.Operation;
2827
import eu.bittrade.libs.steemj.configuration.SteemJConfig;
2928
import eu.bittrade.libs.steemj.enums.PrivateKeyType;
29+
import eu.bittrade.libs.steemj.enums.ValidationType;
3030
import eu.bittrade.libs.steemj.exceptions.SteemInvalidTransactionException;
3131
import eu.bittrade.libs.steemj.interfaces.ByteTransformable;
3232
import eu.bittrade.libs.steemj.interfaces.SignatureObject;
@@ -106,17 +106,6 @@ public SignedTransaction(BlockId blockId, List<Operation> operations, List<Futur
106106
this.signatures = new ArrayList<>();
107107
}
108108

109-
/**
110-
* <b>This method is only used by JUnit-Tests</b>
111-
*
112-
* Create a new signed transaction object.
113-
*/
114-
@VisibleForTesting
115-
protected SignedTransaction() {
116-
super();
117-
this.signatures = new ArrayList<>();
118-
}
119-
120109
/**
121110
* Get the signatures for this transaction.
122111
*
@@ -145,57 +134,28 @@ private boolean isCanonical(byte[] signature) {
145134

146135
/**
147136
*
148-
* Like {@link #sign(String) sign(String)}, but uses the default Steem chain
149-
* id.
150-
*
151-
* @param skipValidation
152-
* Define if the validation should be skipped or not.
153-
* @throws SteemInvalidTransactionException
154-
* If the transaction can not be signed.
155-
*/
156-
@VisibleForTesting
157-
protected void sign(boolean skipValidation) throws SteemInvalidTransactionException {
158-
sign(SteemJConfig.getInstance().getChainId(), skipValidation);
159-
}
160-
161-
/**
162-
*
163-
* Like {@link #sign(String) sign(String)}, but uses the default Steem chain
164-
* id.
137+
* Like {@link #sign(String) sign(String)}, but uses the
138+
* {@link SteemJConfig#getChainId() default chain id}.
165139
*
166140
* @throws SteemInvalidTransactionException
167141
* If the transaction can not be signed.
168142
*/
169143
public void sign() throws SteemInvalidTransactionException {
170-
sign(SteemJConfig.getInstance().getChainId(), false);
144+
sign(SteemJConfig.getInstance().getChainId());
171145
}
172146

173147
/**
174148
* Use this method if you want to specify a different chainId than the
175-
* default one for STEEM. Otherwise use the {@link #sign() sign()} method.
149+
* {@link SteemJConfig#getChainId() default one}. Otherwise use the
150+
* {@link #sign() sign()} method.
176151
*
177152
* @param chainId
178153
* The chain id that should be used during signing.
179154
* @throws SteemInvalidTransactionException
180155
* If the transaction can not be signed.
181156
*/
182157
public void sign(String chainId) throws SteemInvalidTransactionException {
183-
sign(chainId, false);
184-
}
185-
186-
/**
187-
* Use this method if you want to specify a different chainId than the
188-
* default one for STEEM. Otherwise use the {@link #sign() sign()} method.
189-
*
190-
* @param chainId
191-
* The chain id that should be used during signing.
192-
* @param skipValidation
193-
* Define if the validation should be skipped or not.
194-
* @throws SteemInvalidTransactionException
195-
* If the transaction can not be signed.
196-
*/
197-
protected void sign(String chainId, boolean skipValidation) throws SteemInvalidTransactionException {
198-
if (!skipValidation) {
158+
if (!SteemJConfig.getInstance().getValidationLevel().equals(ValidationType.SKIP_VALIDATION)) {
199159
this.validate();
200160
}
201161

core/src/main/java/eu/bittrade/libs/steemj/base/models/deserializer/GuestBloggerPairDeserializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ public class GuestBloggerPairDeserializer extends JsonDeserializer<List<Pair<Acc
2424
public List<Pair<AccountName, Long>> deserialize(JsonParser jsonParser,
2525
DeserializationContext deserializationContext) throws IOException {
2626

27-
List<Pair<AccountName, Long>> result = new ArrayList<>();
27+
List<Pair<AccountName, Long>> result = new ArrayList<>();
2828

2929
ObjectCodec codec = jsonParser.getCodec();
3030
TreeNode rootNode = codec.readTree(jsonParser);
3131

3232
if (rootNode.isArray()) {
3333
for (JsonNode node : (ArrayNode) rootNode) {
34-
//result.put((node.get(0)).asText(), (node.get(0)).asInt());
34+
// result.put((node.get(0)).asText(), (node.get(0)).asInt());
3535
}
3636

3737
return result;

core/src/main/java/eu/bittrade/libs/steemj/base/models/operations/AbstractAccountCreateOperation.java

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ public Asset getFee() {
6161
* than 0.
6262
*/
6363
public void setFee(Asset fee) {
64-
if (fee == null) {
65-
throw new InvalidParameterException("The fee can't be null.");
66-
}
67-
68-
this.fee = fee;
64+
this.fee = setIfNotNull(fee, "The fee can't be null.");
6965
}
7066

7167
/**
@@ -87,11 +83,7 @@ public AccountName getCreator() {
8783
* If the <code>creator</code> is null.
8884
*/
8985
public void setCreator(AccountName creator) {
90-
if (creator == null) {
91-
throw new InvalidParameterException("The creator can't be null.");
92-
}
93-
94-
this.creator = creator;
86+
this.creator = setIfNotNull(creator, "The creator can't be null.");
9587
}
9688

9789
/**
@@ -112,11 +104,7 @@ public AccountName getNewAccountName() {
112104
* If the <code>newAccountName</code> is null.
113105
*/
114106
public void setNewAccountName(AccountName newAccountName) {
115-
if (newAccountName == null) {
116-
throw new InvalidParameterException("The new account name can't be null.");
117-
}
118-
119-
this.newAccountName = newAccountName;
107+
this.newAccountName = setIfNotNull(newAccountName, "The new account name can't be null.");
120108
}
121109

122110
/**
@@ -141,11 +129,7 @@ public Authority getOwner() {
141129
*/
142130
@Override
143131
public void setOwner(Authority owner) {
144-
if (owner == null) {
145-
throw new InvalidParameterException("The owner can't be null.");
146-
}
147-
148-
this.owner = owner;
132+
this.owner = setIfNotNull(owner, "The owner can't be null.");
149133
}
150134

151135
/**
@@ -170,11 +154,7 @@ public Authority getActive() {
170154
*/
171155
@Override
172156
public void setActive(Authority active) {
173-
if (active == null) {
174-
throw new InvalidParameterException("The active can't be null.");
175-
}
176-
177-
this.active = active;
157+
this.active = setIfNotNull(active, "The active can't be null.");
178158
}
179159

180160
/**
@@ -199,11 +179,7 @@ public Authority getPosting() {
199179
*/
200180
@Override
201181
public void setPosting(Authority posting) {
202-
if (posting == null) {
203-
throw new InvalidParameterException("The posting can't be null.");
204-
}
205-
206-
this.posting = posting;
182+
this.posting = setIfNotNull(posting, "The posting can't be null.");
207183
}
208184

209185
/**

core/src/main/java/eu/bittrade/libs/steemj/base/models/operations/AbstractEscrowOperation.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ public AccountName getFrom() {
5858
* If the <code>from</code> is null.
5959
*/
6060
public void setFrom(AccountName from) {
61-
if (from == null) {
62-
throw new InvalidParameterException("The from account can't be null.");
63-
}
64-
65-
this.from = from;
61+
this.from = setIfNotNull(from, "The from account can't be null.");
6662
}
6763

6864
/**
@@ -83,11 +79,7 @@ public AccountName getTo() {
8379
* If the <code>to</code> is null.
8480
*/
8581
public void setTo(AccountName to) {
86-
if (to == null) {
87-
throw new InvalidParameterException("The to account can't be null.");
88-
}
89-
90-
this.to = to;
82+
this.to = setIfNotNull(to, "The to account can't be null.");
9183
}
9284

9385
/**
@@ -108,11 +100,7 @@ public AccountName getAgent() {
108100
* If the <code>agent</code> is null.
109101
*/
110102
public void setAgent(AccountName agent) {
111-
if (agent == null) {
112-
throw new InvalidParameterException("The agent can't be null.");
113-
}
114-
115-
this.agent = agent;
103+
this.agent = setIfNotNull(agent, "The agent can't be null.");
116104
}
117105

118106
/**

core/src/main/java/eu/bittrade/libs/steemj/base/models/operations/AbstractTransferOperation.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ public AccountName getFrom() {
5858
* If the <code>from</code> account is null.
5959
*/
6060
public void setFrom(AccountName from) {
61-
if (from == null) {
62-
throw new InvalidParameterException("The from account can't be null.");
63-
}
64-
65-
this.from = from;
61+
this.from = setIfNotNull(from, "The from account can't be null.");
6662
}
6763

6864
/**
@@ -86,11 +82,7 @@ public AccountName getTo() {
8682
* If the <code>to</code> account is null.
8783
*/
8884
public void setTo(AccountName to) {
89-
if (to == null) {
90-
throw new InvalidParameterException("The to account can't be null.");
91-
}
92-
93-
this.to = to;
85+
this.to = setIfNotNull(to, "The to account can't be null.");
9486
}
9587

9688
/**
@@ -111,11 +103,7 @@ public Asset getAmount() {
111103
* If the <code>amount</code> is null.
112104
*/
113105
public void setAmount(Asset amount) {
114-
if (amount == null) {
115-
throw new InvalidParameterException("The amount can't be null.");
116-
}
117-
118-
this.amount = amount;
106+
this.amount = setIfNotNull(amount, "The amount can't be null.");
119107
}
120108

121109
@Override

core/src/main/java/eu/bittrade/libs/steemj/base/models/operations/AccountCreateOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public AccountCreateOperation(@JsonProperty("creator") AccountName creator, @Jso
7575
@Override
7676
public byte[] toByteArray() throws SteemInvalidTransactionException {
7777
try (ByteArrayOutputStream serializedAccountCreateOperation = new ByteArrayOutputStream()) {
78-
serializedAccountCreateOperation
79-
.write(SteemJUtils.transformIntToVarIntByteArray(OperationType.ACCOUNT_CREATE_OPERATION.ordinal()));
78+
serializedAccountCreateOperation.write(
79+
SteemJUtils.transformIntToVarIntByteArray(OperationType.ACCOUNT_CREATE_OPERATION.getOrderId()));
8080
serializedAccountCreateOperation.write(this.getFee().toByteArray());
8181
serializedAccountCreateOperation.write(this.getCreator().toByteArray());
8282
serializedAccountCreateOperation.write(this.getNewAccountName().toByteArray());

core/src/main/java/eu/bittrade/libs/steemj/base/models/operations/AccountCreateWithDelegationOperation.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,7 @@ public Asset getDelegation() {
117117
* than 0.
118118
*/
119119
public void setDelegation(Asset delegation) {
120-
if (delegation == null) {
121-
throw new InvalidParameterException("The delegation can't be null.");
122-
}
123-
124-
this.delegation = delegation;
120+
this.delegation = setIfNotNull(delegation, "The delegation can't be null.");
125121
}
126122

127123
/**
@@ -150,8 +146,8 @@ public void setExtensions(List<FutureExtensions> extensions) {
150146
@Override
151147
public byte[] toByteArray() throws SteemInvalidTransactionException {
152148
try (ByteArrayOutputStream serializedAccountCreateWithDelegationOperation = new ByteArrayOutputStream()) {
153-
serializedAccountCreateWithDelegationOperation.write(SteemJUtils
154-
.transformIntToVarIntByteArray(OperationType.ACCOUNT_CREATE_WITH_DELEGATION_OPERATION.ordinal()));
149+
serializedAccountCreateWithDelegationOperation.write(SteemJUtils.transformIntToVarIntByteArray(
150+
OperationType.ACCOUNT_CREATE_WITH_DELEGATION_OPERATION.getOrderId()));
155151
serializedAccountCreateWithDelegationOperation.write(this.getFee().toByteArray());
156152
serializedAccountCreateWithDelegationOperation.write(this.getDelegation().toByteArray());
157153
serializedAccountCreateWithDelegationOperation.write(this.getCreator().toByteArray());

core/src/main/java/eu/bittrade/libs/steemj/base/models/operations/AccountUpdateOperation.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,14 @@ public AccountName getAccount() {
178178
* If the <code>account</code> is null.
179179
*/
180180
public void setAccount(AccountName account) {
181-
if (account == null) {
182-
throw new InvalidParameterException("The account can't be null.");
183-
}
184-
185-
this.account = account;
181+
this.account = setIfNotNull(account, "The account can't be null.");
186182
}
187183

188184
@Override
189185
public byte[] toByteArray() throws SteemInvalidTransactionException {
190186
try (ByteArrayOutputStream serializedAccountUpdateOperation = new ByteArrayOutputStream()) {
191-
serializedAccountUpdateOperation
192-
.write(SteemJUtils.transformIntToVarIntByteArray(OperationType.ACCOUNT_UPDATE_OPERATION.ordinal()));
187+
serializedAccountUpdateOperation.write(
188+
SteemJUtils.transformIntToVarIntByteArray(OperationType.ACCOUNT_UPDATE_OPERATION.getOrderId()));
193189
serializedAccountUpdateOperation.write(this.getAccount().toByteArray());
194190

195191
// Handle optional values.

core/src/main/java/eu/bittrade/libs/steemj/base/models/operations/AccountWitnessProxyOperation.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,7 @@ public AccountName getAccount() {
7171
* been configured as the proxy.
7272
*/
7373
public void setAccount(AccountName account) {
74-
if (account == null) {
75-
throw new InvalidParameterException("The account can't be null.");
76-
}
77-
78-
this.account = account;
74+
this.account = setIfNotNull(account, "The account can't be null.");
7975
}
8076

8177
/**
@@ -108,8 +104,8 @@ public void setProxy(AccountName proxy) {
108104
@Override
109105
public byte[] toByteArray() throws SteemInvalidTransactionException {
110106
try (ByteArrayOutputStream serializedAccountWitnessProxyOperation = new ByteArrayOutputStream()) {
111-
serializedAccountWitnessProxyOperation.write(
112-
SteemJUtils.transformIntToVarIntByteArray(OperationType.ACCOUNT_WITNESS_PROXY_OPERATION.ordinal()));
107+
serializedAccountWitnessProxyOperation.write(SteemJUtils
108+
.transformIntToVarIntByteArray(OperationType.ACCOUNT_WITNESS_PROXY_OPERATION.getOrderId()));
113109
serializedAccountWitnessProxyOperation.write(this.getAccount().toByteArray());
114110
serializedAccountWitnessProxyOperation.write(this.getProxy().toByteArray());
115111

core/src/main/java/eu/bittrade/libs/steemj/base/models/operations/AccountWitnessVoteOperation.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,7 @@ public AccountName getAccount() {
9898
* If the <code>account</code> account is null
9999
*/
100100
public void setAccount(AccountName account) {
101-
if (account == null) {
102-
throw new InvalidParameterException("The witness acccount can't be null.");
103-
}
104-
105-
this.account = account;
101+
this.account = setIfNotNull(account, "The witness acccount can't be null.");
106102
}
107103

108104
/**
@@ -123,11 +119,7 @@ public AccountName getWitness() {
123119
* If the <code>witness</code> account is null
124120
*/
125121
public void setWitness(AccountName witness) {
126-
if (witness == null) {
127-
throw new InvalidParameterException("The witness acccount can't be null.");
128-
}
129-
130-
this.witness = witness;
122+
this.witness = setIfNotNull(witness, "The witness acccount can't be null.");
131123
}
132124

133125
/**
@@ -152,8 +144,8 @@ public void setApprove(boolean approve) {
152144
@Override
153145
public byte[] toByteArray() throws SteemInvalidTransactionException {
154146
try (ByteArrayOutputStream serializedAccountWitnessVoteOperation = new ByteArrayOutputStream()) {
155-
serializedAccountWitnessVoteOperation.write(
156-
SteemJUtils.transformIntToVarIntByteArray(OperationType.ACCOUNT_WITNESS_VOTE_OPERATION.ordinal()));
147+
serializedAccountWitnessVoteOperation.write(SteemJUtils
148+
.transformIntToVarIntByteArray(OperationType.ACCOUNT_WITNESS_VOTE_OPERATION.getOrderId()));
157149
serializedAccountWitnessVoteOperation.write(this.getAccount().toByteArray());
158150
serializedAccountWitnessVoteOperation.write(this.getWitness().toByteArray());
159151
serializedAccountWitnessVoteOperation.write(SteemJUtils.transformBooleanToByteArray(this.getApprove()));

0 commit comments

Comments
 (0)