Skip to content

Commit

Permalink
FAB-8861 Missing Blockinfo information
Browse files Browse the repository at this point in the history
Change-Id: I700836c24260f88f444330209fa02ce9222064ab
Signed-off-by: rickr <cr22rc@gmail.com>
  • Loading branch information
cr22rc committed Mar 14, 2018
1 parent 03c428e commit ff4b881
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 14 deletions.
12 changes: 12 additions & 0 deletions src/main/java/org/hyperledger/fabric/sdk/BlockEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ public class TransactionEvent extends TransactionEnvelopeInfo {
super(filteredTransaction);
}

/**
* The BlockEvent for this TransactionEvent.
*
* @return BlockEvent for this transaction.
*/

public BlockEvent getBlockEvent() {

return BlockEvent.this;

}

/**
* The event hub that received this event.
*
Expand Down
115 changes: 104 additions & 11 deletions src/main/java/org/hyperledger/fabric/sdk/BlockInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.hyperledger.fabric.protos.common.Common;
import org.hyperledger.fabric.protos.common.Common.Block;
import org.hyperledger.fabric.protos.ledger.rwset.Rwset.TxReadWriteSet;
import org.hyperledger.fabric.protos.msp.Identities;
import org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeInput;
import org.hyperledger.fabric.protos.peer.FabricTransaction;
import org.hyperledger.fabric.protos.peer.PeerEvents;
Expand All @@ -46,16 +47,6 @@ public class BlockInfo {
this.block = new BlockDeserializer(block);
}

// BlockInfo(PeerEvents.Event event) {
// if (event.getEventCase() == PeerEvents.Event.EventCase.FILTERED_BLOCK) {
// block = null;
// filteredBlock = event.getFilteredBlock();
// } else {
// this.block = new BlockDeserializer(event.getBlock());
// filteredBlock = null;
// }
// }

BlockInfo(PeerEvents.DeliverResponse resp) {

final PeerEvents.DeliverResponse.TypeCase type = resp.getTypeCase();
Expand Down Expand Up @@ -149,11 +140,20 @@ public int getEnvelopeCount() {
return isFiltered() ? filteredBlock.getFilteredTransactionsCount() : block.getData().getDataCount();
}

/**
* Wrappers Envelope
*/

public class EnvelopeInfo {
private final EnvelopeDeserializer envelopeDeserializer;
private final HeaderDeserializer headerDeserializer;
protected final FilteredTransaction filteredTx;

/**
* This block is filtered
*
* @return true if it's filtered.
*/
boolean isFiltered() {
return filteredTx != null;

Expand All @@ -167,18 +167,79 @@ boolean isFiltered() {
filteredTx = null;
}

public EnvelopeInfo(FilteredTransaction filteredTx) {
EnvelopeInfo(FilteredTransaction filteredTx) {
this.filteredTx = filteredTx;
envelopeDeserializer = null;
headerDeserializer = null;

}

/**
* Get channel id
*
* @return The channel id also referred to as channel name.
*/
public String getChannelId() {

return BlockInfo.this.isFiltered() ? filteredBlock.getChannelId() : headerDeserializer.getChannelHeader().getChannelId();
}

public class IdentitiesInfo {
final String mspid;
final String id;

/**
* The identification of the identity usually the certificate.
*
* @return The certificate of the user in PEM format.
*/
public String getId() {
return id;
}

/**
* The MSPId of the user.
*
* @return The MSPid of the user.
*/
public String getMspid() {
return mspid;
}

IdentitiesInfo(Identities.SerializedIdentity identity) {
mspid = identity.getMspid();
id = identity.getIdBytes().toStringUtf8();

}

}

/**
* This is the creator or submitter of the transaction.
* Returns null for a filtered block.
*
* @return {@link IdentitiesInfo}
*/
public IdentitiesInfo getCreator() {
return isFiltered() ? null : new IdentitiesInfo(headerDeserializer.getCreator());

}

/**
* The nonce of the transaction.
*
* @return return null for filtered block.
*/
public byte[] getNonce() {
return isFiltered() ? null : headerDeserializer.getNonce();

}

/**
* The transaction ID
*
* @return the transaction id.
*/
public String getTransactionID() {

return BlockInfo.this.isFiltered() ? filteredTx.getTxid() : headerDeserializer.getChannelHeader().getTxId();
Expand Down Expand Up @@ -317,6 +378,16 @@ public class TransactionEnvelopeInfo extends EnvelopeInfo {
this.transactionDeserializer = null;
}

/**
* Signature for the transaction.
*
* @return byte array that as the signature.
*/
public byte[] getSignature() {

return transactionDeserializer.getSignature();
}

TransactionEnvelopeInfo(EndorserTransactionEnvDeserializer transactionDeserializer) {
super(transactionDeserializer);

Expand Down Expand Up @@ -600,10 +671,32 @@ public byte[] getSignature() {
return endorsement.getSignature().toByteArray();
}

/**
* @return
* @deprecated use getId and getMspid
*/
public byte[] getEndorser() {
return endorsement.getEndorser().toByteArray();
}

public String getId() {

try {
return Identities.SerializedIdentity.parseFrom(endorsement.getEndorser()).getIdBytes().toStringUtf8();
} catch (InvalidProtocolBufferException e) {
throw new InvalidProtocolBufferRuntimeException(e);
}

}

public String getMspid() {
try {
return Identities.SerializedIdentity.parseFrom(endorsement.getEndorser()).getMspid();
} catch (InvalidProtocolBufferException e) {
throw new InvalidProtocolBufferRuntimeException(e);
}
}

}

public enum EnvelopeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ Envelope getEnvelope() {

}

//Todo ret.getSignature();

return ret;

}

byte[] getSignature() {

return getEnvelope().getSignature().toByteArray();

}

PayloadDeserializer getPayload() {

PayloadDeserializer ret = null;
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/org/hyperledger/fabric/sdk/HeaderDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@

import java.lang.ref.WeakReference;

import com.google.protobuf.InvalidProtocolBufferException;
import org.hyperledger.fabric.protos.common.Common;
import org.hyperledger.fabric.protos.common.Common.Header;
import org.hyperledger.fabric.protos.msp.Identities;
import org.hyperledger.fabric.sdk.exception.InvalidProtocolBufferRuntimeException;

class HeaderDeserializer {

Expand Down Expand Up @@ -53,4 +57,25 @@ ChannelHeaderDeserializer getChannelHeader() {

}

Identities.SerializedIdentity getCreator() {

try {
Common.SignatureHeader signatureHeader1 = Common.SignatureHeader.parseFrom(header.getSignatureHeader());
return Identities.SerializedIdentity.parseFrom(signatureHeader1.getCreator());
} catch (InvalidProtocolBufferException e) {
throw new InvalidProtocolBufferRuntimeException(e);
}

}

byte[] getNonce() {

try {
Common.SignatureHeader signatureHeader1 = Common.SignatureHeader.parseFrom(header.getSignatureHeader());
return signatureHeader1.getNonce().toByteArray();
} catch (InvalidProtocolBufferException e) {
throw new InvalidProtocolBufferRuntimeException(e);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,14 @@ policy OR(Org1MSP.member, Org2MSP.member) meaning 1 signature from someone in ei
waitOnFabric(0);

assertTrue(transactionEvent.isValid()); // must be valid to be here.
assertNotNull(transactionEvent.getSignature()); //musth have a signature.
BlockEvent blockEvent = transactionEvent.getBlockEvent(); // This is the blockevent that has this transaction.
assertNotNull(blockEvent.getBlock()); // Make sure the RAW Fabric block is returned.

out("Finished instantiate transaction with transaction id %s", transactionEvent.getTransactionID());

try {
assertEquals(blockEvent.getChannelId(), channel.getName());
successful.clear();
failed.clear();

Expand Down Expand Up @@ -900,6 +905,8 @@ void blockWalker(HFClient client, Channel channel) throws InvalidArgumentExcepti
out(" Transaction number %d has epoch: %d", i, envelopeInfo.getEpoch());
out(" Transaction number %d has transaction timestamp: %tB %<te, %<tY %<tT %<Tp", i, envelopeInfo.getTimestamp());
out(" Transaction number %d has type id: %s", i, "" + envelopeInfo.getType());
out(" Transaction number %d has nonce : %s", i, "" + Hex.encodeHexString(envelopeInfo.getNonce()));
out(" Transaction number %d has submitter mspid: %s, certificate: %s", i, envelopeInfo.getCreator().getMspid(), envelopeInfo.getCreator().getId());

if (envelopeInfo.getType() == TRANSACTION_ENVELOPE) {
BlockInfo.TransactionEnvelopeInfo transactionEnvelopeInfo = (BlockInfo.TransactionEnvelopeInfo) envelopeInfo;
Expand All @@ -924,7 +931,7 @@ void blockWalker(HFClient client, Channel channel) throws InvalidArgumentExcepti
for (int n = 0; n < transactionActionInfo.getEndorsementsCount(); ++n) {
BlockInfo.EndorserInfo endorserInfo = transactionActionInfo.getEndorsementInfo(n);
out("Endorser %d signature: %s", n, Hex.encodeHexString(endorserInfo.getSignature()));
out("Endorser %d endorser: %s", n, new String(endorserInfo.getEndorser(), "UTF-8"));
out("Endorser %d endorser: mspid %s \n certificate %s", n, endorserInfo.getMspid(), endorserInfo.getId());
}
out(" Transaction action %d has %d chaincode input arguments", j, transactionActionInfo.getChaincodeInputArgsCount());
for (int z = 0; z < transactionActionInfo.getChaincodeInputArgsCount(); ++z) {
Expand Down

0 comments on commit ff4b881

Please sign in to comment.