|
@@ -1,4 +1,4 @@
|
|
|
-import { DatabaseManager } from '@joystream/hydra-common'
|
|
|
+import { DatabaseManager, SubstrateEvent } from '@joystream/hydra-common'
|
|
|
import {
|
|
|
DistributionBucketFamilyMetadata,
|
|
|
DistributionBucketOperatorMetadata,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
GeographicalAreaSubdivistion,
|
|
|
DistributionBucketFamilyGeographicArea,
|
|
|
} from 'query-node/dist/model'
|
|
|
-import { deserializeMetadata, invalidMetadata } from '../common'
|
|
|
+import { deserializeMetadata, deterministicEntityId, invalidMetadata } from '../common'
|
|
|
import { Bytes } from '@polkadot/types'
|
|
|
import {
|
|
|
DistributionBucketOperatorMetadata as DistributionBucketOperatorMetadataProto,
|
|
@@ -33,11 +33,12 @@ const protobufContinentToGraphlContinent: { [key in GeographicalAreaProto.Contin
|
|
|
}
|
|
|
|
|
|
async function processNodeLocationMetadata(
|
|
|
+ event: SubstrateEvent,
|
|
|
store: DatabaseManager,
|
|
|
current: NodeLocationMetadata | undefined,
|
|
|
meta: INodeLocationMetadata
|
|
|
): Promise<NodeLocationMetadata> {
|
|
|
- const nodeLocation = current || new NodeLocationMetadata()
|
|
|
+ const nodeLocation = current || new NodeLocationMetadata({ id: deterministicEntityId(event) })
|
|
|
if (isSet(meta.city)) {
|
|
|
nodeLocation.city = meta.city
|
|
|
}
|
|
@@ -45,7 +46,7 @@ async function processNodeLocationMetadata(
|
|
|
if (isEmptyObject(meta.coordinates)) {
|
|
|
nodeLocation.coordinates = null as any
|
|
|
} else {
|
|
|
- const coordinates = current?.coordinates || new GeoCoordinates()
|
|
|
+ const coordinates = current?.coordinates || new GeoCoordinates({ id: deterministicEntityId(event) })
|
|
|
coordinates.latitude = meta.coordinates.latitude || coordinates.latitude || 0
|
|
|
coordinates.longitude = meta.coordinates.longitude || coordinates.longitude || 0
|
|
|
await store.save<GeoCoordinates>(coordinates)
|
|
@@ -65,6 +66,7 @@ async function processNodeLocationMetadata(
|
|
|
}
|
|
|
|
|
|
export async function processDistributionOperatorMetadata(
|
|
|
+ event: SubstrateEvent,
|
|
|
store: DatabaseManager,
|
|
|
current: DistributionBucketOperatorMetadata | undefined,
|
|
|
metadataBytes: Bytes
|
|
@@ -73,14 +75,14 @@ export async function processDistributionOperatorMetadata(
|
|
|
if (!meta) {
|
|
|
return current
|
|
|
}
|
|
|
- const metadataEntity = current || new DistributionBucketOperatorMetadata()
|
|
|
+ const metadataEntity = current || new DistributionBucketOperatorMetadata({ id: deterministicEntityId(event) })
|
|
|
if (isSet(meta.endpoint)) {
|
|
|
metadataEntity.nodeEndpoint = meta.endpoint
|
|
|
}
|
|
|
if (isSet(meta.location)) {
|
|
|
metadataEntity.nodeLocation = isEmptyObject(meta.location)
|
|
|
? (null as any)
|
|
|
- : await processNodeLocationMetadata(store, metadataEntity.nodeLocation, meta.location)
|
|
|
+ : await processNodeLocationMetadata(event, store, metadataEntity.nodeLocation, meta.location)
|
|
|
}
|
|
|
if (isSet(meta.extra)) {
|
|
|
metadataEntity.extra = meta.extra
|
|
@@ -92,6 +94,7 @@ export async function processDistributionOperatorMetadata(
|
|
|
}
|
|
|
|
|
|
export async function processStorageOperatorMetadata(
|
|
|
+ event: SubstrateEvent,
|
|
|
store: DatabaseManager,
|
|
|
current: StorageBucketOperatorMetadata | undefined,
|
|
|
metadataBytes: Bytes
|
|
@@ -100,14 +103,14 @@ export async function processStorageOperatorMetadata(
|
|
|
if (!meta) {
|
|
|
return current
|
|
|
}
|
|
|
- const metadataEntity = current || new StorageBucketOperatorMetadata()
|
|
|
+ const metadataEntity = current || new StorageBucketOperatorMetadata({ id: deterministicEntityId(event) })
|
|
|
if (isSet(meta.endpoint)) {
|
|
|
metadataEntity.nodeEndpoint = meta.endpoint || (null as any)
|
|
|
}
|
|
|
if (isSet(meta.location)) {
|
|
|
metadataEntity.nodeLocation = isEmptyObject(meta.location)
|
|
|
? (null as any)
|
|
|
- : await processNodeLocationMetadata(store, metadataEntity.nodeLocation, meta.location)
|
|
|
+ : await processNodeLocationMetadata(event, store, metadataEntity.nodeLocation, meta.location)
|
|
|
}
|
|
|
if (isSet(meta.extra)) {
|
|
|
metadataEntity.extra = meta.extra || (null as any)
|
|
@@ -119,6 +122,7 @@ export async function processStorageOperatorMetadata(
|
|
|
}
|
|
|
|
|
|
export async function processDistributionBucketFamilyMetadata(
|
|
|
+ event: SubstrateEvent,
|
|
|
store: DatabaseManager,
|
|
|
current: DistributionBucketFamilyMetadata | undefined,
|
|
|
metadataBytes: Bytes
|
|
@@ -127,7 +131,7 @@ export async function processDistributionBucketFamilyMetadata(
|
|
|
if (!meta) {
|
|
|
return current
|
|
|
}
|
|
|
- const metadataEntity = current || new DistributionBucketFamilyMetadata()
|
|
|
+ const metadataEntity = current || new DistributionBucketFamilyMetadata({ id: deterministicEntityId(event) })
|
|
|
if (isSet(meta.region)) {
|
|
|
metadataEntity.region = meta.region || (null as any)
|
|
|
}
|
|
@@ -138,7 +142,7 @@ export async function processDistributionBucketFamilyMetadata(
|
|
|
metadataEntity.latencyTestTargets = meta.latencyTestTargets.filter((t) => t)
|
|
|
}
|
|
|
|
|
|
- await store.save<DistributionBucketOperatorMetadata>(metadataEntity)
|
|
|
+ await store.save<DistributionBucketFamilyMetadata>(metadataEntity)
|
|
|
|
|
|
// Update areas after metadata is saved (since we need an id to reference)
|
|
|
if (isSet(meta.areas)) {
|
|
@@ -161,9 +165,7 @@ export async function processDistributionBucketFamilyMetadata(
|
|
|
}
|
|
|
area.id = `${metadataEntity.id}-C-${continent.code}`
|
|
|
area.area = continent
|
|
|
- }
|
|
|
-
|
|
|
- if (a.countryCode) {
|
|
|
+ } else if (a.countryCode) {
|
|
|
if (!isValidCountryCode(a.countryCode)) {
|
|
|
return invalidMetadata(`Invalid country code: ${a.countryCode}`)
|
|
|
}
|
|
@@ -171,9 +173,7 @@ export async function processDistributionBucketFamilyMetadata(
|
|
|
country.code = a.countryCode
|
|
|
area.id = `${metadataEntity.id}-c-${country.code}`
|
|
|
area.area = country
|
|
|
- }
|
|
|
-
|
|
|
- if (a.subdivisionCode) {
|
|
|
+ } else if (a.subdivisionCode) {
|
|
|
if (!isValidSubdivisionCode(a.subdivisionCode)) {
|
|
|
return invalidMetadata(`Invalid subdivision code: ${a.subdivisionCode}`)
|
|
|
}
|
|
@@ -181,6 +181,8 @@ export async function processDistributionBucketFamilyMetadata(
|
|
|
subdivision.code = a.subdivisionCode
|
|
|
area.id = `${metadataEntity.id}-s-${subdivision.code}`
|
|
|
area.area = subdivision
|
|
|
+ } else {
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
await store.save<DistributionBucketFamilyGeographicArea>(area)
|