Created
May 28, 2023 13:17
-
-
Save kazabubu21/476d1226ded207a1e649ac0afff88ff1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static long checkWeight(Permission permission, List<ByteString> sigs, byte[] hash, | |
List<ByteString> approveList) | |
throws SignatureException, PermissionException, SignatureFormatException { | |
long currentWeight = 0; | |
if (sigs.size() > permission.getKeysCount()) { | |
throw new PermissionException( | |
"Signature count is " + (sigs.size()) + " more than key counts of permission : " | |
+ permission.getKeysCount()); | |
} | |
HashMap addMap = new HashMap(); | |
for (ByteString sig : sigs) { | |
if (sig.size() < 65) { | |
throw new SignatureFormatException( | |
"Signature size is " + sig.size()); | |
} | |
String base64 = TransactionCapsule.getBase64FromByteString(sig); | |
byte[] address = SignUtils | |
.signatureToAddress(hash, base64, CommonParameter.getInstance().isECKeyCryptoEngine()); | |
long weight = getWeight(permission, address); | |
if (weight == 0) { | |
throw new PermissionException( | |
ByteArray.toHexString(sig.toByteArray()) + " is signed by " + encode58Check(address) | |
+ " but it is not contained of permission."); | |
} | |
if (ForkController.instance().pass(Parameter.ForkBlockVersionEnum.VERSION_4_7_1)) { | |
base64 = encode58Check(address); | |
} | |
if (addMap.containsKey(base64)) { | |
throw new PermissionException(encode58Check(address) + " has signed twice!"); | |
} | |
addMap.put(base64, weight); | |
if (approveList != null) { | |
approveList.add(ByteString.copyFrom(address)); //out put approve list. | |
} | |
currentWeight += weight; | |
} | |
return currentWeight; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment