mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-21 00:55:10 +00:00
Parse transaction creator to Identity in off_chain_data samples (#883)
Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com> Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
This commit is contained in:
parent
a6028cd398
commit
4109e741e4
3 changed files with 29 additions and 6 deletions
|
|
@ -7,8 +7,10 @@
|
||||||
package parser;
|
package parser;
|
||||||
|
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import org.hyperledger.fabric.client.identity.Identity;
|
||||||
import org.hyperledger.fabric.protos.common.ChannelHeader;
|
import org.hyperledger.fabric.protos.common.ChannelHeader;
|
||||||
import org.hyperledger.fabric.protos.common.Payload;
|
import org.hyperledger.fabric.protos.common.Payload;
|
||||||
|
import org.hyperledger.fabric.protos.msp.SerializedIdentity;
|
||||||
import org.hyperledger.fabric.protos.peer.TxValidationCode;
|
import org.hyperledger.fabric.protos.peer.TxValidationCode;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -30,8 +32,20 @@ final class ParsedTransaction implements Transaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] getCreator() throws InvalidProtocolBufferException {
|
public Identity getCreator() throws InvalidProtocolBufferException {
|
||||||
return payload.getSignatureHeader().getCreator().toByteArray();
|
var creator = SerializedIdentity.parseFrom(payload.getSignatureHeader().getCreator());
|
||||||
|
|
||||||
|
return new Identity() {
|
||||||
|
@Override
|
||||||
|
public String getMspId() {
|
||||||
|
return creator.getMspid();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] getCredentials() {
|
||||||
|
return creator.getIdBytes().toByteArray();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
package parser;
|
package parser;
|
||||||
|
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import org.hyperledger.fabric.client.identity.Identity;
|
||||||
import org.hyperledger.fabric.protos.common.ChannelHeader;
|
import org.hyperledger.fabric.protos.common.ChannelHeader;
|
||||||
import org.hyperledger.fabric.protos.common.Payload;
|
import org.hyperledger.fabric.protos.common.Payload;
|
||||||
import org.hyperledger.fabric.protos.peer.TxValidationCode;
|
import org.hyperledger.fabric.protos.peer.TxValidationCode;
|
||||||
|
|
@ -15,7 +16,7 @@ import java.util.List;
|
||||||
|
|
||||||
public interface Transaction {
|
public interface Transaction {
|
||||||
ChannelHeader getChannelHeader() throws InvalidProtocolBufferException;
|
ChannelHeader getChannelHeader() throws InvalidProtocolBufferException;
|
||||||
byte[] getCreator() throws InvalidProtocolBufferException;
|
Identity getCreator() throws InvalidProtocolBufferException;
|
||||||
TxValidationCode getValidationCode();
|
TxValidationCode getValidationCode();
|
||||||
boolean isValid();
|
boolean isValid();
|
||||||
List<NamespaceReadWriteSet> getNamespaceReadWriteSets() throws InvalidProtocolBufferException;
|
List<NamespaceReadWriteSet> getNamespaceReadWriteSets() throws InvalidProtocolBufferException;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { common, ledger, peer } from '@hyperledger/fabric-protos';
|
import { Identity } from '@hyperledger/fabric-gateway';
|
||||||
|
import { common, ledger, msp, peer } from '@hyperledger/fabric-protos';
|
||||||
import { assertDefined, cache } from './utils';
|
import { assertDefined, cache } from './utils';
|
||||||
|
|
||||||
export interface Block {
|
export interface Block {
|
||||||
|
|
@ -15,7 +16,7 @@ export interface Block {
|
||||||
|
|
||||||
export interface Transaction {
|
export interface Transaction {
|
||||||
getChannelHeader(): common.ChannelHeader;
|
getChannelHeader(): common.ChannelHeader;
|
||||||
getCreator(): Uint8Array;
|
getCreator(): Identity;
|
||||||
getValidationCode(): number;
|
getValidationCode(): number;
|
||||||
isValid(): boolean;
|
isValid(): boolean;
|
||||||
getNamespaceReadWriteSets(): NamespaceReadWriteSet[];
|
getNamespaceReadWriteSets(): NamespaceReadWriteSet[];
|
||||||
|
|
@ -106,7 +107,14 @@ function newTransaction(payload: Payload): Transaction {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getChannelHeader: () => payload.getChannelHeader(),
|
getChannelHeader: () => payload.getChannelHeader(),
|
||||||
getCreator: () => payload.getSignatureHeader().getCreator_asU8(),
|
getCreator: () => {
|
||||||
|
const creatorBytes = payload.getSignatureHeader().getCreator_asU8();
|
||||||
|
const creator = msp.SerializedIdentity.deserializeBinary(creatorBytes);
|
||||||
|
return {
|
||||||
|
mspId: creator.getMspid(),
|
||||||
|
credentials: creator.getIdBytes_asU8(),
|
||||||
|
};
|
||||||
|
},
|
||||||
getNamespaceReadWriteSets: () => transaction.getReadWriteSets()
|
getNamespaceReadWriteSets: () => transaction.getReadWriteSets()
|
||||||
.flatMap(readWriteSet => readWriteSet.getNamespaceReadWriteSets()),
|
.flatMap(readWriteSet => readWriteSet.getNamespaceReadWriteSets()),
|
||||||
getValidationCode: () => payload.getTransactionValidationCode(),
|
getValidationCode: () => payload.getTransactionValidationCode(),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue