iterate entity metadata sequentially (#543)
* iterate entity metadata sequentially * r * c
This commit is contained in:
parent
195e3f9a5a
commit
7da654649d
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@status-im/js': patch
|
||||
---
|
||||
|
||||
iterate metadata sequentially
|
|
@ -9,7 +9,10 @@ if (!publicKey) {
|
|||
)
|
||||
}
|
||||
|
||||
const environment = process.env.NEXT_PUBLIC_ENVIRONMENT as 'production' | 'test'
|
||||
const environment = process.env.NEXT_PUBLIC_ENVIRONMENT as
|
||||
| 'development'
|
||||
| 'preview'
|
||||
| 'production'
|
||||
|
||||
/**
|
||||
* For some reason the regular import fails with a server error:
|
||||
|
|
|
@ -8,7 +8,10 @@ if (!publicKey) {
|
|||
)
|
||||
}
|
||||
|
||||
const environment = process.env.ENVIRONMENT as 'production' | 'test'
|
||||
const environment = process.env.ENVIRONMENT as
|
||||
| 'development'
|
||||
| 'preview'
|
||||
| 'production'
|
||||
|
||||
export const App = () => {
|
||||
return (
|
||||
|
|
|
@ -132,7 +132,7 @@ class Client {
|
|||
}
|
||||
|
||||
static async start(options: ClientOptions): Promise<Client> {
|
||||
// const { environment = 'development' } = options
|
||||
const { environment = 'development' } = options
|
||||
|
||||
let waku: LightNode | undefined
|
||||
let client: Client | undefined
|
||||
|
@ -161,7 +161,7 @@ class Client {
|
|||
* >@see https://forum.vac.dev/t/waku-v2-scalability-studies/142/2
|
||||
*/
|
||||
bootstrap({
|
||||
list: peers['production'],
|
||||
list: peers[environment],
|
||||
timeout: 0,
|
||||
// note: Infinity prevents connection
|
||||
// tagTTL: Infinity,
|
||||
|
|
|
@ -14,6 +14,7 @@ const production = [
|
|||
'/dns4/store-02.ac-cn-hongkong-c.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm9CQhsuwPR54q27kNj9iaQVfyRzTGKrhFmr94oD8ujU6P',
|
||||
]
|
||||
|
||||
// todo?: https://github.com/status-im/infra-shards/issues/29#issuecomment-1992729489 `shards.staging`; await integration in desktop and mobile
|
||||
// note!: users may experience additional latency due to cross-regional connection
|
||||
// todo: use "dynamic" discovery protocol instead
|
||||
// todo?: use a regional map together with an environment variable for the peer selection (e.g. `VERCEL_REGION`, but probably limited to Serverless Functions)
|
||||
|
|
|
@ -37,7 +37,7 @@ import type { LightNode } from '@waku/interfaces'
|
|||
|
||||
export interface RequestClientOptions {
|
||||
ethProviderApiKey: string
|
||||
// environment?: 'development' | 'preview' | 'production'
|
||||
environment?: 'development' | 'preview' | 'production'
|
||||
}
|
||||
|
||||
class RequestClient {
|
||||
|
@ -72,7 +72,7 @@ class RequestClient {
|
|||
}
|
||||
|
||||
static async start(options: RequestClientOptions): Promise<RequestClient> {
|
||||
// const { environment = 'development' } = options
|
||||
const { environment = 'development' } = options
|
||||
|
||||
let waku: LightNode | undefined
|
||||
let client: RequestClient | undefined
|
||||
|
@ -89,7 +89,7 @@ class RequestClient {
|
|||
libp2p: {
|
||||
peerDiscovery: [
|
||||
bootstrap({
|
||||
list: peers['production'],
|
||||
list: peers[environment],
|
||||
timeout: 0,
|
||||
// note: Infinity prevents connection
|
||||
// tagTTL: Infinity,
|
||||
|
@ -205,29 +205,28 @@ class RequestClient {
|
|||
const contentTopic = idToContentTopic(communityPublicKey)
|
||||
const symmetricKey = await generateKeyFromPassword(communityPublicKey)
|
||||
|
||||
let communityDescription: CommunityDescription | undefined = undefined
|
||||
try {
|
||||
// todo: use queryGenerator() instead
|
||||
await this.waku.store.queryWithOrderedCallback(
|
||||
[
|
||||
const wakuMessageGenerator = this.waku.store.queryGenerator([
|
||||
createDecoder(contentTopic, symmetricKey, {
|
||||
clusterId: 16,
|
||||
shard: 32,
|
||||
}),
|
||||
],
|
||||
async wakuMessage => {
|
||||
])
|
||||
for await (const wakuMessages of wakuMessageGenerator) {
|
||||
for await (const wakuMessage of wakuMessages) {
|
||||
if (!wakuMessage) {
|
||||
continue
|
||||
}
|
||||
|
||||
// handle
|
||||
const message = this.handleWakuMessage(wakuMessage)
|
||||
|
||||
if (!message) {
|
||||
return
|
||||
continue
|
||||
}
|
||||
|
||||
if (
|
||||
message.type !==
|
||||
ApplicationMetadataMessage_Type.COMMUNITY_DESCRIPTION
|
||||
message.type !== ApplicationMetadataMessage_Type.COMMUNITY_DESCRIPTION
|
||||
) {
|
||||
return
|
||||
continue
|
||||
}
|
||||
|
||||
// decode
|
||||
|
@ -242,10 +241,9 @@ class RequestClient {
|
|||
message.timestamp
|
||||
)
|
||||
) {
|
||||
return
|
||||
continue
|
||||
}
|
||||
|
||||
// isSignatureValid
|
||||
if (isEncrypted(decodedCommunityDescription.tokenPermissions)) {
|
||||
// todo?: zod
|
||||
const permission = Object.values(
|
||||
|
@ -257,7 +255,7 @@ class RequestClient {
|
|||
)
|
||||
|
||||
if (!permission) {
|
||||
return
|
||||
continue
|
||||
}
|
||||
|
||||
const criteria = permission.tokenCriteria[0]
|
||||
|
@ -265,13 +263,19 @@ class RequestClient {
|
|||
const chainId = Object.keys(contracts)[0]
|
||||
|
||||
if (!chainId) {
|
||||
return
|
||||
continue
|
||||
}
|
||||
|
||||
const providerUrl = this.#ethProviderURLs[Number(chainId)]
|
||||
|
||||
if (!providerUrl) {
|
||||
continue
|
||||
}
|
||||
|
||||
const ethereumClient = this.getEthereumClient(Number(chainId))
|
||||
|
||||
if (!ethereumClient) {
|
||||
return
|
||||
continue
|
||||
}
|
||||
|
||||
const ownerPublicKey = await ethereumClient.resolveOwner(
|
||||
|
@ -281,28 +285,19 @@ class RequestClient {
|
|||
)
|
||||
|
||||
if (ownerPublicKey !== message.signerPublicKey) {
|
||||
return
|
||||
continue
|
||||
}
|
||||
} else if (
|
||||
communityPublicKey !==
|
||||
`0x${compressPublicKey(message.signerPublicKey)}`
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!communityDescription) {
|
||||
communityDescription = decodedCommunityDescription
|
||||
continue
|
||||
}
|
||||
|
||||
// stop
|
||||
throw new Error('stop')
|
||||
return decodedCommunityDescription
|
||||
}
|
||||
)
|
||||
} catch {
|
||||
// eslint-disable-next-line no-empty
|
||||
}
|
||||
|
||||
return communityDescription
|
||||
}
|
||||
|
||||
private fetchContactCodeAdvertisement = async (
|
||||
|
@ -313,29 +308,30 @@ class RequestClient {
|
|||
`${publicKey}-contact-code`
|
||||
)
|
||||
|
||||
let contactCodeAdvertisement: ContactCodeAdvertisement | undefined =
|
||||
undefined
|
||||
try {
|
||||
await this.waku.store.queryWithOrderedCallback(
|
||||
[
|
||||
const wakuMessageGenerator = this.waku.store.queryGenerator([
|
||||
createDecoder(contentTopic, symmetricKey, {
|
||||
clusterId: 16,
|
||||
shard: 32,
|
||||
}),
|
||||
],
|
||||
wakuMessage => {
|
||||
])
|
||||
for await (const wakuMessages of wakuMessageGenerator) {
|
||||
for await (const wakuMessage of wakuMessages) {
|
||||
if (!wakuMessage) {
|
||||
continue
|
||||
}
|
||||
|
||||
// handle
|
||||
const message = this.handleWakuMessage(wakuMessage)
|
||||
|
||||
if (!message) {
|
||||
return
|
||||
continue
|
||||
}
|
||||
|
||||
if (
|
||||
message.type !==
|
||||
ApplicationMetadataMessage_Type.CONTACT_CODE_ADVERTISEMENT
|
||||
) {
|
||||
return
|
||||
continue
|
||||
}
|
||||
|
||||
// decode
|
||||
|
@ -345,7 +341,7 @@ class RequestClient {
|
|||
|
||||
// validate
|
||||
if (!decodedContactCode.chatIdentity) {
|
||||
return
|
||||
continue
|
||||
}
|
||||
|
||||
if (
|
||||
|
@ -354,26 +350,17 @@ class RequestClient {
|
|||
message.timestamp
|
||||
)
|
||||
) {
|
||||
return
|
||||
continue
|
||||
}
|
||||
|
||||
if (publicKey !== message.signerPublicKey) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!contactCodeAdvertisement) {
|
||||
contactCodeAdvertisement = decodedContactCode
|
||||
continue
|
||||
}
|
||||
|
||||
// stop
|
||||
throw new Error('stop')
|
||||
return decodedContactCode
|
||||
}
|
||||
)
|
||||
} catch {
|
||||
// eslint-disable-next-line no-empty
|
||||
}
|
||||
|
||||
return contactCodeAdvertisement
|
||||
}
|
||||
|
||||
private handleWakuMessage = (
|
||||
|
|
Loading…
Reference in New Issue