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:
|
* 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 = () => {
|
export const App = () => {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -132,7 +132,7 @@ class Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
static async start(options: ClientOptions): Promise<Client> {
|
static async start(options: ClientOptions): Promise<Client> {
|
||||||
// const { environment = 'development' } = options
|
const { environment = 'development' } = options
|
||||||
|
|
||||||
let waku: LightNode | undefined
|
let waku: LightNode | undefined
|
||||||
let client: Client | undefined
|
let client: Client | undefined
|
||||||
|
@ -161,7 +161,7 @@ class Client {
|
||||||
* >@see https://forum.vac.dev/t/waku-v2-scalability-studies/142/2
|
* >@see https://forum.vac.dev/t/waku-v2-scalability-studies/142/2
|
||||||
*/
|
*/
|
||||||
bootstrap({
|
bootstrap({
|
||||||
list: peers['production'],
|
list: peers[environment],
|
||||||
timeout: 0,
|
timeout: 0,
|
||||||
// note: Infinity prevents connection
|
// note: Infinity prevents connection
|
||||||
// tagTTL: Infinity,
|
// tagTTL: Infinity,
|
||||||
|
|
|
@ -14,6 +14,7 @@ const production = [
|
||||||
'/dns4/store-02.ac-cn-hongkong-c.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm9CQhsuwPR54q27kNj9iaQVfyRzTGKrhFmr94oD8ujU6P',
|
'/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
|
// note!: users may experience additional latency due to cross-regional connection
|
||||||
// todo: use "dynamic" discovery protocol instead
|
// 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)
|
// 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 {
|
export interface RequestClientOptions {
|
||||||
ethProviderApiKey: string
|
ethProviderApiKey: string
|
||||||
// environment?: 'development' | 'preview' | 'production'
|
environment?: 'development' | 'preview' | 'production'
|
||||||
}
|
}
|
||||||
|
|
||||||
class RequestClient {
|
class RequestClient {
|
||||||
|
@ -72,7 +72,7 @@ class RequestClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
static async start(options: RequestClientOptions): Promise<RequestClient> {
|
static async start(options: RequestClientOptions): Promise<RequestClient> {
|
||||||
// const { environment = 'development' } = options
|
const { environment = 'development' } = options
|
||||||
|
|
||||||
let waku: LightNode | undefined
|
let waku: LightNode | undefined
|
||||||
let client: RequestClient | undefined
|
let client: RequestClient | undefined
|
||||||
|
@ -89,7 +89,7 @@ class RequestClient {
|
||||||
libp2p: {
|
libp2p: {
|
||||||
peerDiscovery: [
|
peerDiscovery: [
|
||||||
bootstrap({
|
bootstrap({
|
||||||
list: peers['production'],
|
list: peers[environment],
|
||||||
timeout: 0,
|
timeout: 0,
|
||||||
// note: Infinity prevents connection
|
// note: Infinity prevents connection
|
||||||
// tagTTL: Infinity,
|
// tagTTL: Infinity,
|
||||||
|
@ -205,29 +205,28 @@ class RequestClient {
|
||||||
const contentTopic = idToContentTopic(communityPublicKey)
|
const contentTopic = idToContentTopic(communityPublicKey)
|
||||||
const symmetricKey = await generateKeyFromPassword(communityPublicKey)
|
const symmetricKey = await generateKeyFromPassword(communityPublicKey)
|
||||||
|
|
||||||
let communityDescription: CommunityDescription | undefined = undefined
|
const wakuMessageGenerator = this.waku.store.queryGenerator([
|
||||||
try {
|
|
||||||
// todo: use queryGenerator() instead
|
|
||||||
await this.waku.store.queryWithOrderedCallback(
|
|
||||||
[
|
|
||||||
createDecoder(contentTopic, symmetricKey, {
|
createDecoder(contentTopic, symmetricKey, {
|
||||||
clusterId: 16,
|
clusterId: 16,
|
||||||
shard: 32,
|
shard: 32,
|
||||||
}),
|
}),
|
||||||
],
|
])
|
||||||
async wakuMessage => {
|
for await (const wakuMessages of wakuMessageGenerator) {
|
||||||
|
for await (const wakuMessage of wakuMessages) {
|
||||||
|
if (!wakuMessage) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// handle
|
// handle
|
||||||
const message = this.handleWakuMessage(wakuMessage)
|
const message = this.handleWakuMessage(wakuMessage)
|
||||||
|
|
||||||
if (!message) {
|
if (!message) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
message.type !==
|
message.type !== ApplicationMetadataMessage_Type.COMMUNITY_DESCRIPTION
|
||||||
ApplicationMetadataMessage_Type.COMMUNITY_DESCRIPTION
|
|
||||||
) {
|
) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// decode
|
// decode
|
||||||
|
@ -242,10 +241,9 @@ class RequestClient {
|
||||||
message.timestamp
|
message.timestamp
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// isSignatureValid
|
|
||||||
if (isEncrypted(decodedCommunityDescription.tokenPermissions)) {
|
if (isEncrypted(decodedCommunityDescription.tokenPermissions)) {
|
||||||
// todo?: zod
|
// todo?: zod
|
||||||
const permission = Object.values(
|
const permission = Object.values(
|
||||||
|
@ -257,7 +255,7 @@ class RequestClient {
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!permission) {
|
if (!permission) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const criteria = permission.tokenCriteria[0]
|
const criteria = permission.tokenCriteria[0]
|
||||||
|
@ -265,13 +263,19 @@ class RequestClient {
|
||||||
const chainId = Object.keys(contracts)[0]
|
const chainId = Object.keys(contracts)[0]
|
||||||
|
|
||||||
if (!chainId) {
|
if (!chainId) {
|
||||||
return
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
const providerUrl = this.#ethProviderURLs[Number(chainId)]
|
||||||
|
|
||||||
|
if (!providerUrl) {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const ethereumClient = this.getEthereumClient(Number(chainId))
|
const ethereumClient = this.getEthereumClient(Number(chainId))
|
||||||
|
|
||||||
if (!ethereumClient) {
|
if (!ethereumClient) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const ownerPublicKey = await ethereumClient.resolveOwner(
|
const ownerPublicKey = await ethereumClient.resolveOwner(
|
||||||
|
@ -281,28 +285,19 @@ class RequestClient {
|
||||||
)
|
)
|
||||||
|
|
||||||
if (ownerPublicKey !== message.signerPublicKey) {
|
if (ownerPublicKey !== message.signerPublicKey) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (
|
||||||
communityPublicKey !==
|
communityPublicKey !==
|
||||||
`0x${compressPublicKey(message.signerPublicKey)}`
|
`0x${compressPublicKey(message.signerPublicKey)}`
|
||||||
) {
|
) {
|
||||||
return
|
continue
|
||||||
}
|
|
||||||
|
|
||||||
if (!communityDescription) {
|
|
||||||
communityDescription = decodedCommunityDescription
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop
|
// stop
|
||||||
throw new Error('stop')
|
return decodedCommunityDescription
|
||||||
}
|
}
|
||||||
)
|
|
||||||
} catch {
|
|
||||||
// eslint-disable-next-line no-empty
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return communityDescription
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fetchContactCodeAdvertisement = async (
|
private fetchContactCodeAdvertisement = async (
|
||||||
|
@ -313,29 +308,30 @@ class RequestClient {
|
||||||
`${publicKey}-contact-code`
|
`${publicKey}-contact-code`
|
||||||
)
|
)
|
||||||
|
|
||||||
let contactCodeAdvertisement: ContactCodeAdvertisement | undefined =
|
const wakuMessageGenerator = this.waku.store.queryGenerator([
|
||||||
undefined
|
|
||||||
try {
|
|
||||||
await this.waku.store.queryWithOrderedCallback(
|
|
||||||
[
|
|
||||||
createDecoder(contentTopic, symmetricKey, {
|
createDecoder(contentTopic, symmetricKey, {
|
||||||
clusterId: 16,
|
clusterId: 16,
|
||||||
shard: 32,
|
shard: 32,
|
||||||
}),
|
}),
|
||||||
],
|
])
|
||||||
wakuMessage => {
|
for await (const wakuMessages of wakuMessageGenerator) {
|
||||||
|
for await (const wakuMessage of wakuMessages) {
|
||||||
|
if (!wakuMessage) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// handle
|
// handle
|
||||||
const message = this.handleWakuMessage(wakuMessage)
|
const message = this.handleWakuMessage(wakuMessage)
|
||||||
|
|
||||||
if (!message) {
|
if (!message) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
message.type !==
|
message.type !==
|
||||||
ApplicationMetadataMessage_Type.CONTACT_CODE_ADVERTISEMENT
|
ApplicationMetadataMessage_Type.CONTACT_CODE_ADVERTISEMENT
|
||||||
) {
|
) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// decode
|
// decode
|
||||||
|
@ -345,7 +341,7 @@ class RequestClient {
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
if (!decodedContactCode.chatIdentity) {
|
if (!decodedContactCode.chatIdentity) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
@ -354,26 +350,17 @@ class RequestClient {
|
||||||
message.timestamp
|
message.timestamp
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (publicKey !== message.signerPublicKey) {
|
if (publicKey !== message.signerPublicKey) {
|
||||||
return
|
continue
|
||||||
}
|
|
||||||
|
|
||||||
if (!contactCodeAdvertisement) {
|
|
||||||
contactCodeAdvertisement = decodedContactCode
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop
|
// stop
|
||||||
throw new Error('stop')
|
return decodedContactCode
|
||||||
}
|
}
|
||||||
)
|
|
||||||
} catch {
|
|
||||||
// eslint-disable-next-line no-empty
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return contactCodeAdvertisement
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleWakuMessage = (
|
private handleWakuMessage = (
|
||||||
|
|
Loading…
Reference in New Issue