Documentation ¶
Overview ¶
Package history handles transaction history logging.
Index ¶
- func GenerateExportableTransactionLog(stub cached_stub.CachedStubInterface, caller data_model.User, ...) (data_model.ExportableTransactionLog, error)
- func GetHistoryManager(assetManager asset_manager.AssetManager) history_manager.HistoryManager
- func Init(stub cached_stub.CachedStubInterface, logLevel ...shim.LoggingLevel) ([]byte, error)
- func PutQueryTransactionLog(stub cached_stub.CachedStubInterface, caller data_model.User, args []string) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateExportableTransactionLog ¶
func GenerateExportableTransactionLog(stub cached_stub.CachedStubInterface, caller data_model.User, log data_model.TransactionLog, encryptionKey data_model.Key) (data_model.ExportableTransactionLog, error)
GenerateExportableTransactionLog returns an exportable transaction log. It is meant to be called in a query context. The ExportableTransactionLog this function returns should be returned from the query and then passed back into the chaincode using the function history.PutQueryTransactionLog.
Example ¶
mstub := test_utils.CreateExampleMockStub() stub := cached_stub.NewCachedStub(mstub) caller := test_utils.CreateTestUser("caller") txTimestamp, _ := stub.GetTxTimestamp() transactionLog := data_model.TransactionLog{ TransactionID: stub.GetTxID(), Namespace: "namespace", FunctionName: "function_name", CallerID: "caller", Timestamp: txTimestamp.GetSeconds(), Data: "any arbitrary data object", Field1: "abc", } mstub.MockTransactionStart(transactionLog.TransactionID) stub = cached_stub.NewCachedStub(mstub) GenerateExportableTransactionLog(stub, caller, transactionLog, caller.GetSymKey()) mstub.MockTransactionEnd(transactionLog.TransactionID)
Output:
func GetHistoryManager ¶
func GetHistoryManager(assetManager asset_manager.AssetManager) history_manager.HistoryManager
GetHistoryManager constructs and returns a HistoryManagerImpl instance.
Example ¶
stub := cached_stub.NewCachedStub(test_utils.CreateExampleMockStub()) caller := test_utils.CreateTestUser("caller1") assetManager := asset_mgmt_i.GetAssetManager(stub, caller) GetHistoryManager(assetManager)
Output:
func Init ¶
func Init(stub cached_stub.CachedStubInterface, logLevel ...shim.LoggingLevel) ([]byte, error)
------------------------------------------------------ ---------------------- INIT FUNCTIONS ---------------- ------------------------------------------------------ Init sets up the history package by building the history index table.
func PutQueryTransactionLog ¶
func PutQueryTransactionLog(stub cached_stub.CachedStubInterface, caller data_model.User, args []string) error
PutQueryTransactionLog stores a log for a query transaction, encrypted with the provided encryptionKey. To log a query, first call history.GenerateExportableTransactionLog during the query to get an exportableTransactionLog. Then return the exportableTransactionLog from the query. Finally, create a separate transaction to invoke this function and pass in the exportableTransactionLog.
args = [exportableTransactionLog]
Example ¶
mstub := test_utils.CreateExampleMockStub() stub := cached_stub.NewCachedStub(mstub) caller := test_utils.CreateTestUser("caller") txTimestamp, _ := stub.GetTxTimestamp() transactionLog := data_model.TransactionLog{ TransactionID: stub.GetTxID(), Namespace: "namespace", FunctionName: "function_name", CallerID: "caller", Timestamp: txTimestamp.GetSeconds(), Data: "any arbitrary data object", Field1: "abc", } mstub.MockTransactionStart(transactionLog.TransactionID) stub = cached_stub.NewCachedStub(mstub) exportableLog, _ := GenerateExportableTransactionLog(stub, caller, transactionLog, caller.GetSymKey()) mstub.MockTransactionEnd(transactionLog.TransactionID) mstub.MockTransactionStart("different-tx") stub = cached_stub.NewCachedStub(mstub) exportableLogBytes, _ := json.Marshal(&exportableLog) PutQueryTransactionLog(stub, caller, []string{string(exportableLogBytes)}) mstub.MockTransactionEnd("different-tx")
Output:
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
Package history_manager is an interface for high-level history management functions.
|
Package history_manager is an interface for high-level history management functions. |