Skip to content

Commit

Permalink
FAB-6245 Return of BlockInfo.getTransactionActionInfos
Browse files Browse the repository at this point in the history
Change-Id: Id3db51876015867dab62a18d80e9e1b4612d5c4f
Signed-off-by: rickr <cr22rc@gmail.com>
  • Loading branch information
cr22rc committed Oct 5, 2017
1 parent 85ba053 commit 38e0d38
Showing 1 changed file with 23 additions and 47 deletions.
70 changes: 23 additions & 47 deletions src/main/java/org/hyperledger/fabric/sdk/BlockInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,31 +90,6 @@ public int getEnvelopeCount() {
return block.getData().getDataCount();
}

// /**
// * Get transaction info on a specific transaction.
// *
// * @param index index into the block.
// * @return Transaction Info
// * @throws InvalidProtocolBufferException
// */

// public TransactionEnvelopeInfo getEnvelopeInfo(int index) throws InvalidProtocolBufferException {
//
// try {
// // block.getData(0).getEnvelope().getSignature();
//
// EnvelopeDeserializer.newInstance(block.getBlock().getData().getData(index));
//
// final PayloadDeserializer payload = block.getData(index).getPayload();
//
// return new TransactionEnvelopeInfo(null, payload.getHeader());
// } catch (InvalidProtocolBufferRuntimeException e) {
// throw (InvalidProtocolBufferException) e.getCause();
// }
//
// }
//

public class EnvelopeInfo {
private final EnvelopeDeserializer envelopeDeserializer;
HeaderDeserializer headerDeserializer;
Expand Down Expand Up @@ -175,21 +150,28 @@ public EnvelopeType getType() {

}

public EnvelopeInfo getEnvelopeInfo(int blockIndex) throws InvalidProtocolBufferException {
/**
* Return a specific envelope in the block by it's index.
*
* @param envelopeIndex
* @return EnvelopeInfo that contains information on the envelope.
* @throws InvalidProtocolBufferException
*/

public EnvelopeInfo getEnvelopeInfo(int envelopeIndex) throws InvalidProtocolBufferException {

try {
// block.getData(0).getEnvelope().getSignature();

EnvelopeInfo ret;

EnvelopeDeserializer ed = EnvelopeDeserializer.newInstance(block.getBlock().getData().getData(blockIndex), block.getTransActionsMetaData()[blockIndex]);
EnvelopeDeserializer ed = EnvelopeDeserializer.newInstance(block.getBlock().getData().getData(envelopeIndex), block.getTransActionsMetaData()[envelopeIndex]);

switch (ed.getType()) {
case 3:
ret = new TransactionEnvelopeInfo((EndorserTransactionEnvDeserializer) ed, blockIndex);
ret = new TransactionEnvelopeInfo((EndorserTransactionEnvDeserializer) ed, envelopeIndex);
break;
default: //just assume base properties.
ret = new EnvelopeInfo(ed, blockIndex);
ret = new EnvelopeInfo(ed, envelopeIndex);
break;

}
Expand All @@ -201,9 +183,15 @@ public EnvelopeInfo getEnvelopeInfo(int blockIndex) throws InvalidProtocolBuffer

}

/**
* Return and iterable EnvelopeInfo over each Envelope contained in the Block
*
* @return
*/

public Iterable<EnvelopeInfo> getEnvelopeInfos() {

return new TransactionInfoIterable();
return new EnvelopeInfoIterable();
}

public class TransactionEnvelopeInfo extends EnvelopeInfo {
Expand Down Expand Up @@ -392,23 +380,11 @@ public Iterator<TransactionActionInfo> iterator() {

}

/**
* Iterable interface over transaction info in the block.
*
* @return iterator
*/

public Iterable<EnvelopeInfo> getTransactionActionInfos() {

return new TransactionInfoIterable();

}

class TransactionInfoIterator implements Iterator<EnvelopeInfo> {
class EnvelopeInfoIterator implements Iterator<EnvelopeInfo> {
int ci = 0;
final int max;

TransactionInfoIterator() {
EnvelopeInfoIterator() {
max = block.getData().getDataCount();

}
Expand All @@ -431,11 +407,11 @@ public EnvelopeInfo next() {
}
}

class TransactionInfoIterable implements Iterable<EnvelopeInfo> {
class EnvelopeInfoIterable implements Iterable<EnvelopeInfo> {

@Override
public Iterator<EnvelopeInfo> iterator() {
return new TransactionInfoIterator();
return new EnvelopeInfoIterator();
}
}

Expand Down

0 comments on commit 38e0d38

Please sign in to comment.