com.jd.blockchain.transaction.DataAccountKVSetOpTemplate Maven / Gradle / Ivy
package com.jd.blockchain.transaction;
import java.util.LinkedHashMap;
import java.util.Map;
import com.jd.binaryproto.DataContractRegistry;
import com.jd.blockchain.ledger.BytesValue;
import com.jd.blockchain.ledger.DataAccountKVSetOperation;
import utils.Bytes;
public class DataAccountKVSetOpTemplate implements DataAccountKVSetOperation {
static {
DataContractRegistry.register(DataAccountKVSetOperation.class);
}
private Bytes accountAddress;
private Map kvset = new LinkedHashMap<>();
public DataAccountKVSetOpTemplate() {
}
public DataAccountKVSetOpTemplate(Bytes accountAddress) {
this.accountAddress = accountAddress;
}
public DataAccountKVSetOpTemplate(Bytes accountAddress, Map kvset) {
this.accountAddress = accountAddress;
this.kvset = kvset;
}
@Override
public Bytes getAccountAddress() {
return accountAddress;
}
@Override
public KVWriteEntry[] getWriteSet() {
return kvset.values().toArray(new KVWriteEntry[kvset.size()]);
}
public void setWriteSet(Object[] kvEntries) {
for (Object object : kvEntries) {
KVWriteEntry kvEntry = (KVWriteEntry) object;
set(kvEntry.getKey(), kvEntry.getValue(), kvEntry.getExpectedVersion());
}
return;
}
public void set(String key, BytesValue value, long expVersion) {
if (kvset.containsKey(key)) {
throw new IllegalArgumentException("Cann't set the same key repeatedly!");
}
KVData kvdata = new KVData(key, value, expVersion);
kvset.put(key, kvdata);
}
public void set(KVData kvData) {
if (kvset.containsKey(kvData.getKey())) {
throw new IllegalArgumentException("Cann't set the same key repeatedly!");
}
kvset.put(kvData.getKey(), kvData);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy