-
Notifications
You must be signed in to change notification settings - Fork 30
[ECR-2914] LC: Implemented get transaction endpoint support #725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5f605bd
move tx classes
bullet-tooth f2ab026
created tx message serializer
bullet-tooth 5dfcab0
implemented get tx endpoint
bullet-tooth 4803bf0
rm redundant dependency
bullet-tooth 8d87e4d
PR comments fix
bullet-tooth 115cf81
Merge branch 'master' into ecr-2914-2
bullet-tooth f349175
PR comments fix
bullet-tooth 083c769
PR comments fix
bullet-tooth 4e8a354
added panic status
bullet-tooth 152f989
mackage name refactoring
bullet-tooth a131385
optimize imports
bullet-tooth 8ccc715
Merge branch 'master' into ecr-2914-2
bullet-tooth 06dd091
fix PR comments
bullet-tooth a657e81
Merge branch 'master' into ecr-2914-2
dmitry-timofeev d1ad7d1
fix PR comments
bullet-tooth 5c2ed59
changelog update
bullet-tooth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...n/java/com/exonum/binding/common/serialization/json/TransactionMessageJsonSerializer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2019 The Exonum Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.exonum.binding.common.serialization.json; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
import com.exonum.binding.common.message.TransactionMessage; | ||
import com.google.common.io.BaseEncoding; | ||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonParseException; | ||
import com.google.gson.JsonPrimitive; | ||
import com.google.gson.JsonSerializationContext; | ||
import com.google.gson.JsonSerializer; | ||
import java.lang.reflect.Type; | ||
|
||
final class TransactionMessageJsonSerializer implements JsonSerializer<TransactionMessage>, | ||
JsonDeserializer<TransactionMessage> { | ||
private static final BaseEncoding HEX_ENCODER = BaseEncoding.base16().lowerCase(); | ||
|
||
@Override | ||
public JsonElement serialize(TransactionMessage src, Type typeOfSrc, | ||
JsonSerializationContext context) { | ||
checkNotNull(src, "Transaction message value is null"); | ||
byte[] bytes = src.toBytes(); | ||
String hex = HEX_ENCODER.encode(bytes); | ||
|
||
return new JsonPrimitive(hex); | ||
} | ||
|
||
@Override | ||
public TransactionMessage deserialize(JsonElement json, Type typeOfT, | ||
JsonDeserializationContext context) throws JsonParseException { | ||
checkNotNull(json, "Transaction message json input is null"); | ||
String hex = json.getAsString(); | ||
byte[] bytes = HEX_ENCODER.decode(hex); | ||
|
||
return TransactionMessage.fromBytes(bytes); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,13 +19,15 @@ | |
|
||
import static com.exonum.binding.common.serialization.json.JsonSerializer.json; | ||
import static com.exonum.binding.test.Bytes.bytes; | ||
import static com.exonum.binding.test.Bytes.fromHex; | ||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.isJson; | ||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.withJsonPath; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
import com.exonum.binding.common.crypto.PublicKey; | ||
import com.exonum.binding.common.hash.HashCode; | ||
import com.exonum.binding.common.message.TransactionMessage; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class JsonSerializerTest { | ||
|
@@ -57,6 +59,18 @@ void hashCodeSerializesAsValue() { | |
assertJsonValue(json, "000102"); | ||
} | ||
|
||
@Test | ||
void transactionMessageSerializesAsValue() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There is one below. |
||
String hex = "87095f09d413633626a4a5b903d7e8dbb7a9f54baa92eb77965c5ad0417d8d65000" | ||
+ "000007f0000010292a0d0ed9368a70984098519cef6bde555e85eaf8105c561a6c0b9599fae" | ||
+ "f4eb7b02155160f0c2598c97c42bc294599a2be34ce9ce66ba7baa11bfdaf06e5e0c"; | ||
TransactionMessage value = TransactionMessage.fromBytes(fromHex(hex)); | ||
|
||
String json = json().toJson(new Wrapper<>(value)); | ||
|
||
assertJsonValue(json, hex); | ||
} | ||
|
||
private static void assertJsonValue(String json, Object expectedValue) { | ||
assertThat(json, isJson(withJsonPath("$.value", equalTo(expectedValue)))); | ||
} | ||
|
72 changes: 72 additions & 0 deletions
72
...va/com/exonum/binding/common/serialization/json/TransactionMessageGsonSerializerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2019 The Exonum Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.exonum.binding.common.serialization.json; | ||
|
||
import static com.exonum.binding.common.crypto.CryptoFunctions.ed25519; | ||
import static com.exonum.binding.common.serialization.json.JsonSerializer.json; | ||
import static com.exonum.binding.test.Bytes.bytes; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import com.exonum.binding.common.crypto.KeyPair; | ||
import com.exonum.binding.common.message.TransactionMessage; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.gson.Gson; | ||
import java.util.List; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
class TransactionMessageGsonSerializerTest { | ||
|
||
private static Gson gson; | ||
|
||
@BeforeAll | ||
static void setup() { | ||
gson = JsonSerializer.builder() | ||
.registerTypeHierarchyAdapter(TransactionMessage.class, | ||
new TransactionMessageJsonSerializer()) | ||
.create(); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("source") | ||
void roundTripTest(TransactionMessage msg) { | ||
String json = gson.toJson(msg); | ||
TransactionMessage restoredMsg = json().fromJson(json, TransactionMessage.class); | ||
|
||
assertThat(restoredMsg, is(msg)); | ||
} | ||
|
||
private static List<TransactionMessage> source() { | ||
KeyPair keys = ed25519().generateKeyPair(); | ||
|
||
return ImmutableList.of( | ||
TransactionMessage.builder() | ||
.serviceId(Short.MIN_VALUE) | ||
.transactionId(Short.MAX_VALUE) | ||
.payload(bytes()) | ||
.sign(keys, ed25519()), | ||
TransactionMessage.builder() | ||
.serviceId((short) 0) | ||
.transactionId((short) 127) | ||
.payload(bytes(0x00, 0x01, 0x02)) | ||
.sign(keys, ed25519()) | ||
); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any needs for
TransactionMessage
serialization to JSON in other ways?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't say 🤷♂️ @vitvakatu , @MakarovS ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd leave it as it is for now.