Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions client/src/main/java/jp/co/soramitsu/iroha/java/BlocksQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ public Queries.BlocksQuery buildUnsigned() {
return q.build();
}

public static BlocksQueryBuilder builder(String accountId, Instant time, long counter) {
return new BlocksQueryBuilder(accountId, time, counter);
public static BlocksQueryBuilder builder(String accountId, Instant time, long counter, FieldValidator.Config config) {
return new BlocksQueryBuilder(accountId, time, counter, config);
}

public static BlocksQueryBuilder builder(String accountId, Date time, long counter) {
return new BlocksQueryBuilder(accountId, time, counter);
public static BlocksQueryBuilder builder(String accountId, Date time, long counter, FieldValidator.Config config) {
return new BlocksQueryBuilder(accountId, time, counter, config);
}

public static BlocksQueryBuilder builder(String accountId, Long time, long counter) {
return new BlocksQueryBuilder(accountId, time, counter);
public static BlocksQueryBuilder builder(String accountId, Long time, long counter, FieldValidator.Config config) {
return new BlocksQueryBuilder(accountId, time, counter, config);
}

public static BlocksQueryBuilder builder(String accountId, long counter) {
return builder(accountId, System.currentTimeMillis(), counter);
public static BlocksQueryBuilder builder(String accountId, long counter, FieldValidator.Config config) {
return builder(accountId, System.currentTimeMillis(), counter, config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import jp.co.soramitsu.crypto.ed25519.Ed25519Sha3.CryptoException;

public class BlocksQueryBuilder {

private final FieldValidator.Config config;
private FieldValidator validator;

private QueryPayloadMeta.Builder meta = QueryPayloadMeta.newBuilder();
Expand All @@ -25,20 +25,21 @@ private void init(String accountId, Long time, long counter) {
setCounter(counter);
}

public BlocksQueryBuilder(String accountId, Instant time, long counter) {
init(accountId, time.toEpochMilli(), counter);
public BlocksQueryBuilder(String accountId, Instant time, long counter, FieldValidator.Config config) {
this(accountId, time.toEpochMilli(), counter, config);
}

public BlocksQueryBuilder(String accountId, Date time, long counter) {
init(accountId, time.getTime(), counter);
public BlocksQueryBuilder(String accountId, Date time, long counter, FieldValidator.Config config) {
this(accountId, time.getTime(), counter, config);
}

public BlocksQueryBuilder(String accountId, Long time, long counter) {
public BlocksQueryBuilder(String accountId, Long time, long counter, FieldValidator.Config config) {
this.config = config;
init(accountId, time, counter);
}

public BlocksQueryBuilder enableValidation() {
this.validator = new FieldValidator();
this.validator = new FieldValidator(this.config);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
* Stateless validator for transaction and query fields.
*/
public class FieldValidator {
private final int maxDescriptionLength;

static final class Config {
int maxDescriptionLength;
Config(int maxDescriptionLength) {
this.maxDescriptionLength = maxDescriptionLength;
}
}

public static final Config defaultConfig = new Config(64);

FieldValidator(Config config){
this.maxDescriptionLength = config.maxDescriptionLength;
}

public void checkAmount(@NonNull String amount) {
BigDecimal am;
Expand Down Expand Up @@ -154,7 +168,7 @@ public void checkEvmAddress(@NonNull String address) {
}
}

public void checkPublicKey(@NonNull byte[] peerKey) {
public void checkPublicKey(byte[] peerKey) {
if (peerKey.length != 32 && peerKey.length != 35) {
throw new ValidationException(PUBKEY, "Public key must be 32 or 35 bytes length, got '%d'",
peerKey.length);
Expand Down Expand Up @@ -205,9 +219,9 @@ public void checkDescription(String description) {
}

int len = description.length();
if (len > 64) {
throw new ValidationException(DESCRIPTION, "Max length is 64, given string length is '%d'",
len);
if (len > this.maxDescriptionLength) {
throw new ValidationException(DESCRIPTION, String.format("Max length is '%d', given string length is '%d'",
this.maxDescriptionLength, len));
}
}

Expand Down
32 changes: 16 additions & 16 deletions client/src/main/java/jp/co/soramitsu/iroha/java/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,35 +63,35 @@ public Queries.Query buildUnsigned() {
return q.build();
}

public static QueryBuilder builder(String accountId, Long time, long counter) {
return new QueryBuilder(accountId, time, counter);
public static QueryBuilder builder(String accountId, Long time, long counter, FieldValidator.Config config) {
return new QueryBuilder(accountId, time, counter, config);
}

public static QueryBuilder builder(String accountId, Date time, long counter) {
return new QueryBuilder(accountId, time, counter);
public static QueryBuilder builder(String accountId, Date time, long counter, FieldValidator.Config config) {
return new QueryBuilder(accountId, time, counter, config);
}

public static QueryBuilder builder(String accountId, Instant time, long counter) {
return new QueryBuilder(accountId, time, counter);
public static QueryBuilder builder(String accountId, Instant time, long counter, FieldValidator.Config config) {
return new QueryBuilder(accountId, time, counter, config);
}

public static QueryBuilder builder(String accountId, long counter) {
return new QueryBuilder(accountId, Instant.now(), counter);
public static QueryBuilder builder(String accountId, long counter, FieldValidator.Config config) {
return new QueryBuilder(accountId, Instant.now(), counter, config);
}

public static QueryBuilder builder(String accountId, Long time, long counter, SignatureBuilder signatureBuilder) {
return new QueryBuilder(accountId, time, counter, signatureBuilder);
public static QueryBuilder builder(String accountId, Long time, long counter, SignatureBuilder signatureBuilder, FieldValidator.Config config) {
return new QueryBuilder(accountId, time, counter, signatureBuilder, config);
}

public static QueryBuilder builder(String accountId, Date time, long counter, SignatureBuilder signatureBuilder) {
return new QueryBuilder(accountId, time, counter, signatureBuilder);
public static QueryBuilder builder(String accountId, Date time, long counter, SignatureBuilder signatureBuilder, FieldValidator.Config config) {
return new QueryBuilder(accountId, time, counter, signatureBuilder, config);
}

public static QueryBuilder builder(String accountId, Instant time, long counter, SignatureBuilder signatureBuilder) {
return new QueryBuilder(accountId, time, counter, signatureBuilder);
public static QueryBuilder builder(String accountId, Instant time, long counter, SignatureBuilder signatureBuilder, FieldValidator.Config config) {
return new QueryBuilder(accountId, time, counter, signatureBuilder, config);
}

public static QueryBuilder builder(String accountId, long counter, SignatureBuilder signatureBuilder) {
return new QueryBuilder(accountId, Instant.now(), counter, signatureBuilder);
public static QueryBuilder builder(String accountId, long counter, SignatureBuilder signatureBuilder, FieldValidator.Config config) {
return new QueryBuilder(accountId, Instant.now(), counter, signatureBuilder, config);
}
}
61 changes: 27 additions & 34 deletions client/src/main/java/jp/co/soramitsu/iroha/java/QueryAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,29 @@ public class QueryAPI {
private String accountId;
@NonNull
private KeyPair keyPair;

@NonNull
private final FieldValidator.Config config;
// default signature builder
private SignatureBuilder signatureBuilder;

public QueryAPI(IrohaAPI api, String accountId, KeyPair keyPair) {
this.api = api;
this.accountId = accountId;
this.keyPair = keyPair;
signatureBuilder = Ed25519Sha3SignatureBuilder.getInstance();
public QueryAPI(IrohaAPI api, String accountId, KeyPair keyPair, FieldValidator.Config config) {
this(api, accountId, keyPair, Ed25519Sha3SignatureBuilder.getInstance(), config);
}

public QueryAPI(IrohaAPI api, String accountId, KeyPair keyPair, SignatureBuilder signatureBuilder) {
public QueryAPI(IrohaAPI api, String accountId, KeyPair keyPair, SignatureBuilder signatureBuilder, FieldValidator.Config config) {
this.api = api;
this.accountId = accountId;
this.keyPair = keyPair;
this.signatureBuilder = signatureBuilder;
this.config = config;
}

public QueryAPI(IrohaAPI api, Account account) {
this.api = api;
this.accountId = account.getId();
this.keyPair = account.getKeyPair();
signatureBuilder = Ed25519Sha3SignatureBuilder.getInstance();
public QueryAPI(IrohaAPI api, Account account, FieldValidator.Config config) {
this(api, account.getId(), account.getKeyPair(), Ed25519Sha3SignatureBuilder.getInstance(), config);
}

public QueryAPI(IrohaAPI api, Account account, SignatureBuilder signatureBuilder) {
this.api = api;
this.accountId = account.getId();
this.keyPair = account.getKeyPair();
this.signatureBuilder = signatureBuilder;
public QueryAPI(IrohaAPI api, Account account, SignatureBuilder signatureBuilder, FieldValidator.Config config) {
this(api, account.getId(), account.getKeyPair(), signatureBuilder, config);
}

private static AtomicInteger counter = new AtomicInteger(1);
Expand All @@ -77,7 +70,7 @@ private void checkErrorResponse(QueryResponse response) {
}

public EngineReceiptsResponse getEngineReceipts(String txHash) {
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder)
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder, this.config)
.getEngineReceipts(txHash)
.buildSigned(keyPair);

Expand All @@ -89,7 +82,7 @@ public EngineReceiptsResponse getEngineReceipts(String txHash) {
}

public PeersResponse getPeers() {
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder)
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder, this.config)
.getPeers()
.buildSigned(keyPair);

Expand All @@ -111,7 +104,7 @@ public String getAccountDetails(
String writer,
String key
) {
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder)
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder, this.config)
.getAccountDetail(accountId, writer, key)
.buildSigned(keyPair);

Expand All @@ -132,7 +125,7 @@ public AccountDetailResponse getAccountDetails(
String accountDetailRecordIdWriter,
String accountDetailRecordIdKey
) {
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder)
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder, this.config)
.getAccountDetail(
accountId,
writer,
Expand Down Expand Up @@ -160,7 +153,7 @@ public AccountDetailResponse getAccountDetails(
}

public AccountResponse getAccount(String accountId) {
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder)
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder, this.config)
.getAccount(accountId)
.buildSigned(keyPair);

Expand All @@ -172,7 +165,7 @@ public AccountResponse getAccount(String accountId) {
}

public BlockResponse getBlock(Long height) {
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder)
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder, this.config)
.getBlock(height)
.buildSigned(keyPair);

Expand All @@ -190,7 +183,7 @@ public TransactionsPageResponse getAccountTransactions(String accountId,
Timestamp lastTxTime,
Integer firstTxHeight,
Integer lastTxHeight) {
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder)
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder, this.config)
.getAccountTransactions(accountId, pageSize, firstHashHex, ordering, firstTxTime, lastTxTime, firstTxHeight, lastTxHeight)
.buildSigned(keyPair);

Expand Down Expand Up @@ -243,7 +236,7 @@ public TransactionsPageResponse getAccountAssetTransactions(String accountId,
Integer firstTxHeight,
Integer lastTxHeight) {

val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder)
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder, this.config)
.getAccountAssetTransactions(accountId, assetId, pageSize, firstHashHex, ordering, firstTxTime, lastTxTime, firstTxHeight, lastTxHeight)
.buildSigned(keyPair);

Expand Down Expand Up @@ -283,7 +276,7 @@ public TransactionsResponse getTransactions(List<byte[]> hashes) {
}

public TransactionsResponse getTransactions(Iterable<String> hashes) {
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder)
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder, this.config)
.getTransactions(hashes)
.buildSigned(keyPair);

Expand All @@ -295,7 +288,7 @@ public TransactionsResponse getTransactions(Iterable<String> hashes) {
}

public AssetResponse getAssetInfo(String assetId) {
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder)
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder, this.config)
.getAssetInfo(assetId)
.buildSigned(keyPair);

Expand All @@ -313,7 +306,7 @@ public AssetResponse getAssetInfo(String assetId) {
*/
@Deprecated
public AccountAssetResponse getAccountAssets(String accountId) {
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder)
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder, this.config)
.getAccountAssets(accountId)
.buildSigned(keyPair);

Expand All @@ -329,7 +322,7 @@ public AccountAssetResponse getAccountAssets(
Integer pageSize,
String firstAssetId
) {
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder)
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder, this.config)
.getAccountAssets(accountId, pageSize, firstAssetId)
.buildSigned(keyPair);

Expand All @@ -348,7 +341,7 @@ public AccountAssetResponse getAccountAssets(
}

public SignatoriesResponse getSignatories(String accountId) {
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder)
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder, this.config)
.getSignatories(accountId)
.buildSigned(keyPair);

Expand All @@ -366,7 +359,7 @@ public SignatoriesResponse getSignatories(String accountId) {
*/
@Deprecated
public TransactionsResponse getPendingTransactions() {
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder)
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder, this.config)
.getPendingTransactions()
.buildSigned(keyPair);

Expand All @@ -386,7 +379,7 @@ public TransactionsResponse getPendingTransactions(
Integer firstTxHeight,
Integer lastTxHeight
) {
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder)
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder, this.config)
.getPendingTransactions(pageSize, firstHashHex, ordering, firstTxTime, lastTxTime, firstTxHeight, lastTxHeight)
.buildSigned(keyPair);

Expand Down Expand Up @@ -426,7 +419,7 @@ public TransactionsResponse getPendingTransactions(
}

public RolesResponse getRoles() {
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder)
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder, this.config)
.getRoles()
.buildSigned(keyPair);

Expand All @@ -438,7 +431,7 @@ public RolesResponse getRoles() {
}

public RolePermissionsResponse getRolePermissions(String roleId) {
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder)
val q = Query.builder(this.accountId, counter.getAndIncrement(), signatureBuilder, this.config)
.getRolePermissions(roleId)
.buildSigned(keyPair);

Expand Down
Loading