Skip to content

Commit

Permalink
Feature/update iroha 1.2.0 (#68)
Browse files Browse the repository at this point in the history
* Update commands and queries

update docker and protobuf
add commands SetSettingValue, CallEngine
add query GetEngineReceipts
add new permissions
update compareAndSet - add checkEmpty parameter
add ordering
add Ed25519/Sha2 crypto support
implement setSettingValue
Iroha release! Update Iroha container to hyperledger/iroha:1.2.0
fix send transaction list test - wait until all is committed
tls support for Iroha API

Signed-off-by: Alexey-N-Chernyshov <[email protected]>
  • Loading branch information
Alexey-N-Chernyshov authored Dec 8, 2020
1 parent 3242dd7 commit a003266
Show file tree
Hide file tree
Showing 44 changed files with 1,409 additions and 194 deletions.
30 changes: 3 additions & 27 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,6 @@ subprojects {
sourceCompatibility = 1.8 // java 8
targetCompatibility = 1.8

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

artifacts {
archives sourcesJar
archives javadocJar
}

final def rootReportDir = "${buildDir}/reports/}"

jacoco {
Expand All @@ -54,18 +39,9 @@ subprojects {
}

test {
testlogger {
theme 'standard'
showExceptions true
slowThreshold 2000
showSummary true
showPassed true
showSkipped true
showFailed true
showStandardStreams true
showPassedStandardStreams false
showSkippedStandardStreams false
showFailedStandardStreams true
testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ repositories {
}

final def spockVersion = '1.2-groovy-2.4'
final def edVersion = '2.0.1'
final def edSha3Version = '2.0.1'
final def edDsaVersion = '0.3.0'
final def spockGenesisVersion = '0.6.0'
final def lombokVersion = '1.18.4'
final def rxjavaVersion = '2.2.4'
Expand All @@ -22,7 +23,8 @@ final def objgenesisVersion = '3.0.1'

dependencies {
compile "io.reactivex.rxjava2:rxjava:${rxjavaVersion}"
compile("com.github.warchant:ed25519-sha3-java:${edVersion}")
compile "com.github.warchant:ed25519-sha3-java:${edSha3Version}"
compile "net.i2p.crypto:eddsa:${edDsaVersion}"

compileOnly("org.projectlombok:lombok:$lombokVersion")
testCompileOnly("org.projectlombok:lombok:$lombokVersion")
Expand All @@ -33,10 +35,14 @@ dependencies {
testCompile project(":testcontainers")
compile group: 'com.jcabi', name: 'jcabi-aspects', version: "${jcabiVersion}"

runtime 'io.netty:netty-tcnative-boringssl-static:2.0.34.Final'

// for mocking in groovy
testCompile("net.bytebuddy:byte-buddy:${bytebuddyVersion}")
testCompile("org.objenesis:objenesis:${objgenesisVersion}")
testCompile("cglib:cglib-nodep:${cglibVersion}")

implementation 'javax.annotation:javax.annotation-api:1.3.2'
}

apply from: 'proto.gradle'
Expand Down
4 changes: 2 additions & 2 deletions client/proto.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ext {
grpcVersion = '1.29.0'
protobufVersion = '3.12.2'
grpcVersion = '1.33.1'
protobufVersion = '3.14.0'
}

repositories {
Expand Down
13 changes: 12 additions & 1 deletion client/src/main/java/jp/co/soramitsu/iroha/java/BlocksQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,29 @@
import java.time.Instant;
import java.util.Date;
import jp.co.soramitsu.crypto.ed25519.Ed25519Sha3.CryptoException;
import jp.co.soramitsu.iroha.java.crypto.Ed25519Sha3SignatureBuilder;
import jp.co.soramitsu.iroha.java.crypto.SignatureBuilder;
import jp.co.soramitsu.iroha.java.detail.Hashable;

public class BlocksQuery
extends Hashable<Payload.Builder> {

private QueryPayloadMeta.Builder meta;
private SignatureBuilder signatureBuilder;
private Queries.BlocksQuery.Builder q = Queries.BlocksQuery.newBuilder();

public BlocksQuery(QueryPayloadMeta.Builder meta) {
super(Payload.newBuilder());

this.meta = meta;
signatureBuilder = Ed25519Sha3SignatureBuilder.getInstance();
}

public BlocksQuery(QueryPayloadMeta.Builder meta, SignatureBuilder signatureBuilder) {
super(Payload.newBuilder());

this.meta = meta;
this.signatureBuilder = signatureBuilder;
}

public byte[] payload() {
Expand All @@ -32,7 +43,7 @@ private void updatePayload() {

public Queries.BlocksQuery buildSigned(KeyPair keyPair) throws CryptoException {
updatePayload();
q.setSignature(Utils.sign(this, keyPair));
q.setSignature(signatureBuilder.sign(this, keyPair));
return q.build();
}

Expand Down
62 changes: 35 additions & 27 deletions client/src/main/java/jp/co/soramitsu/iroha/java/FieldValidator.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,7 @@
package jp.co.soramitsu.iroha.java;

import static jp.co.soramitsu.iroha.java.ValidationException.Type.ACCOUNT_ID;
import static jp.co.soramitsu.iroha.java.ValidationException.Type.ACCOUNT_NAME;
import static jp.co.soramitsu.iroha.java.ValidationException.Type.AMOUNT;
import static jp.co.soramitsu.iroha.java.ValidationException.Type.ASSET_ID;
import static jp.co.soramitsu.iroha.java.ValidationException.Type.ASSET_NAME;
import static jp.co.soramitsu.iroha.java.ValidationException.Type.DESCRIPTION;
import static jp.co.soramitsu.iroha.java.ValidationException.Type.DETAILS_KEY;
import static jp.co.soramitsu.iroha.java.ValidationException.Type.DETAILS_VALUE;
import static jp.co.soramitsu.iroha.java.ValidationException.Type.DOMAIN;
import static jp.co.soramitsu.iroha.java.ValidationException.Type.HASH_LENGTH;
import static jp.co.soramitsu.iroha.java.ValidationException.Type.PAGE_SIZE;
import static jp.co.soramitsu.iroha.java.ValidationException.Type.PEER_ADDRESS;
import static jp.co.soramitsu.iroha.java.ValidationException.Type.PRECISION;
import static jp.co.soramitsu.iroha.java.ValidationException.Type.PUBKEY;
import static jp.co.soramitsu.iroha.java.ValidationException.Type.QUORUM;
import static jp.co.soramitsu.iroha.java.ValidationException.Type.ROLE_NAME;
import static jp.co.soramitsu.iroha.java.ValidationException.Type.TIMESTAMP;
import static jp.co.soramitsu.iroha.java.detail.Const.accountDetailsKeyPattern;
import static jp.co.soramitsu.iroha.java.detail.Const.accountDetailsMaxLength;
import static jp.co.soramitsu.iroha.java.detail.Const.accountIdDelimiter;
import static jp.co.soramitsu.iroha.java.detail.Const.accountPattern;
import static jp.co.soramitsu.iroha.java.detail.Const.assetIdDelimiter;
import static jp.co.soramitsu.iroha.java.detail.Const.assetNamePattern;
import static jp.co.soramitsu.iroha.java.detail.Const.hostPortDelimiter;
import static jp.co.soramitsu.iroha.java.detail.Const.roleNamePattern;
import static jp.co.soramitsu.iroha.java.ValidationException.Type.*;
import static jp.co.soramitsu.iroha.java.detail.Const.*;

import java.math.BigDecimal;
import java.net.URI;
Expand Down Expand Up @@ -165,13 +142,32 @@ public void checkPeerAddress(@NonNull String address) {
}
}

public void checkEvmAddress(@NonNull String address) {
val m = evmAddress.matcher(address);
if (!m.matches()) {
throw new ValidationException(
EVM_ADDRESS,
"Invalid EVM address. Expected '%s', got '%s'",
evmAddress.pattern(),
address
);
}
}

public void checkPublicKey(@NonNull byte[] peerKey) {
if (peerKey.length != 32) {
throw new ValidationException(PUBKEY, "Public key must be 32 bytes length, got '%d'",
if (peerKey.length != 32 && peerKey.length != 35) {
throw new ValidationException(PUBKEY, "Public key must be 32 or 35 bytes length, got '%d'",
peerKey.length);
}
}

public void checkPublicKey(@NonNull String peerKey) {
if (peerKey.length() != 64 && ((peerKey.length() != 70) || !peerKey.toLowerCase().startsWith("ed0120"))) {
throw new ValidationException(PUBKEY, "Public key must be 64 or 70 hex length with supported format, got '%d'",
peerKey.length());
}
}

public void checkRoleName(@NonNull String roleName) {
Matcher m = roleNamePattern.matcher(roleName);
if (!m.find()) {
Expand Down Expand Up @@ -228,4 +224,16 @@ public void checkHashLength(@NonNull String hash) {
length);
}
}

public void checkHexString(@NonNull String string) {
val m = hexString.matcher(string);
if (!m.matches()) {
throw new ValidationException(
HEX_STRING,
"Invalid hex string. Expected '%s', got '%s'",
hexString.pattern(),
string
);
}
}
}
48 changes: 40 additions & 8 deletions client/src/main/java/jp/co/soramitsu/iroha/java/IrohaAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import io.grpc.Channel;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.NettyChannelBuilder;
import io.reactivex.Observable;
import io.reactivex.exceptions.Exceptions;
import iroha.protocol.CommandService_v1Grpc;
Expand All @@ -20,6 +22,8 @@
import iroha.protocol.QueryService_v1Grpc.QueryService_v1Stub;
import iroha.protocol.TransactionOuterClass;
import java.io.Closeable;
import java.io.File;
import java.io.InputStream;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import jp.co.soramitsu.iroha.java.detail.StreamObserverToEmitter;
Expand Down Expand Up @@ -50,22 +54,50 @@ public class IrohaAPI implements Closeable {
private QueryService_v1Stub queryStreamingStub;

public IrohaAPI(URI uri) {
this(uri.getHost(), uri.getPort());
this(uri, null);
}

/**
* Constructor with secure connection over TLS
*
* @param uri - address to connect to Iroha
* @param certFile - certification filename for SSL/TLS connection
*/
public IrohaAPI(URI uri, String certFile) {
this(uri.getHost(), uri.getPort(), certFile);
}

@SneakyThrows
public IrohaAPI(String host, int port) {
this(
this(host, port, null);
}

/**
* Constructor with secure connection over TLS
*
* @param host - address to connect to Iroha
* @param port - port to connect to Iroha
* @param certFile - certificate filename for SSL/TLS connection
*/
@SneakyThrows
public IrohaAPI(String host, int port, String certFile) {
ManagedChannel channel = certFile == null ?
ManagedChannelBuilder
.forAddress(host, port)
.usePlaintext()
.build()
);
:
NettyChannelBuilder
.forAddress(host, port)
.sslContext(
GrpcSslContexts.forClient().trustManager(new File(certFile)).build())
.build();

setChannel(channel);

this.uri = new URI("grpc", null, host, port, null, null, null);
}

public IrohaAPI(ManagedChannel channel) {
private void setChannel(ManagedChannel channel) {
this.channel = channel;
this.setChannelForBlockingCmdStub(channel);
this.setChannelForBlockingQueryStub(channel);
Expand Down Expand Up @@ -104,7 +136,7 @@ public IrohaAPI setChannelForStreamingQueryStub(Channel channel) {

/**
* Send transaction synchronously, then subscribe for transaction status stream.
*
* <p>
* It uses {@link WaitForTerminalStatus} subscription strategy by default.
*
* @param tx protobuf transaction.
Expand All @@ -124,7 +156,7 @@ public Observable<ToriiResponse> transaction(TransactionOuterClass.Transaction t

/**
* Send transaction synchronously.
*
* <p>
* Blocking call.
*
* @param tx protobuf transaction.
Expand Down Expand Up @@ -155,7 +187,7 @@ public Observable<BlockQueryResponse> blocksQuery(Queries.BlocksQuery query) {

/**
* Synchronously send list of transactions.
*
* <p>
* Blocking call.
*/
public void transactionListSync(Iterable<TransactionOuterClass.Transaction> txList) {
Expand Down
37 changes: 36 additions & 1 deletion client/src/main/java/jp/co/soramitsu/iroha/java/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,43 @@
import java.time.Instant;
import java.util.Date;
import jp.co.soramitsu.crypto.ed25519.Ed25519Sha3.CryptoException;
import jp.co.soramitsu.iroha.java.crypto.Ed25519Sha3SignatureBuilder;
import jp.co.soramitsu.iroha.java.crypto.SignatureBuilder;
import jp.co.soramitsu.iroha.java.detail.Hashable;

public class Query
extends Hashable<Payload.Builder> {

private QueryPayloadMeta.Builder meta;
private SignatureBuilder signatureBuilder;
private Queries.Query.Builder q = Queries.Query.newBuilder();

public Query(QueryPayloadMeta.Builder meta) {
super(Payload.newBuilder());

this.meta = meta;
signatureBuilder = Ed25519Sha3SignatureBuilder.getInstance();
}

public Query(QueryPayloadMeta.Builder meta, SignatureBuilder signatureBuilder) {
super(Payload.newBuilder());

this.meta = meta;
this.signatureBuilder = signatureBuilder;
}

public Query(QueryOrBuilder queryBuilder) {
super(queryBuilder.getPayload().toBuilder());

this.meta = queryBuilder.getPayload().getMeta().toBuilder();
signatureBuilder = Ed25519Sha3SignatureBuilder.getInstance();
}

public Query(QueryOrBuilder queryBuilder, SignatureBuilder signatureBuilder) {
super(queryBuilder.getPayload().toBuilder());

this.meta = queryBuilder.getPayload().getMeta().toBuilder();
this.signatureBuilder = signatureBuilder;
}

private void updatePayload() {
Expand All @@ -35,7 +54,7 @@ private void updatePayload() {

public Queries.Query buildSigned(KeyPair keyPair) throws CryptoException {
updatePayload();
q.setSignature(Utils.sign(this, keyPair));
q.setSignature(signatureBuilder.sign(this, keyPair));
return q.build();
}

Expand All @@ -59,4 +78,20 @@ public static QueryBuilder builder(String accountId, Instant time, long counter)
public static QueryBuilder builder(String accountId, long counter) {
return new QueryBuilder(accountId, Instant.now(), counter);
}

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, Date time, long counter, SignatureBuilder signatureBuilder) {
return new QueryBuilder(accountId, time, counter, signatureBuilder);
}

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, long counter, SignatureBuilder signatureBuilder) {
return new QueryBuilder(accountId, Instant.now(), counter, signatureBuilder);
}
}
Loading

0 comments on commit a003266

Please sign in to comment.