2121import java .util .Collections ;
2222import java .util .Comparator ;
2323import java .util .Date ;
24+ import java .util .HashMap ;
2425import java .util .HashSet ;
2526import java .util .LinkedList ;
2627import java .util .List ;
@@ -1194,14 +1195,36 @@ private void switchFork(BlockCapsule newHead)
11941195
11951196 }
11961197
1198+ private boolean isSameSig (TransactionCapsule tx1 , TransactionCapsule tx2 ) {
1199+ if (tx1 == null || tx2 == null ) {
1200+ return false ;
1201+ }
1202+
1203+ if (tx1 .getInstance ().getSignatureCount () != tx2 .getInstance ().getSignatureCount ()) {
1204+ return false ;
1205+ }
1206+
1207+ boolean flag = true ;
1208+ for (int i = 0 ; i < tx1 .getInstance ().getSignatureCount (); i ++) {
1209+ ByteString sig1 = tx1 .getInstance ().getSignature (i );
1210+ ByteString sig2 = tx2 .getInstance ().getSignature (i );
1211+ if (!sig1 .equals (sig2 )) {
1212+ flag = false ;
1213+ break ;
1214+ }
1215+ }
1216+
1217+ return flag ;
1218+ }
1219+
11971220 public List <TransactionCapsule > getVerifyTxs (BlockCapsule block ) {
11981221
11991222 if (pendingTransactions .size () == 0 ) {
12001223 return block .getTransactions ();
12011224 }
12021225
12031226 List <TransactionCapsule > txs = new ArrayList <>();
1204- Set <String > txIds = new HashSet <>();
1227+ Map <String , TransactionCapsule > txMap = new HashMap <>();
12051228 Set <String > multiAddresses = new HashSet <>();
12061229
12071230 pendingTransactions .forEach (capsule -> {
@@ -1210,14 +1233,14 @@ public List<TransactionCapsule> getVerifyTxs(BlockCapsule block) {
12101233 String address = Hex .toHexString (capsule .getOwnerAddress ());
12111234 multiAddresses .add (address );
12121235 } else {
1213- txIds . add (txId );
1236+ txMap . put (txId , capsule );
12141237 }
12151238 });
12161239
12171240 block .getTransactions ().forEach (capsule -> {
12181241 String address = Hex .toHexString (capsule .getOwnerAddress ());
12191242 String txId = Hex .toHexString (capsule .getTransactionId ().getBytes ());
1220- if (multiAddresses .contains (address ) || !txIds . contains (txId )) {
1243+ if (multiAddresses .contains (address ) || !isSameSig ( capsule , txMap . get (txId ) )) {
12211244 txs .add (capsule );
12221245 } else {
12231246 capsule .setVerified (true );
0 commit comments