*Update dist
This commit is contained in:
parent
4f855110f5
commit
c750fce402
|
@ -1 +1 @@
|
|||
{"version":3,"file":"wisdom.d.ts","sourceRoot":"","sources":["../../src/query/wisdom.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,WAAW,CAAC;AAOrC,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,YAAY;IACtD,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,MAAM,CAAK;IAEnB,SAAS,CAAC,cAAc,IAAI,IAAI;IAoDhC,OAAO,CAAC,KAAK;IAWb,SAAS,CAAC,SAAS,IAAI,MAAM,EAAE,GAAG,EAAE;CAGrC"}
|
||||
{"version":3,"file":"wisdom.d.ts","sourceRoot":"","sources":["../../src/query/wisdom.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,WAAW,CAAC;AAcrC,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,YAAY;IACtD,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,MAAM,CAAK;IAEnB,SAAS,CAAC,cAAc,IAAI,IAAI;IA6ChC,OAAO,CAAC,KAAK;IAWb,SAAS,CAAC,SAAS,IAAI,MAAM,EAAE,GAAG,EAAE;CAGrC"}
|
|
@ -3,6 +3,10 @@ import { flatten } from "../util.js";
|
|||
import { Buffer } from "buffer";
|
||||
import { blake2b } from "libskynet";
|
||||
import { ERR_MAX_TRIES_HIT } from "../error.js";
|
||||
function flatHash(data) {
|
||||
const flattenedData = flatten(data).sort();
|
||||
return Buffer.from(blake2b(Buffer.from(JSON.stringify(flattenedData)))).toString("hex");
|
||||
}
|
||||
export default class WisdomRpcQuery extends RpcQueryBase {
|
||||
_maxTries = 3;
|
||||
_tries = 0;
|
||||
|
@ -10,14 +14,12 @@ export default class WisdomRpcQuery extends RpcQueryBase {
|
|||
const responseStore = this._responses;
|
||||
const responseStoreData = Object.values(responseStore);
|
||||
const responseObjects = responseStoreData.reduce((output, item) => {
|
||||
const itemFlattened = flatten(item?.data).sort();
|
||||
const hash = Buffer.from(blake2b(Buffer.from(JSON.stringify(itemFlattened)))).toString("hex");
|
||||
const hash = flatHash(item?.data);
|
||||
output[hash] = item?.data;
|
||||
return output;
|
||||
}, {});
|
||||
const responses = responseStoreData.reduce((output, item) => {
|
||||
const itemFlattened = flatten(item?.data).sort();
|
||||
const hash = Buffer.from(blake2b(Buffer.from(JSON.stringify(itemFlattened)))).toString("hex");
|
||||
const hash = flatHash(item?.data);
|
||||
output[hash] = output[hash] ?? 0;
|
||||
output[hash]++;
|
||||
return output;
|
||||
|
@ -35,7 +37,7 @@ export default class WisdomRpcQuery extends RpcQueryBase {
|
|||
}
|
||||
response = { error: ERR_MAX_TRIES_HIT };
|
||||
}
|
||||
this.resolve(response);
|
||||
this.resolve({ data: response });
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue