123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666 |
- /*
- eslint-disable @typescript-eslint/naming-convention
- */
- import { DatabaseManager, EventContext, StoreContext } from '@joystream/hydra-common'
- import { Storage } from '../generated/types/storage'
- import {
- DistributionBucket,
- DistributionBucketFamily,
- DistributionBucketOperator,
- DistributionBucketOperatorMetadata,
- DistributionBucketOperatorStatus,
- NodeLocationMetadata,
- StorageBag,
- StorageBagOwner,
- StorageBagOwnerChannel,
- StorageBagOwnerCouncil,
- StorageBagOwnerMember,
- StorageBagOwnerWorkingGroup,
- StorageBucket,
- StorageBucketOperatorStatusActive,
- StorageBucketOperatorStatusInvited,
- StorageBucketOperatorStatusMissing,
- StorageDataObject,
- StorageSystemParameters,
- GeoCoordinates,
- StorageBagDistributionAssignment,
- StorageBagStorageAssignment,
- } from 'query-node/dist/model'
- import BN from 'bn.js'
- import { getById } from '../common'
- import { BTreeSet } from '@polkadot/types'
- import { In } from 'typeorm'
- import _ from 'lodash'
- import { DataObjectId, BagId, DynamicBagId, StaticBagId } from '@joystream/types/augment/all'
- import {
- processDistributionBucketFamilyMetadata,
- processDistributionOperatorMetadata,
- processStorageOperatorMetadata,
- } from './metadata'
- import { createDataObjects, getStorageSystem, removeDataObject } from './utils'
- async function getDataObjectsInBag(
- store: DatabaseManager,
- bagId: BagId,
- dataObjectIds: BTreeSet<DataObjectId>
- ): Promise<StorageDataObject[]> {
- const dataObjects = await store.getMany(StorageDataObject, {
- where: {
- id: In(Array.from(dataObjectIds).map((id) => id.toString())),
- storageBag: { id: getBagId(bagId) },
- },
- })
- if (dataObjects.length !== Array.from(dataObjectIds).length) {
- throw new Error(
- `Missing data objects: ${_.difference(
- Array.from(dataObjectIds).map((id) => id.toString()),
- dataObjects.map((o) => o.id)
- )} in bag ${getBagId(bagId)}`
- )
- }
- return dataObjects
- }
- function getStaticBagOwner(bagId: StaticBagId): typeof StorageBagOwner {
- if (bagId.isCouncil) {
- return new StorageBagOwnerCouncil()
- } else if (bagId.isWorkingGroup) {
- const owner = new StorageBagOwnerWorkingGroup()
- owner.workingGroupId = bagId.asWorkingGroup.toString().toLowerCase()
- return owner
- } else {
- throw new Error(`Unexpected static bag type: ${bagId.type}`)
- }
- }
- function getDynamicBagOwner(bagId: DynamicBagId) {
- if (bagId.isChannel) {
- const owner = new StorageBagOwnerChannel()
- owner.channelId = bagId.asChannel.toNumber()
- return owner
- } else if (bagId.isMember) {
- const owner = new StorageBagOwnerMember()
- owner.memberId = bagId.asMember.toNumber()
- return owner
- } else {
- throw new Error(`Unexpected dynamic bag type: ${bagId.type}`)
- }
- }
- function getStaticBagId(bagId: StaticBagId): string {
- if (bagId.isCouncil) {
- return `static:council`
- } else if (bagId.isWorkingGroup) {
- return `static:wg:${bagId.asWorkingGroup.type.toLowerCase()}`
- } else {
- throw new Error(`Unexpected static bag type: ${bagId.type}`)
- }
- }
- function getDynamicBagId(bagId: DynamicBagId): string {
- if (bagId.isChannel) {
- return `dynamic:channel:${bagId.asChannel.toString()}`
- } else if (bagId.isMember) {
- return `dynamic:member:${bagId.asMember.toString()}`
- } else {
- throw new Error(`Unexpected dynamic bag type: ${bagId.type}`)
- }
- }
- function getBagId(bagId: BagId) {
- return bagId.isStatic ? getStaticBagId(bagId.asStatic) : getDynamicBagId(bagId.asDynamic)
- }
- async function getDynamicBag(
- store: DatabaseManager,
- bagId: DynamicBagId,
- relations?: 'objects'[]
- ): Promise<StorageBag> {
- return getById(store, StorageBag, getDynamicBagId(bagId), relations)
- }
- async function getStaticBag(store: DatabaseManager, bagId: StaticBagId, relations?: 'objects'[]): Promise<StorageBag> {
- const id = getStaticBagId(bagId)
- const bag = await store.get(StorageBag, { where: { id }, relations })
- if (!bag) {
- console.log(`Creating new static bag: ${id}`)
- const newBag = new StorageBag({
- id,
- owner: getStaticBagOwner(bagId),
- })
- await store.save<StorageBag>(newBag)
- return newBag
- }
- return bag
- }
- async function getBag(store: DatabaseManager, bagId: BagId, relations?: 'objects'[]): Promise<StorageBag> {
- return bagId.isStatic
- ? getStaticBag(store, bagId.asStatic, relations)
- : getDynamicBag(store, bagId.asDynamic, relations)
- }
- async function getDistributionBucketOperatorWithMetadata(
- store: DatabaseManager,
- id: string
- ): Promise<DistributionBucketOperator> {
- const operator = await store.get(DistributionBucketOperator, {
- where: { id },
- relations: ['metadata', 'metadata.nodeLocation', 'metadata.nodeLocation.coordinates'],
- })
- if (!operator) {
- throw new Error(`DistributionBucketOperator not found by id: ${id}`)
- }
- return operator
- }
- async function getStorageBucketWithOperatorMetadata(store: DatabaseManager, id: string): Promise<StorageBucket> {
- const bucket = await store.get(StorageBucket, {
- where: { id },
- relations: ['operatorMetadata', 'operatorMetadata.nodeLocation', 'operatorMetadata.nodeLocation.coordinates'],
- })
- if (!bucket) {
- throw new Error(`StorageBucket not found by id: ${id}`)
- }
- return bucket
- }
- async function getDistributionBucketFamilyWithMetadata(
- store: DatabaseManager,
- id: string
- ): Promise<DistributionBucketFamily> {
- const family = await store.get(DistributionBucketFamily, {
- where: { id },
- relations: ['metadata', 'metadata.areas'],
- })
- if (!family) {
- throw new Error(`DistributionBucketFamily not found by id: ${id}`)
- }
- return family
- }
- // STORAGE BUCKETS
- export async function storage_StorageBucketCreated({ event, store }: EventContext & StoreContext): Promise<void> {
- const [
- bucketId,
- invitedWorkerId,
- acceptingNewBags,
- dataObjectSizeLimit,
- dataObjectCountLimit,
- ] = new Storage.StorageBucketCreatedEvent(event).params
- const storageBucket = new StorageBucket({
- id: bucketId.toString(),
- acceptingNewBags: acceptingNewBags.isTrue,
- dataObjectCountLimit: new BN(dataObjectCountLimit.toString()),
- dataObjectsSizeLimit: new BN(dataObjectSizeLimit.toString()),
- dataObjectsCount: new BN(0),
- dataObjectsSize: new BN(0),
- })
- if (invitedWorkerId.isSome) {
- const operatorStatus = new StorageBucketOperatorStatusInvited()
- operatorStatus.workerId = invitedWorkerId.unwrap().toNumber()
- storageBucket.operatorStatus = operatorStatus
- } else {
- storageBucket.operatorStatus = new StorageBucketOperatorStatusMissing()
- }
- await store.save<StorageBucket>(storageBucket)
- }
- export async function storage_StorageOperatorMetadataSet({ event, store }: EventContext & StoreContext): Promise<void> {
- const [bucketId, , metadataBytes] = new Storage.StorageOperatorMetadataSetEvent(event).params
- const storageBucket = await getStorageBucketWithOperatorMetadata(store, bucketId.toString())
- storageBucket.operatorMetadata = await processStorageOperatorMetadata(
- store,
- storageBucket.operatorMetadata,
- metadataBytes
- )
- await store.save<StorageBucket>(storageBucket)
- }
- export async function storage_StorageBucketStatusUpdated({ event, store }: EventContext & StoreContext): Promise<void> {
- const [bucketId, acceptingNewBags] = new Storage.StorageBucketStatusUpdatedEvent(event).params
- const storageBucket = await getById(store, StorageBucket, bucketId.toString())
- storageBucket.acceptingNewBags = acceptingNewBags.isTrue
- await store.save<StorageBucket>(storageBucket)
- }
- export async function storage_StorageBucketInvitationAccepted({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [bucketId, workerId] = new Storage.StorageBucketInvitationAcceptedEvent(event).params
- const storageBucket = await getById(store, StorageBucket, bucketId.toString())
- const operatorStatus = new StorageBucketOperatorStatusActive()
- operatorStatus.workerId = workerId.toNumber()
- storageBucket.operatorStatus = operatorStatus
- await store.save<StorageBucket>(storageBucket)
- }
- export async function storage_StorageBucketInvitationCancelled({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [bucketId] = new Storage.StorageBucketInvitationCancelledEvent(event).params
- const storageBucket = await getById(store, StorageBucket, bucketId.toString())
- const operatorStatus = new StorageBucketOperatorStatusMissing()
- storageBucket.operatorStatus = operatorStatus
- await store.save<StorageBucket>(storageBucket)
- }
- export async function storage_StorageBucketOperatorInvited({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [bucketId, workerId] = new Storage.StorageBucketOperatorInvitedEvent(event).params
- const storageBucket = await getById(store, StorageBucket, bucketId.toString())
- const operatorStatus = new StorageBucketOperatorStatusInvited()
- operatorStatus.workerId = workerId.toNumber()
- storageBucket.operatorStatus = operatorStatus
- await store.save<StorageBucket>(storageBucket)
- }
- export async function storage_StorageBucketOperatorRemoved({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [bucketId] = new Storage.StorageBucketInvitationCancelledEvent(event).params
- const storageBucket = await getById(store, StorageBucket, bucketId.toString())
- const operatorStatus = new StorageBucketOperatorStatusMissing()
- storageBucket.operatorStatus = operatorStatus
- await store.save<StorageBucket>(storageBucket)
- }
- export async function storage_StorageBucketsUpdatedForBag({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [bagId, addedBucketsIds, removedBucketsIds] = new Storage.StorageBucketsUpdatedForBagEvent(event).params
- // Get or create bag
- const storageBag = await getBag(store, bagId)
- const assignmentsToRemove = await store.getMany(StorageBagStorageAssignment, {
- where: {
- storageBag,
- storageBucket: { id: In(Array.from(removedBucketsIds).map((bucketId) => bucketId.toString())) },
- },
- })
- const assignmentsToAdd = Array.from(addedBucketsIds).map(
- (bucketId) =>
- new StorageBagStorageAssignment({
- id: `${storageBag.id}-${bucketId.toString()}`,
- storageBag,
- storageBucket: new StorageBucket({ id: bucketId.toString() }),
- })
- )
- await Promise.all(assignmentsToRemove.map((a) => store.remove<StorageBagStorageAssignment>(a)))
- await Promise.all(assignmentsToAdd.map((a) => store.save<StorageBagStorageAssignment>(a)))
- }
- export async function storage_VoucherChanged({ event, store }: EventContext & StoreContext): Promise<void> {
- const [bucketId, voucher] = new Storage.VoucherChangedEvent(event).params
- const bucket = await getById(store, StorageBucket, bucketId.toString())
- bucket.dataObjectCountLimit = voucher.objectsLimit
- bucket.dataObjectsSizeLimit = voucher.sizeLimit
- bucket.dataObjectsCount = voucher.objectsUsed
- bucket.dataObjectsSize = voucher.sizeUsed
- await store.save<StorageBucket>(bucket)
- }
- export async function storage_StorageBucketVoucherLimitsSet({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [bucketId, sizeLimit, countLimit] = new Storage.StorageBucketVoucherLimitsSetEvent(event).params
- const bucket = await getById(store, StorageBucket, bucketId.toString())
- bucket.dataObjectsSizeLimit = sizeLimit
- bucket.dataObjectCountLimit = countLimit
- await store.save<StorageBucket>(bucket)
- }
- export async function storage_StorageBucketDeleted({ event, store }: EventContext & StoreContext): Promise<void> {
- const [bucketId] = new Storage.StorageBucketDeletedEvent(event).params
- // TODO: Cascade remove on db level (would require changes in Hydra / comitting autogenerated files)
- const assignments = await store.getMany(StorageBagStorageAssignment, {
- where: { storageBucket: { id: bucketId.toString() } },
- })
- await Promise.all(assignments.map((a) => store.remove<StorageBagStorageAssignment>(a)))
- await store.remove<StorageBucket>(new StorageBucket({ id: bucketId.toString() }))
- }
- // DYNAMIC BAGS
- export async function storage_DynamicBagCreated({ event, store }: EventContext & StoreContext): Promise<void> {
- const [bagId, , storageBucketIdsSet, distributionBucketIdsSet] = new Storage.DynamicBagCreatedEvent(event).params
- const storageBag = new StorageBag({
- id: getDynamicBagId(bagId),
- owner: getDynamicBagOwner(bagId),
- })
- const storageAssignments = Array.from(storageBucketIdsSet).map(
- (bucketId) =>
- new StorageBagStorageAssignment({
- id: `${storageBag.id}-${bucketId.toString()}`,
- storageBag,
- storageBucket: new StorageBucket({ id: bucketId.toString() }),
- })
- )
- const distributionAssignments = Array.from(distributionBucketIdsSet).map(
- (bucketId) =>
- new StorageBagDistributionAssignment({
- id: `${storageBag.id}-${bucketId.toString()}`,
- storageBag,
- distributionBucket: new DistributionBucket({ id: bucketId.toString() }),
- })
- )
- await store.save<StorageBag>(storageBag)
- await Promise.all(storageAssignments.map((a) => store.save<StorageBagStorageAssignment>(a)))
- await Promise.all(distributionAssignments.map((a) => store.save<StorageBagDistributionAssignment>(a)))
- }
- export async function storage_DynamicBagDeleted({ event, store }: EventContext & StoreContext): Promise<void> {
- const [, bagId] = new Storage.DynamicBagDeletedEvent(event).params
- const storageBag = await getDynamicBag(store, bagId, ['objects'])
- // The bag should already be empty, so no cascade-remove required
- await store.remove<StorageBag>(storageBag)
- }
- // DATA OBJECTS
- // Note: "Uploaded" here actually means "created" (the real upload happens later)
- export async function storage_DataObjectsUploaded({ event, store }: EventContext & StoreContext): Promise<void> {
- const [dataObjectIds, uploadParams] = new Storage.DataObjectsUploadedEvent(event).params
- const { bagId, objectCreationList } = uploadParams
- const storageBag = await getBag(store, bagId)
- await createDataObjects(store, objectCreationList, storageBag, dataObjectIds)
- }
- export async function storage_PendingDataObjectsAccepted({ event, store }: EventContext & StoreContext): Promise<void> {
- const [, , bagId, dataObjectIds] = new Storage.PendingDataObjectsAcceptedEvent(event).params
- const dataObjects = await getDataObjectsInBag(store, bagId, dataObjectIds)
- await Promise.all(
- dataObjects.map(async (dataObject) => {
- dataObject.isAccepted = true
- await store.save<StorageDataObject>(dataObject)
- })
- )
- }
- export async function storage_DataObjectsMoved({ event, store }: EventContext & StoreContext): Promise<void> {
- const [srcBagId, destBagId, dataObjectIds] = new Storage.DataObjectsMovedEvent(event).params
- const dataObjects = await getDataObjectsInBag(store, srcBagId, dataObjectIds)
- const destBag = await getBag(store, destBagId)
- await Promise.all(
- dataObjects.map(async (dataObject) => {
- dataObject.storageBag = destBag
- await store.save<StorageDataObject>(dataObject)
- })
- )
- }
- export async function storage_DataObjectsDeleted({ event, store }: EventContext & StoreContext): Promise<void> {
- const [, bagId, dataObjectIds] = new Storage.DataObjectsDeletedEvent(event).params
- const dataObjects = await getDataObjectsInBag(store, bagId, dataObjectIds)
- await Promise.all(dataObjects.map((o) => removeDataObject(store, o)))
- }
- // DISTRIBUTION FAMILY
- export async function storage_DistributionBucketFamilyCreated({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [familyId] = new Storage.DistributionBucketFamilyCreatedEvent(event).params
- const family = new DistributionBucketFamily({
- id: familyId.toString(),
- })
- await store.save<DistributionBucketFamily>(family)
- }
- export async function storage_DistributionBucketFamilyMetadataSet({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [familyId, metadataBytes] = new Storage.DistributionBucketFamilyMetadataSetEvent(event).params
- const family = await getDistributionBucketFamilyWithMetadata(store, familyId.toString())
- family.metadata = await processDistributionBucketFamilyMetadata(store, family.metadata, metadataBytes)
- await store.save<DistributionBucketFamily>(family)
- }
- export async function storage_DistributionBucketFamilyDeleted({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [familyId] = new Storage.DistributionBucketFamilyDeletedEvent(event).params
- const family = await getById(store, DistributionBucketFamily, familyId.toString())
- await store.remove(family)
- }
- // DISTRIBUTION BUCKET
- export async function storage_DistributionBucketCreated({ event, store }: EventContext & StoreContext): Promise<void> {
- const [familyId, acceptingNewBags, bucketId] = new Storage.DistributionBucketCreatedEvent(event).params
- const family = await getById(store, DistributionBucketFamily, familyId.toString())
- const bucket = new DistributionBucket({
- id: bucketId.toString(),
- acceptingNewBags: acceptingNewBags.valueOf(),
- distributing: true, // Runtime default
- family,
- })
- await store.save<DistributionBucket>(bucket)
- }
- export async function storage_DistributionBucketStatusUpdated({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [, bucketId, acceptingNewBags] = new Storage.DistributionBucketStatusUpdatedEvent(event).params
- const bucket = await getById(store, DistributionBucket, bucketId.toString())
- bucket.acceptingNewBags = acceptingNewBags.valueOf()
- await store.save<DistributionBucket>(bucket)
- }
- export async function storage_DistributionBucketDeleted({ event, store }: EventContext & StoreContext): Promise<void> {
- const [, bucketId] = new Storage.DistributionBucketDeletedEvent(event).params
- // TODO: Cascade remove on db level (would require changes in Hydra / comitting autogenerated files)
- const assignments = await store.getMany(StorageBagDistributionAssignment, {
- where: { distributionBucket: { id: bucketId.toString() } },
- })
- await Promise.all(assignments.map((a) => store.remove<StorageBagDistributionAssignment>(a)))
- await store.remove<DistributionBucket>(new DistributionBucket({ id: bucketId.toString() }))
- }
- export async function storage_DistributionBucketsUpdatedForBag({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [bagId, , addedBucketsIds, removedBucketsIds] = new Storage.DistributionBucketsUpdatedForBagEvent(event).params
- // Get or create bag
- const storageBag = await getBag(store, bagId)
- const assignmentsToRemove = await store.getMany(StorageBagDistributionAssignment, {
- where: {
- storageBag,
- distributionBucket: { id: In(Array.from(removedBucketsIds).map((bucketId) => bucketId.toString())) },
- },
- })
- const assignmentsToAdd = Array.from(addedBucketsIds).map(
- (bucketId) =>
- new StorageBagDistributionAssignment({
- id: `${storageBag.id}-${bucketId.toString()}`,
- storageBag,
- distributionBucket: new DistributionBucket({ id: bucketId.toString() }),
- })
- )
- await Promise.all(assignmentsToRemove.map((a) => store.remove<StorageBagDistributionAssignment>(a)))
- await Promise.all(assignmentsToAdd.map((a) => store.save<StorageBagDistributionAssignment>(a)))
- }
- export async function storage_DistributionBucketModeUpdated({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [, bucketId, distributing] = new Storage.DistributionBucketModeUpdatedEvent(event).params
- const bucket = await getById(store, DistributionBucket, bucketId.toString())
- bucket.distributing = distributing.valueOf()
- await store.save<DistributionBucket>(bucket)
- }
- export async function storage_DistributionBucketOperatorInvited({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [, bucketId, workerId] = new Storage.DistributionBucketOperatorInvitedEvent(event).params
- const bucket = await getById(store, DistributionBucket, bucketId.toString())
- const invitedOperator = new DistributionBucketOperator({
- id: `${bucketId}-${workerId}`,
- distributionBucket: bucket,
- status: DistributionBucketOperatorStatus.INVITED,
- workerId: workerId.toNumber(),
- })
- await store.save<DistributionBucketOperator>(invitedOperator)
- }
- export async function storage_DistributionBucketInvitationCancelled({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [, bucketId, workerId] = new Storage.DistributionBucketOperatorInvitedEvent(event).params
- const invitedOperator = await getById(store, DistributionBucketOperator, `${bucketId}-${workerId}`)
- await store.remove<DistributionBucketOperator>(invitedOperator)
- }
- export async function storage_DistributionBucketInvitationAccepted({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [workerId, , bucketId] = new Storage.DistributionBucketInvitationAcceptedEvent(event).params
- const invitedOperator = await getById(store, DistributionBucketOperator, `${bucketId}-${workerId}`)
- invitedOperator.status = DistributionBucketOperatorStatus.ACTIVE
- await store.save<DistributionBucketOperator>(invitedOperator)
- }
- export async function storage_DistributionBucketMetadataSet({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [workerId, , bucketId, metadataBytes] = new Storage.DistributionBucketMetadataSetEvent(event).params
- const operator = await getDistributionBucketOperatorWithMetadata(store, `${bucketId}-${workerId}`)
- operator.metadata = await processDistributionOperatorMetadata(store, operator.metadata, metadataBytes)
- await store.save<DistributionBucketOperator>(operator)
- }
- export async function storage_DistributionBucketOperatorRemoved({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [, bucketId, workerId] = new Storage.DistributionBucketOperatorRemovedEvent(event).params
- // TODO: Cascade remove on db level (would require changes in Hydra / comitting autogenerated files)
- const operator = await getDistributionBucketOperatorWithMetadata(store, `${bucketId}-${workerId}`)
- await store.remove<DistributionBucketOperator>(operator)
- if (operator.metadata) {
- await store.remove<DistributionBucketOperatorMetadata>(operator.metadata)
- if (operator.metadata.nodeLocation) {
- await store.remove<NodeLocationMetadata>(operator.metadata.nodeLocation)
- if (operator.metadata.nodeLocation.coordinates) {
- await store.remove<GeoCoordinates>(operator.metadata.nodeLocation.coordinates)
- }
- }
- }
- }
- // STORAGE SYSTEM GLOBAL PARAMS
- export async function storage_UpdateBlacklist({ event, store }: EventContext & StoreContext): Promise<void> {
- const [removedContentIds, addedContentIds] = new Storage.UpdateBlacklistEvent(event).params
- const storageSystem = await getStorageSystem(store)
- storageSystem.blacklist = storageSystem.blacklist
- .filter((cid) => !Array.from(removedContentIds).some((id) => id.eq(cid)))
- .concat(Array.from(addedContentIds).map((id) => id.toString()))
- await store.save<StorageSystemParameters>(storageSystem)
- }
- export async function storage_DistributionBucketsPerBagLimitUpdated({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [newLimit] = new Storage.DistributionBucketsPerBagLimitUpdatedEvent(event).params
- const storageSystem = await getStorageSystem(store)
- storageSystem.distributionBucketsPerBagLimit = newLimit.toNumber()
- await store.save<StorageSystemParameters>(storageSystem)
- }
- export async function storage_StorageBucketsPerBagLimitUpdated({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [newLimit] = new Storage.StorageBucketsPerBagLimitUpdatedEvent(event).params
- const storageSystem = await getStorageSystem(store)
- storageSystem.storageBucketsPerBagLimit = newLimit.toNumber()
- await store.save<StorageSystemParameters>(storageSystem)
- }
- export async function storage_StorageBucketsVoucherMaxLimitsUpdated({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [sizeLimit, countLimit] = new Storage.StorageBucketsVoucherMaxLimitsUpdatedEvent(event).params
- const storageSystem = await getStorageSystem(store)
- storageSystem.storageBucketMaxObjectsSizeLimit = sizeLimit
- storageSystem.storageBucketMaxObjectsCountLimit = countLimit
- await store.save<StorageSystemParameters>(storageSystem)
- }
- export async function storage_UploadingBlockStatusUpdated({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [isBlocked] = new Storage.UploadingBlockStatusUpdatedEvent(event).params
- const storageSystem = await getStorageSystem(store)
- storageSystem.uploadingBlocked = isBlocked.isTrue
- await store.save<StorageSystemParameters>(storageSystem)
- }
- export async function storage_DataObjectPerMegabyteFeeUpdated({
- event,
- store,
- }: EventContext & StoreContext): Promise<void> {
- const [newFee] = new Storage.DataObjectPerMegabyteFeeUpdatedEvent(event).params
- const storageSystem = await getStorageSystem(store)
- storageSystem.dataObjectFeePerMb = newFee
- await store.save<StorageSystemParameters>(storageSystem)
- }
|