Skip to content

Commit

Permalink
[FAB-4170] chaincodeInput deserializer
Browse files Browse the repository at this point in the history
Change-Id: Ic1e272efd5123948accefdd487e2f561ac0b01ae
Signed-off-by: liuwenliang0632@qq.com <liuwenliang0632@qq.com>
  • Loading branch information
liuwenliang0632 authored and cr22rc committed May 28, 2017
1 parent 033d05b commit 4f4767c
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/hyperledger/fabric/sdk/BlockInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,15 @@ public int getResponseStatus() {
public int getChaincodeInputArgsCount() {
if (getChaincodeInputArgsCount < 0) {
getChaincodeInputArgsCount = transactionAction.getPayload().getChaincodeProposalPayload().
getChaincodeInput().getChaincodeInput().getArgsCount();
getChaincodeInvocationSpec().getChaincodeInput().getChaincodeInput().getArgsCount();
}
return getChaincodeInputArgsCount;
}

public byte[] getChaincodeInputArgs(int index) {

ChaincodeInput input = transactionAction.getPayload().getChaincodeProposalPayload().
getChaincodeInput().getChaincodeInput();
getChaincodeInvocationSpec().getChaincodeInput().getChaincodeInput();

return input.getArgs(index).toByteArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ class ChaincodeInputDeserializer {
private final ByteString byteString;
private WeakReference<ChaincodeInput> chaincodeInput;

ChaincodeInputDeserializer(ByteString byteString) {
this.byteString = byteString;
ChaincodeInputDeserializer(ChaincodeInput chaincodeInput) {
this.byteString = chaincodeInput.toByteString();
this.chaincodeInput = new WeakReference<>(chaincodeInput);
}

ChaincodeInput getChaincodeInput() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
*
* Copyright 2016,2017 DTCC, Fujitsu Australia Software Technology, IBM - All Rights Reserved.
*
* 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 org.hyperledger.fabric.sdk;

import java.lang.ref.WeakReference;

import org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeInvocationSpec;
import org.hyperledger.fabric.sdk.exception.InvalidProtocolBufferRuntimeException;

import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;

class ChaincodeInvocationSpecDeserializer {
private final ByteString byteString;
private WeakReference<ChaincodeInvocationSpec> invocationSpec;
private WeakReference<ChaincodeInputDeserializer> chaincodeInputDeserializer;

ChaincodeInvocationSpecDeserializer(ByteString byteString) {
this.byteString = byteString;
}

ChaincodeInvocationSpec getChaincodeInvocationSpec() {
ChaincodeInvocationSpec ret = null;

if (invocationSpec != null) {
ret = invocationSpec.get();

}
if (ret == null) {

try {
ret = ChaincodeInvocationSpec.parseFrom(byteString);
} catch (InvalidProtocolBufferException e) {
throw new InvalidProtocolBufferRuntimeException(e);
}

invocationSpec = new WeakReference<>(ret);

}

return ret;

}
ChaincodeInputDeserializer getChaincodeInput() {
ChaincodeInputDeserializer ret = null;

if (chaincodeInputDeserializer != null) {
ret = chaincodeInputDeserializer.get();

}
if (ret == null) {

ret = new ChaincodeInputDeserializer(getChaincodeInvocationSpec().getChaincodeSpec().getInput());

chaincodeInputDeserializer = new WeakReference<>(ret);

}

return ret;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class ChaincodeProposalPayloadDeserializer {
private final ByteString byteString;
private WeakReference<ChaincodeProposalPayload> chaincodeProposalPayload;
private WeakReference<ChaincodeInputDeserializer> chaincodeInputDeserialize;
private WeakReference<ChaincodeInvocationSpecDeserializer> invocationSpecDeserializer;

ChaincodeProposalPayloadDeserializer(ByteString byteString) {
this.byteString = byteString;
Expand Down Expand Up @@ -56,18 +56,18 @@ ChaincodeProposalPayload getChaincodeProposalPayload() {

}

ChaincodeInputDeserializer getChaincodeInput() {
ChaincodeInputDeserializer ret = null;
ChaincodeInvocationSpecDeserializer getChaincodeInvocationSpec() {
ChaincodeInvocationSpecDeserializer ret = null;

if (chaincodeInputDeserialize != null) {
ret = chaincodeInputDeserialize.get();
if (invocationSpecDeserializer != null) {
ret = invocationSpecDeserializer.get();

}
if (ret == null) {

ret = new ChaincodeInputDeserializer(getChaincodeProposalPayload().getInput());
ret = new ChaincodeInvocationSpecDeserializer(getChaincodeProposalPayload().getInput());

chaincodeInputDeserialize = new WeakReference<>(ret);
invocationSpecDeserializer = new WeakReference<>(ret);

}

Expand Down

0 comments on commit 4f4767c

Please sign in to comment.