mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Handle unl change announcement in js client library. (#225)
This commit is contained in:
@@ -378,6 +378,20 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
const validateAndEmitUnlChange = (changedUnl) => {
|
||||
// If this is currently a trusted connection, notify unl update.
|
||||
const trustedKeys = getTrustedKeys();
|
||||
if (trustedKeys && trustedKeys[pubkey]) {
|
||||
// Prepare sorted new unl lookup object for equality comparison.
|
||||
const newUnl = {};
|
||||
changedUnl.sort().forEach(k => newUnl[k] = true);
|
||||
|
||||
// Only emit unl change event if the unl has really changed.
|
||||
if (JSON.stringify(trustedKeys) != JSON.stringify(newUnl))
|
||||
emitter && emitter.emit(events.unlChange, changedUnl);
|
||||
}
|
||||
}
|
||||
|
||||
const handshakeMessageHandler = (m) => {
|
||||
|
||||
if (connectionStatus == 0 && m.type == "user_challenge" && m.hp_version && m.contract_id) {
|
||||
@@ -438,17 +452,7 @@
|
||||
handshakeResolver && handshakeResolver(true);
|
||||
console.log(`Connected to ${server}`);
|
||||
|
||||
// If this is currently a trusted connection, notify unl update.
|
||||
const trustedKeys = getTrustedKeys();
|
||||
if (trustedKeys && trustedKeys[pubkey]) {
|
||||
// Prepare sorted new unl lookup object for equality comparison.
|
||||
const newUnl = {};
|
||||
m.unl.sort().forEach(k => newUnl[k] = true);
|
||||
|
||||
// Only emit unl change event if the unl has really changed.
|
||||
if (JSON.stringify(trustedKeys) != JSON.stringify(newUnl))
|
||||
emitter && emitter.emit(events.unlChange, m.unl);
|
||||
}
|
||||
validateAndEmitUnlChange(m.unl);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -494,9 +498,11 @@
|
||||
statResponseResolvers = [];
|
||||
}
|
||||
else if (m.type == "unl_change") {
|
||||
// UNL change announcement message is handled in this block.
|
||||
console.log("Received :", m.type);
|
||||
console.log(m.unl);
|
||||
if (m.unl) {
|
||||
// Convert unl pubkeys to hex string.
|
||||
let unl = m.unl.map(k => msgHelper.stringifyValue(k));
|
||||
validateAndEmitUnlChange(unl);
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace msg::usrmsg::bson
|
||||
* Message format:
|
||||
* {
|
||||
* "type": "unl_change",
|
||||
* "unl": ["<pubkey1>{[1byte(11101101) prefix][32byte]}", ...], // Binary pubkey list of unl nodes.
|
||||
* "unl": ["<pubkey1>{[1byte(11101101) prefix][32byte]}", ...] // Binary pubkey list of unl nodes.
|
||||
* }
|
||||
* @param unl_list The unl node pubkey list to be put in the message.
|
||||
*/
|
||||
|
||||
@@ -319,7 +319,7 @@ namespace msg::usrmsg::json
|
||||
* Message format:
|
||||
* {
|
||||
* "type": "unl_change",
|
||||
* ["<pubkey1>{[ed prefix][64 characters]}", ...], // Hex pubkey list of unl nodes.
|
||||
* "unl": ["<pubkey1>{[ed prefix][64 characters]}", ...] // Hex pubkey list of unl nodes.
|
||||
* }
|
||||
* @param unl_list The unl node pubkey list to be put in the message.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user