Loading src/dlt/gateway/src/main/kotlin/Main.kt +6 −1 Original line number Diff line number Diff line Loading @@ -118,7 +118,12 @@ fun main() = runBlocking { val data = DltGateway.DltRecord.newBuilder() .setRecordId(id) .setOperation(DltGateway.DltRecordOperationEnum.DLTRECORDOPERATION_ADD) .setDataJson("{}") .setDataJson("\"{\"device_config\": {\"config_rules\": []}, \"device_drivers\": []," + "\"device_endpoints\": [], \"device_id\": {\"device_uuid\": {\"uuid\": \"dev-12345\"}}," + "\"device_operational_status\": \"DEVICEOPERATIONALSTATUS_ENABLED\"," + "\"device_type\": \"packet-router\"}\", \"operation\": \"DLTRECORDOPERATION_ADD\"," + "\"record_id\": {\"domain_uuid\": {\"uuid\": \"tfs-a\"}, \"record_uuid\": {\"uuid\": \"dev-12345\"}," + "\"type\": \"DLTRECORDTYPE_DEVICE\"}") .build() println("sending new record") Loading src/dlt/gateway/src/main/kotlin/fabric/FabricConnector.kt +9 −8 Original line number Diff line number Diff line Loading @@ -60,6 +60,9 @@ class FabricConnector(val config: Config.DltConfig) { private val channels: MutableList<Channel<DltRecordEvent>> = mutableListOf() private val encoder: Base64.Encoder = Base64.getEncoder() private val decoder: Base64.Decoder = Base64.getDecoder() init { // Create a CA client for interacting with the CA. val props = Properties() Loading @@ -80,7 +83,7 @@ class FabricConnector(val config: Config.DltConfig) { val consumer = Consumer { event: ContractEvent? -> run { println("new event detected") val record = DltRecord.parseFrom(event?.payload?.get()) val record = DltRecord.parseFrom(decoder.decode(event?.payload?.get())) println(record.recordId.recordUuid) val eventType: ContextOuterClass.EventTypeEnum = when (event?.name) { "Add" -> ContextOuterClass.EventTypeEnum.EVENTTYPE_CREATE Loading Loading @@ -118,13 +121,12 @@ class FabricConnector(val config: Config.DltConfig) { fun putData(record: DltRecord): String { println(record.toString()) println("Put: ${record.toByteArray().decodeToString().length}") try { contract.submitTransaction( "AddRecord", record.recordId.recordUuid.uuid, record.toByteArray().decodeToString() encoder.encodeToString(record.toByteArray()) ) } catch (e: Exception) { println(e.toString()) Loading @@ -134,13 +136,12 @@ class FabricConnector(val config: Config.DltConfig) { } fun getData(uuid: String): DltRecord { try { return try { val result = contract.evaluateTransaction("GetRecord", uuid) println("Get: ${result.size}") return DltRecord.parseFrom(result) DltRecord.parseFrom(decoder.decode(result)) } catch (e: Exception) { println(e.toString()) return DltRecord.getDefaultInstance() DltRecord.getDefaultInstance() } } Loading @@ -149,7 +150,7 @@ class FabricConnector(val config: Config.DltConfig) { contract.submitTransaction( "UpdateRecord", record.recordId.recordUuid.uuid, record.toByteArray().decodeToString() encoder.encodeToString(record.toByteArray()) ) } catch (e: Exception) { return e.toString() Loading Loading
src/dlt/gateway/src/main/kotlin/Main.kt +6 −1 Original line number Diff line number Diff line Loading @@ -118,7 +118,12 @@ fun main() = runBlocking { val data = DltGateway.DltRecord.newBuilder() .setRecordId(id) .setOperation(DltGateway.DltRecordOperationEnum.DLTRECORDOPERATION_ADD) .setDataJson("{}") .setDataJson("\"{\"device_config\": {\"config_rules\": []}, \"device_drivers\": []," + "\"device_endpoints\": [], \"device_id\": {\"device_uuid\": {\"uuid\": \"dev-12345\"}}," + "\"device_operational_status\": \"DEVICEOPERATIONALSTATUS_ENABLED\"," + "\"device_type\": \"packet-router\"}\", \"operation\": \"DLTRECORDOPERATION_ADD\"," + "\"record_id\": {\"domain_uuid\": {\"uuid\": \"tfs-a\"}, \"record_uuid\": {\"uuid\": \"dev-12345\"}," + "\"type\": \"DLTRECORDTYPE_DEVICE\"}") .build() println("sending new record") Loading
src/dlt/gateway/src/main/kotlin/fabric/FabricConnector.kt +9 −8 Original line number Diff line number Diff line Loading @@ -60,6 +60,9 @@ class FabricConnector(val config: Config.DltConfig) { private val channels: MutableList<Channel<DltRecordEvent>> = mutableListOf() private val encoder: Base64.Encoder = Base64.getEncoder() private val decoder: Base64.Decoder = Base64.getDecoder() init { // Create a CA client for interacting with the CA. val props = Properties() Loading @@ -80,7 +83,7 @@ class FabricConnector(val config: Config.DltConfig) { val consumer = Consumer { event: ContractEvent? -> run { println("new event detected") val record = DltRecord.parseFrom(event?.payload?.get()) val record = DltRecord.parseFrom(decoder.decode(event?.payload?.get())) println(record.recordId.recordUuid) val eventType: ContextOuterClass.EventTypeEnum = when (event?.name) { "Add" -> ContextOuterClass.EventTypeEnum.EVENTTYPE_CREATE Loading Loading @@ -118,13 +121,12 @@ class FabricConnector(val config: Config.DltConfig) { fun putData(record: DltRecord): String { println(record.toString()) println("Put: ${record.toByteArray().decodeToString().length}") try { contract.submitTransaction( "AddRecord", record.recordId.recordUuid.uuid, record.toByteArray().decodeToString() encoder.encodeToString(record.toByteArray()) ) } catch (e: Exception) { println(e.toString()) Loading @@ -134,13 +136,12 @@ class FabricConnector(val config: Config.DltConfig) { } fun getData(uuid: String): DltRecord { try { return try { val result = contract.evaluateTransaction("GetRecord", uuid) println("Get: ${result.size}") return DltRecord.parseFrom(result) DltRecord.parseFrom(decoder.decode(result)) } catch (e: Exception) { println(e.toString()) return DltRecord.getDefaultInstance() DltRecord.getDefaultInstance() } } Loading @@ -149,7 +150,7 @@ class FabricConnector(val config: Config.DltConfig) { contract.submitTransaction( "UpdateRecord", record.recordId.recordUuid.uuid, record.toByteArray().decodeToString() encoder.encodeToString(record.toByteArray()) ) } catch (e: Exception) { return e.toString() Loading