fabric-samples/off_chain_data/application-java/app/src/main/java/Write.java
Mark S. Lewis f8e7bfe803
Update Gateway samples for v1.1 release (#779)
- Updated build to use Go 1.18 since Go 1.16 is no longer supported.
- Use Java 11 in updated samples, and take advantage of new language features.

Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
2022-06-30 15:46:32 +01:00

68 lines
1.8 KiB
Java

/*
* Copyright IBM Corp. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
import org.hyperledger.fabric.protos.ledger.rwset.kvrwset.KVWrite;
import java.nio.charset.StandardCharsets;
/**
* Description of a ledger write that can be applied to an off-chain data store.
*/
public final class Write {
private final String channelName;
private final String namespace;
private final String key;
private final boolean isDelete;
private final String value; // Store as String for readability when serialized to JSON.
public Write(final String channelName, final String namespace, final KVWrite write) {
this.channelName = channelName;
this.namespace = namespace;
this.key = write.getKey();
this.isDelete = write.getIsDelete();
this.value = write.getValue().toString(StandardCharsets.UTF_8);
}
/**
* Channel whose ledger is being updated.
* @return A channel name.
*/
public String getChannelName() {
return channelName;
}
/**
* Key name within the ledger namespace.
* @return A ledger key.
*/
public String getKey() {
return key;
}
/**
* Whether the key and associated value are being deleted.
* @return {@code true} if the ledger key is being deleted; otherwise {@code false}.
*/
public boolean isDelete() {
return isDelete;
}
/**
* Namespace within the ledger.
* @return A ledger namespace.
*/
public String getNamespace() {
return namespace;
}
/**
* If {@link #isDelete()}` is {@code false}, the value written to the key; otherwise ignored.
* @return A ledger value.
*/
public byte[] getValue() {
return value.getBytes(StandardCharsets.UTF_8);
}
}