|
@@ -6,6 +6,21 @@ import { ApiPromise } from '@polkadot/api'
|
|
|
import { BagId, DynamicBagType } from '@joystream/types/storage'
|
|
|
import logger from '../../services/logger'
|
|
|
|
|
|
+/**
|
|
|
+ * Creates storage bucket.
|
|
|
+ *
|
|
|
+ * @remarks
|
|
|
+ * It sends an extrinsic to the runtime.
|
|
|
+ *
|
|
|
+ * @param api - runtime API promise
|
|
|
+ * @param account - KeyringPair instance
|
|
|
+ * @param invitedWorker - defines whether the storage provider should be
|
|
|
+ * invited on the bucket creation (optional)
|
|
|
+ * @param allowedNewBags - bucket allows new bag assignments
|
|
|
+ * @param sizeLimit - size limit in bytes for the new bucket (default 0)
|
|
|
+ * @param objectsLimit - object number limit for the new bucket (default 0)
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
export async function createStorageBucket(
|
|
|
api: ApiPromise,
|
|
|
account: KeyringPair,
|
|
@@ -27,6 +42,18 @@ export async function createStorageBucket(
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Accepts the storage provider invitation for a bucket.
|
|
|
+ *
|
|
|
+ * @remarks
|
|
|
+ * It sends an extrinsic to the runtime.
|
|
|
+ *
|
|
|
+ * @param api - runtime API promise
|
|
|
+ * @param account - KeyringPair instance
|
|
|
+ * @param workerId - runtime storage provider ID (worker ID)
|
|
|
+ * @param storageBucketId - runtime storage bucket ID
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
export async function acceptStorageBucketInvitation(
|
|
|
api: ApiPromise,
|
|
|
account: KeyringPair,
|
|
@@ -44,6 +71,20 @@ export async function acceptStorageBucketInvitation(
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Updates storage bucket to bags relationships.
|
|
|
+ *
|
|
|
+ * @remarks
|
|
|
+ * It sends an extrinsic to the runtime.
|
|
|
+ *
|
|
|
+ * @param api - runtime API promise
|
|
|
+ * @param bagId - BagId instance
|
|
|
+ * @param account - KeyringPair instance
|
|
|
+ * @param bucketId - runtime storage bucket ID
|
|
|
+ * @param removeBucket - defines whether to remove bucket. If set to false
|
|
|
+ * the bucket will be added instead.
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
export async function updateStorageBucketsForBag(
|
|
|
api: ApiPromise,
|
|
|
bagId: BagId,
|
|
@@ -71,6 +112,18 @@ export async function updateStorageBucketsForBag(
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Uploads a data object info.
|
|
|
+ *
|
|
|
+ * @remarks
|
|
|
+ * It sends an extrinsic to the runtime.
|
|
|
+ *
|
|
|
+ * @param api - runtime API promise
|
|
|
+ * @param account - KeyringPair instance
|
|
|
+ * @param objectSize - object size in bytes
|
|
|
+ * @param objectCid - object CID (Content ID - multihash)
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
export async function uploadDataObjects(
|
|
|
api: ApiPromise,
|
|
|
objectSize: number,
|
|
@@ -99,6 +152,20 @@ export async function uploadDataObjects(
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Accepts pending data objects by storage provider.
|
|
|
+ *
|
|
|
+ * @remarks
|
|
|
+ * It sends an extrinsic to the runtime.
|
|
|
+ *
|
|
|
+ * @param api - runtime API promise
|
|
|
+ * @param bagId - BagId instance
|
|
|
+ * @param account - KeyringPair instance
|
|
|
+ * @param workerId - runtime storage provider ID (worker ID)
|
|
|
+ * @param storageBucketId - runtime storage bucket ID
|
|
|
+ * @param dataObjects - runtime data objects IDs
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
export async function acceptPendingDataObjects(
|
|
|
api: ApiPromise,
|
|
|
bagId: BagId,
|
|
@@ -123,6 +190,17 @@ export async function acceptPendingDataObjects(
|
|
|
}, true)
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Updates a 'StorageBucketsPerBag' limit.
|
|
|
+ *
|
|
|
+ * @remarks
|
|
|
+ * It sends an extrinsic to the runtime.
|
|
|
+ *
|
|
|
+ * @param api - runtime API promise
|
|
|
+ * @param bagId - BagId instance
|
|
|
+ * @param newLimit - new limit
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
export async function updateStorageBucketsPerBagLimit(
|
|
|
api: ApiPromise,
|
|
|
account: KeyringPair,
|
|
@@ -139,6 +217,18 @@ export async function updateStorageBucketsPerBagLimit(
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Updates a 'StorageBucketsVoucherMaxLimits' variables.
|
|
|
+ *
|
|
|
+ * @remarks
|
|
|
+ * It sends an extrinsic to the runtime.
|
|
|
+ *
|
|
|
+ * @param api - runtime API promise
|
|
|
+ * @param bagId - BagId instance
|
|
|
+ * @param newSizeLimit - new size limit
|
|
|
+ * @param newObjectLimit - new object limit
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
export async function updateStorageBucketsVoucherMaxLimits(
|
|
|
api: ApiPromise,
|
|
|
account: KeyringPair,
|
|
@@ -156,6 +246,17 @@ export async function updateStorageBucketsVoucherMaxLimits(
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Deletes a storage bucket.
|
|
|
+ *
|
|
|
+ * @remarks
|
|
|
+ * It sends an extrinsic to the runtime.
|
|
|
+ *
|
|
|
+ * @param api - runtime API promise
|
|
|
+ * @param account - KeyringPair instance
|
|
|
+ * @param bucketId - runtime storage bucket ID
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
export async function deleteStorageBucket(
|
|
|
api: ApiPromise,
|
|
|
account: KeyringPair,
|
|
@@ -168,6 +269,18 @@ export async function deleteStorageBucket(
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Invites a storage provider for a bucket.
|
|
|
+ *
|
|
|
+ * @remarks
|
|
|
+ * It sends an extrinsic to the runtime.
|
|
|
+ *
|
|
|
+ * @param api - runtime API promise
|
|
|
+ * @param account - KeyringPair instance
|
|
|
+ * @param bucketId - runtime storage bucket ID
|
|
|
+ * @param operatorId - runtime storage operator ID (worker ID)
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
export async function inviteStorageBucketOperator(
|
|
|
api: ApiPromise,
|
|
|
account: KeyringPair,
|
|
@@ -185,6 +298,14 @@ export async function inviteStorageBucketOperator(
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Helper-function. It catches the error, logs it and returns a success flag.
|
|
|
+ *
|
|
|
+ * @param extrinsic - extrinsic promise
|
|
|
+ * @param throwErr - disables the default error catch and rethrows an error
|
|
|
+ * after logging.
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
async function extrinsicWrapper(
|
|
|
extrinsic: () => Promise<void>,
|
|
|
throwErr = false
|
|
@@ -203,6 +324,17 @@ async function extrinsicWrapper(
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Cancels the invite for the storage provider.
|
|
|
+ *
|
|
|
+ * @remarks
|
|
|
+ * It sends an extrinsic to the runtime.
|
|
|
+ *
|
|
|
+ * @param api - runtime API promise
|
|
|
+ * @param account - KeyringPair instance
|
|
|
+ * @param bucketId - runtime storage bucket ID
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
export async function cancelStorageBucketOperatorInvite(
|
|
|
api: ApiPromise,
|
|
|
account: KeyringPair,
|
|
@@ -219,6 +351,17 @@ export async function cancelStorageBucketOperatorInvite(
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Removes a storage provider association with a bucket.
|
|
|
+ *
|
|
|
+ * @remarks
|
|
|
+ * It sends an extrinsic to the runtime.
|
|
|
+ *
|
|
|
+ * @param api - runtime API promise
|
|
|
+ * @param account - KeyringPair instance
|
|
|
+ * @param bucketId - runtime storage bucket ID
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
export async function removeStorageBucketOperator(
|
|
|
api: ApiPromise,
|
|
|
account: KeyringPair,
|
|
@@ -235,6 +378,17 @@ export async function removeStorageBucketOperator(
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Updates a 'DataSizeFee' variable.
|
|
|
+ *
|
|
|
+ * @remarks
|
|
|
+ * It sends an extrinsic to the runtime.
|
|
|
+ *
|
|
|
+ * @param api - runtime API promise
|
|
|
+ * @param bagId - BagId instance
|
|
|
+ * @param fee - new fee
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
export async function updateDataSizeFee(
|
|
|
api: ApiPromise,
|
|
|
account: KeyringPair,
|
|
@@ -245,6 +399,19 @@ export async function updateDataSizeFee(
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Sets a metadata for the storage provider.
|
|
|
+ *
|
|
|
+ * @remarks
|
|
|
+ * It sends an extrinsic to the runtime.
|
|
|
+ *
|
|
|
+ * @param api - runtime API promise
|
|
|
+ * @param account - KeyringPair instance
|
|
|
+ * @param operatorId - runtime storage operator ID (worker ID)
|
|
|
+ * @param bucketId - runtime storage bucket ID
|
|
|
+ * @param metadata - new metadata
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
export async function setStorageOperatorMetadata(
|
|
|
api: ApiPromise,
|
|
|
account: KeyringPair,
|
|
@@ -263,6 +430,17 @@ export async function setStorageOperatorMetadata(
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Updates the 'UploadingBlocked' variable.
|
|
|
+ *
|
|
|
+ * @remarks
|
|
|
+ * It sends an extrinsic to the runtime.
|
|
|
+ *
|
|
|
+ * @param api - runtime API promise
|
|
|
+ * @param account - KeyringPair instance
|
|
|
+ * @param newStatus - new block status
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
export async function updateUploadingBlockedStatus(
|
|
|
api: ApiPromise,
|
|
|
account: KeyringPair,
|
|
@@ -279,6 +457,19 @@ export async function updateUploadingBlockedStatus(
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Updates the storage bucket status (whether it accepts new bags).
|
|
|
+ *
|
|
|
+ * @remarks
|
|
|
+ * It sends an extrinsic to the runtime.
|
|
|
+ *
|
|
|
+ * @param api - runtime API promise
|
|
|
+ * @param account - KeyringPair instance
|
|
|
+ * @param workerId - runtime storage provider ID (worker ID)
|
|
|
+ * @param storageBucketId - runtime storage bucket ID
|
|
|
+ * @param newStatus - new storage bucket status status (accepts new bag)
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
export async function updateStorageBucketStatus(
|
|
|
api: ApiPromise,
|
|
|
account: KeyringPair,
|
|
@@ -295,6 +486,20 @@ export async function updateStorageBucketStatus(
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Updates a 'StorageBucketVoucherLimits' variable for a storage bucket.
|
|
|
+ *
|
|
|
+ * @remarks
|
|
|
+ * It sends an extrinsic to the runtime.
|
|
|
+ *
|
|
|
+ * @param api - runtime API promise
|
|
|
+ * @param account - KeyringPair instance
|
|
|
+ * @param workerId - runtime storage provider ID (worker ID)
|
|
|
+ * @param storageBucketId - runtime storage bucket ID
|
|
|
+ * @param newSizeLimit - new size limit
|
|
|
+ * @param newObjectLimit - new object limit
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
export async function setStorageBucketVoucherLimits(
|
|
|
api: ApiPromise,
|
|
|
account: KeyringPair,
|
|
@@ -314,6 +519,18 @@ export async function setStorageBucketVoucherLimits(
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Updates the number of storage buckets in the dynamic bag creation policy.
|
|
|
+ *
|
|
|
+ * @remarks
|
|
|
+ * It sends an extrinsic to the runtime.
|
|
|
+ *
|
|
|
+ * @param api - runtime API promise
|
|
|
+ * @param account - KeyringPair instance
|
|
|
+ * @param dynamicBagType - dynamic bag type
|
|
|
+ * @param newNumber - new number
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
export async function updateNumberOfStorageBucketsInDynamicBagCreationPolicy(
|
|
|
api: ApiPromise,
|
|
|
account: KeyringPair,
|
|
@@ -331,6 +548,19 @@ export async function updateNumberOfStorageBucketsInDynamicBagCreationPolicy(
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Updates the blacklist for the storage.
|
|
|
+ *
|
|
|
+ * @remarks
|
|
|
+ * It sends an extrinsic to the runtime.
|
|
|
+ *
|
|
|
+ * @param api - runtime API promise
|
|
|
+ * @param account - KeyringPair instance
|
|
|
+ * @param cid - content ID (multihash)
|
|
|
+ * @param removeCid - defines wether the cid should be removed from the cid,
|
|
|
+ * a cid is added when 'false'
|
|
|
+ * @returns promise with a success flag.
|
|
|
+ */
|
|
|
export async function updateBlacklist(
|
|
|
api: ApiPromise,
|
|
|
account: KeyringPair,
|