fabric-samples/commercial-paper/contract/lib/utils.js
Anthony O'Dowd d77665186e FAB-11723 Developing Apps: Sample pt 1 -- contract
Change-Id: Ia61aae9b83c3297dfe28fd475c585e021186a4aa
Signed-off-by: Anthony O'Dowd <a_o-dowd@uk.ibm.com>
2018-09-05 07:41:50 +01:00

34 lines
806 B
JavaScript

/*
SPDX-License-Identifier: Apache-2.0
*/
'use strict';
/**
* Utility class for data, object mapulation, e.g. serialization
*/
class Utils {
/**
* Convert object to buffer containing JSON data serialization
* Typically used before putState() ledger API
* @param {Object} object object to serialize
* @return {buffer} buffer with the data to store
*/
static serialize(object){
return Buffer.from(JSON.stringify(object));
}
/**
* Deserialize object, i.e. Covert serialized data to JSON object
* Typically used after getState() ledger API
* @param {Object} data object to deserialize
* @return {json} json with the data to store
*/
static deserialize(data){
return JSON.parse(data);
}
}
module.exports = Utils;