
org.hyperledger.fabric.contract.Context Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fabric-chaincode-shim Show documentation
Show all versions of fabric-chaincode-shim Show documentation
Hyperledger Fabric Java Chaincode Shim
The newest version!
/*
* Copyright 2019 IBM DTCC All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.fabric.contract;
import java.io.IOException;
import java.security.cert.CertificateException;
import org.hyperledger.fabric.shim.ChaincodeStub;
import org.json.JSONException;
/**
* This context is available to all 'transaction functions' and provides the transaction context. It also provides
* access to the APIs for the world state using {@link #getStub()}
*
* Applications can implement their own versions if they wish to add functionality. All subclasses MUST implement a
* constructor, for example
*
*
{@code
* public MyContext extends Context {
*
* public MyContext(ChaincodeStub stub) {
* super(stub);
* }
* }
*
* }
*/
public class Context {
/** */
protected ChaincodeStub stub;
/** */
protected ClientIdentity clientIdentity;
/**
* Creates new client identity and sets it as a property of the stub.
*
* @param stub Instance of the {@link ChaincodeStub} to use
*/
public Context(final ChaincodeStub stub) {
this.stub = stub;
try {
this.clientIdentity = new ClientIdentity(stub);
} catch (CertificateException | JSONException | IOException e) {
throw new ContractRuntimeException("Could not create new client identity", e);
}
}
/** @return ChaincodeStub instance to use */
public ChaincodeStub getStub() {
return this.stub;
}
/** @return ClientIdentity object to use */
public ClientIdentity getClientIdentity() {
return this.clientIdentity;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy