Skip to content

Commit 9d6709e

Browse files
committed
refactor to use same method
1 parent 4a98eb7 commit 9d6709e

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/main/java/org/arkecosystem/crypto/transactions/types/Transaction.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ public void computeId() {
4141
}
4242

4343
public String getId() {
44-
return Hex.encode(Sha256Hash.hash(Serializer.serialize(this)));
44+
return Hex.encode(Sha256Hash.hash(this.serialize()));
4545
}
4646

4747
public Transaction sign(String passphrase) {
4848
ECKey privateKey = PrivateKey.fromPassphrase(passphrase);
4949

5050
this.senderPublicKey = privateKey.getPublicKeyAsHex();
51-
Sha256Hash hash = Sha256Hash.of(Serializer.serialize(this, true, true, false));
51+
Sha256Hash hash = Sha256Hash.of(this.serialize(true, true, false));
5252

5353
this.signature = Hex.encode(signer().sign(hash.getBytes(), privateKey));
5454

@@ -58,7 +58,7 @@ public Transaction sign(String passphrase) {
5858
public Transaction secondSign(String passphrase) {
5959
ECKey privateKey = PrivateKey.fromPassphrase(passphrase);
6060

61-
Sha256Hash hash = Sha256Hash.of(Serializer.serialize(this, false, true, false));
61+
Sha256Hash hash = Sha256Hash.of(this.serialize(false, true));
6262

6363
this.secondSignature = Hex.encode(signer().sign(hash.getBytes(), privateKey));
6464

@@ -89,7 +89,7 @@ public boolean verify() {
8989
ECKey keys = ECKey.fromPublicOnly(Hex.decode(this.senderPublicKey));
9090

9191
byte[] signature = Hex.decode(this.signature);
92-
byte[] hash = Sha256Hash.hash(Serializer.serialize(this, true, true, false));
92+
byte[] hash = Sha256Hash.hash(this.serialize(true, true, false));
9393

9494
return verifier().verify(hash, keys, signature);
9595
}
@@ -98,7 +98,7 @@ public boolean secondVerify(String secondPublicKey) {
9898
ECKey keys = ECKey.fromPublicOnly(Hex.decode(secondPublicKey));
9999

100100
byte[] signature = Hex.decode(this.secondSignature);
101-
byte[] hash = Sha256Hash.hash(Serializer.serialize(this, false, true, false));
101+
byte[] hash = Sha256Hash.hash(this.serialize(false, true, false));
102102

103103
return verifier().verify(hash, keys, signature);
104104
}
@@ -145,6 +145,24 @@ public HashMap toHashMap() {
145145
return map;
146146
}
147147

148+
public byte[] serialize(
149+
boolean skipSignature, boolean skipSecondSignature, boolean skipMultiSignature) {
150+
return Serializer.serialize(this, skipSignature, skipSecondSignature, skipMultiSignature);
151+
}
152+
153+
public byte[] serialize(boolean skipSignature, boolean skipSecondSignature) {
154+
return serialize(skipSignature, skipSecondSignature, false);
155+
}
156+
157+
public byte[] serialize(boolean skipSignature) {
158+
return serialize(skipSignature, false, false);
159+
}
160+
161+
// Overloaded method with no parameters, defaulting all to false
162+
public byte[] serialize() {
163+
return serialize(false, false, false);
164+
}
165+
148166
public abstract byte[] serializeData();
149167

150168
public abstract void deserializeData(ByteBuffer buffer);

0 commit comments

Comments
 (0)