Optimize the code format: transaction serializeForHash
@@ -95,17 +95,21 @@ public abstract class Transaction<T extends TransactionLogicData> extends BaseNu
bos = new UnsafeByteArrayOutputStream(size);
NulsOutputStreamBuffer buffer = new NulsOutputStreamBuffer(bos);
+ do {
if (size == 0) {
bos.write(NulsConstant.PLACE_HOLDER);
- } else {
+ break;
+ }
if (NulsContext.MAIN_NET_VERSION == 1) {
buffer.writeVarInt(type);
buffer.writeVarInt(time);
- } else {
+ break;
+ }
if (this.blockHeight == -1) {
buffer.writeUint16(type);
buffer.writeUint48(time);
- } else {
+ break;
+ }
if (NulsContext.CHANGE_HASH_SERIALIZE_HEIGHT != null && this.blockHeight >= NulsContext.CHANGE_HASH_SERIALIZE_HEIGHT) {
buffer.writeUint16(type);
buffer.writeUint48(time);
@@ -113,8 +117,8 @@ public abstract class Transaction<T extends TransactionLogicData> extends BaseNu
buffer.writeVarInt(type);
buffer.writeVarInt(time);
}
- }
- }
+ } while (false);
+ if (size > 0) {
buffer.writeBytesWithLength(remark);
buffer.writeNulsData(txData);
buffer.writeNulsData(coinData);
