fix: it-length-prefixed now returns Uint8ArrayList

This commit is contained in:
fryorcraken.eth 2022-09-05 15:02:23 +10:00
parent ab76063f33
commit bfeaf6c14e
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
6 changed files with 19 additions and 6 deletions

1
package-lock.json generated
View File

@ -34,6 +34,7 @@
"libp2p": "0.38.0",
"p-event": "^5.0.1",
"protons-runtime": "^3.1.0",
"uint8arraylist": "^2.3.2",
"uint8arrays": "^3.0.0",
"uuid": "^8.3.2"
},

View File

@ -114,6 +114,7 @@
"libp2p": "0.38.0",
"p-event": "^5.0.1",
"protons-runtime": "^3.1.0",
"uint8arraylist": "^2.3.2",
"uint8arrays": "^3.0.0",
"uuid": "^8.3.2"
},

View File

@ -4,11 +4,11 @@ import all from "it-all";
import * as lp from "it-length-prefixed";
import { pipe } from "it-pipe";
import { Libp2p } from "libp2p";
import { Uint8ArrayList } from "uint8arraylist";
import { PushResponse } from "../../proto/light_push";
import { DefaultPubSubTopic } from "../constants";
import { getPeersForProtocol, selectRandomPeer } from "../select_peer";
import { concat } from "../utils";
import { WakuMessage } from "../waku_message";
import { PushRPC } from "./push_rpc";
@ -76,7 +76,11 @@ export class WakuLightPush {
async (source) => await all(source)
);
try {
const bytes = concat(res);
const bytes = new Uint8ArrayList();
res.forEach((chunk) => {
bytes.append(chunk);
});
const response = PushRPC.decode(bytes).response;
if (!response) {

View File

@ -1,3 +1,4 @@
import type { Uint8ArrayList } from "uint8arraylist";
import { v4 as uuid } from "uuid";
import * as proto from "../../proto/light_push";
@ -17,7 +18,7 @@ export class PushRPC {
});
}
static decode(bytes: Uint8Array): PushRPC {
static decode(bytes: Uint8ArrayList): PushRPC {
const res = proto.PushRPC.decode(bytes);
return new PushRPC(res);
}

View File

@ -1,3 +1,4 @@
import type { Uint8ArrayList } from "uint8arraylist";
import { v4 as uuid } from "uuid";
import * as protoV2Beta3 from "../../proto/store_v2beta3";
@ -139,7 +140,7 @@ export class HistoryRPC {
}
}
decode(bytes: Uint8Array): HistoryRPC {
decode(bytes: Uint8ArrayList): HistoryRPC {
const res = this.historyRpc.decode(bytes);
return new HistoryRPC(res, this.storeCodec);
}

View File

@ -5,12 +5,13 @@ import all from "it-all";
import * as lp from "it-length-prefixed";
import { pipe } from "it-pipe";
import { Libp2p } from "libp2p";
import { Uint8ArrayList } from "uint8arraylist";
import * as protoV2Beta4 from "../../proto/store_v2beta4";
import { HistoryResponse } from "../../proto/store_v2beta4";
import { DefaultPubSubTopic, StoreCodecs } from "../constants";
import { getPeersForProtocol, selectRandomPeer } from "../select_peer";
import { concat, hexToBytes } from "../utils";
import { hexToBytes } from "../utils";
import { DecryptionMethod, WakuMessage } from "../waku_message";
import { HistoryRPC, PageDirection } from "./history_rpc";
@ -211,7 +212,11 @@ export class WakuStore {
lp.decode(),
async (source) => await all(source)
);
const bytes = concat(res);
const bytes = new Uint8ArrayList();
res.forEach((chunk) => {
bytes.append(chunk);
});
const reply = historyRpcQuery.decode(bytes);
if (!reply.response) {