下面列出了com.google.protobuf.ByteString#equals ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Removes the uuid from the full members of a group.
* <p>
* Generally not expected to have to do this, just in the case of leaving a group where you cannot
* get the new group state as you are not in the group any longer.
*/
public static DecryptedGroup removeMember(DecryptedGroup group, UUID uuid, int revision) {
DecryptedGroup.Builder builder = DecryptedGroup.newBuilder(group);
ByteString uuidString = UuidUtil.toByteString(uuid);
boolean removed = false;
ArrayList<DecryptedMember> decryptedMembers = new ArrayList<>(builder.getMembersList());
Iterator<DecryptedMember> membersList = decryptedMembers.iterator();
while (membersList.hasNext()) {
if (uuidString.equals(membersList.next().getUuid())) {
membersList.remove();
removed = true;
}
}
if (removed) {
return builder.clearMembers()
.addAllMembers(decryptedMembers)
.setRevision(revision)
.build();
} else {
return group;
}
}
private void describeMemberRemovals(@NonNull DecryptedGroupChange change, @NonNull List<String> updates) {
boolean editorIsYou = change.getEditor().equals(selfUuidBytes);
for (ByteString member : change.getDeleteMembersList()) {
boolean removedMemberIsYou = member.equals(selfUuidBytes);
if (editorIsYou) {
if (removedMemberIsYou) {
updates.add(context.getString(R.string.MessageRecord_you_left_the_group));
} else {
updates.add(context.getString(R.string.MessageRecord_you_removed_s, describe(member)));
}
} else {
if (removedMemberIsYou) {
updates.add(context.getString(R.string.MessageRecord_s_removed_you_from_the_group, describe(change.getEditor())));
} else {
if (member.equals(change.getEditor())) {
updates.add(context.getString(R.string.MessageRecord_s_left_the_group, describe(member)));
} else {
updates.add(context.getString(R.string.MessageRecord_s_removed_s, describe(change.getEditor()), describe(member)));
}
}
}
}
}
private void describePromotePending(@NonNull DecryptedGroupChange change, @NonNull List<String> updates) {
boolean editorIsYou = change.getEditor().equals(selfUuidBytes);
for (DecryptedMember newMember : change.getPromotePendingMembersList()) {
ByteString uuid = newMember.getUuid();
boolean newMemberIsYou = uuid.equals(selfUuidBytes);
if (editorIsYou) {
if (newMemberIsYou) {
updates.add(context.getString(R.string.MessageRecord_you_accepted_invite));
} else {
updates.add(context.getString(R.string.MessageRecord_you_added_invited_member_s, describe(uuid)));
}
} else {
if (newMemberIsYou) {
updates.add(context.getString(R.string.MessageRecord_s_added_you, describe(change.getEditor())));
} else {
if (uuid.equals(change.getEditor())) {
updates.add(context.getString(R.string.MessageRecord_s_accepted_invite, describe(uuid)));
} else {
updates.add(context.getString(R.string.MessageRecord_s_added_invited_member_s, describe(change.getEditor()), describe(uuid)));
}
}
}
}
}
ScanIterator(
TiConfiguration conf,
RegionStoreClientBuilder builder,
ByteString startKey,
ByteString endKey,
int limit) {
this.startKey = requireNonNull(startKey, "start key is null");
if (startKey.isEmpty()) {
throw new IllegalArgumentException("start key cannot be empty");
}
this.endKey = Key.toRawKey(requireNonNull(endKey, "end key is null"));
this.hasEndKey = !endKey.equals(ByteString.EMPTY);
this.limit = limit;
this.conf = conf;
this.builder = builder;
}
public static Optional<DecryptedMember> findMemberByUuid(Collection<DecryptedMember> members, UUID uuid) {
ByteString uuidBytes = UuidUtil.toByteString(uuid);
for (DecryptedMember member : members) {
if (uuidBytes.equals(member.getUuid())) {
return Optional.of(member);
}
}
return Optional.absent();
}
public static Optional<DecryptedPendingMember> findPendingByUuid(Collection<DecryptedPendingMember> members, UUID uuid) {
ByteString uuidBytes = UuidUtil.toByteString(uuid);
for (DecryptedPendingMember member : members) {
if (uuidBytes.equals(member.getUuid())) {
return Optional.of(member);
}
}
return Optional.absent();
}
private static int findPendingIndexByUuidCipherText(List<DecryptedPendingMember> members, ByteString cipherText) {
for (int i = 0; i < members.size(); i++) {
DecryptedPendingMember member = members.get(i);
if (cipherText.equals(member.getUuidCipherText())) {
return i;
}
}
return -1;
}
private static int findPendingIndexByUuid(List<DecryptedPendingMember> members, ByteString uuid) {
for (int i = 0; i < members.size(); i++) {
DecryptedPendingMember member = members.get(i);
if (uuid.equals(member.getUuid())) {
return i;
}
}
return -1;
}
public static boolean isMember(@NonNull UUID uuid, @NonNull List<DecryptedMember> membersList) {
ByteString uuidBytes = UuidUtil.toByteString(uuid);
for (DecryptedMember member : membersList) {
if (uuidBytes.equals(member.getUuid())) {
return true;
}
}
return false;
}
private static void validatePvtdata(Transaction tx, TxPvtData pvtData)throws LedgerException{
if(pvtData.getWriteSet() == null){
return;
}
for(Rwset.NsPvtReadWriteSet nsPvtRwSet : pvtData.getWriteSet().getNsPvtRwsetList()){
for(Rwset.CollectionPvtReadWriteSet collPvtdata : nsPvtRwSet.getCollectionPvtRwsetList()){
//TODO SM3 hash
ByteString collPvtdataHash = ByteString.copyFrom(Util.getHashBytes(collPvtdata.getRwset().toByteArray()));
ByteString hashInPubdata = tx.retrieveHash(nsPvtRwSet.getNamespace(), collPvtdata.getCollectionName());
if(!collPvtdataHash.equals(hashInPubdata)){
throw new LedgerException("Hash of pvt data mismatch corresponding hash in pub data");
}
}
}
}
public boolean validateWitnessSchedule(ByteString witnessAddress, long timeStamp) {
//to deal with other condition later
if (manager.getDynamicPropertiesStore().getLatestBlockHeaderNumber() == 0) {
return true;
}
long blockAbSlot = getAbSlotAtTime(timeStamp);
long headBlockAbSlot = getAbSlotAtTime(
manager.getDynamicPropertiesStore().getLatestBlockHeaderTimestamp());
if (blockAbSlot <= headBlockAbSlot) {
logger.warn("blockAbSlot is equals with headBlockAbSlot[" + blockAbSlot + "]");
return false;
}
long slot = getSlotAtTime(timeStamp);
final ByteString scheduledWitness = getScheduledWitness(slot);
if (!scheduledWitness.equals(witnessAddress)) {
logger.warn(
"Witness is out of order, scheduledWitness[{}],blockWitnessAddress[{}],blockTimeStamp[{}],slot[{}]",
ByteArray.toHexString(scheduledWitness.toByteArray()),
ByteArray.toHexString(witnessAddress.toByteArray()), new DateTime(timeStamp),
slot);
return false;
}
logger.debug("Validate witnessSchedule successfully,scheduledWitness:{}",
ByteArray.toHexString(witnessAddress.toByteArray()));
return true;
}
public boolean mergeIfNewRoot(ByteString old_root, Map<ByteString, ByteString> updates, ByteString expected_new_root)
{
TrieDBBuffered db = new TrieDBBuffered(basedb);
TrieNode root = db.load(old_root);
ByteString answer = mergeNode(db, root, updates).getHash();
if (answer.equals(expected_new_root))
{
System.out.println("Commiting new UTXO root: " + HashUtils.getHexString(answer));
db.commit();
return true;
}
return false;
}
private static void validateChecksum(String label, ByteString data, ByteString checksum)
throws ValidationException
{
ByteString expected = applyChecksum(label, data);
ByteString have = data.concat(checksum);
if (!expected.equals(have)) throw new ValidationException("Checksum mismatch");
}
/** Returns whether the digest in {@code state} is correct. */
private static boolean isDigestValid(AndroidTiclStateWithDigest state, Logger logger) {
Sha1DigestFunction digester = new Sha1DigestFunction();
digester.update(state.getState().toByteArray());
ByteString computedDigest = ByteString.copyFrom(digester.getDigest());
if (!computedDigest.equals(state.getDigest())) {
logger.warning("Android Ticl state digest mismatch; computed %s for %s",
computedDigest, state);
return false;
}
return true;
}
/** Returns whether the digest in {@code state} is correct. */
private static boolean isDigestValid(AndroidTiclStateWithDigest state, Logger logger) {
Sha1DigestFunction digester = new Sha1DigestFunction();
digester.update(state.getState().toByteArray());
ByteString computedDigest = ByteString.copyFrom(digester.getDigest());
if (!computedDigest.equals(state.getDigest())) {
logger.warning("Android Ticl state digest mismatch; computed %s for %s",
computedDigest, state);
return false;
}
return true;
}
private static int indexOfUuid(List<DecryptedMember> memberList, ByteString uuid) {
for (int i = 0; i < memberList.size(); i++) {
if(uuid.equals(memberList.get(i).getUuid())) return i;
}
return -1;
}
public static boolean checkProof(SnowPowProof proof, ByteString expected_merkle_root, long snow_field_size)
{
long target_index = proof.getWordIdx();
long word_count = snow_field_size / SnowMerkle.HASH_LEN_LONG;
if (target_index < 0) return false;
if (target_index >= word_count) return false;
MessageDigest md;
try
{
md = MessageDigest.getInstance(Globals.SNOW_MERKLE_HASH_ALGO);
}
catch(java.security.NoSuchAlgorithmException e)
{
throw new RuntimeException( e );
}
LinkedList<ByteString> stack = new LinkedList<>();
stack.addAll(proof.getMerkleComponentList());
ByteString current_hash = stack.poll();
if (current_hash == null) return false;
long start = target_index;
long end = target_index;
long dist = 1;
// To visualize this, take the recursive getInnerProof() below
// and do it backwards
while ((stack.size() > 0) && (end <= word_count))
{
dist *= 2;
start = start - (start % dist);
end = start + dist;
long mid = (start + end) / 2;
ByteString left = null;
ByteString right = null;
if (target_index < mid)
{
left = current_hash;
right = stack.poll();
}
else
{
left = stack.poll();
right = current_hash;
}
md.update(left.toByteArray());
md.update(right.toByteArray());
byte[] hash = md.digest();
current_hash = ByteString.copyFrom(hash);
}
// We expect to end with our sublist being the entire file
// so we check to avoid someone passing off an intermediate node
// as a merkle tree member
if (start != 0) return false;
if (end != word_count) return false;
if (current_hash.equals(expected_merkle_root)) return true;
return false;
}