mappingsContent.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. import { SubstrateEvent } from '@dzlzv/hydra-common'
  2. import { DatabaseManager } from '@dzlzv/hydra-db-utils'
  3. // enums
  4. import { Network } from '../generated/graphql-server/src/modules/enums/enums'
  5. // input schema models
  6. import { Block } from '../generated/graphql-server/src/modules/block/block.model'
  7. import { Channel } from '../generated/graphql-server/src/modules/channel/channel.model'
  8. /////////////////// Content directory mappings /////////////////////////////////
  9. /* Template from hydra-cli scaffold (generated with the newer version 2.0.1-beta.0)
  10. export async function balancesTransfer(
  11. db: DatabaseManager,
  12. event_: SubstrateEvent
  13. ) {
  14. const transfer = new Transfer()
  15. transfer.from = Buffer.from(event.data.accountIds[0].toHex())
  16. transfer.to = Buffer.from(event.data.accountIds[1].toHex())
  17. transfer.value = event.data.balance.toBn()
  18. transfer.block = event.ctx.blockNumber
  19. transfer.comment = `Transferred ${transfer.value} from ${transfer.from} to ${transfer.to}`
  20. transfer.insertedAt = new Date()
  21. await db.save<Transfer>(transfer)
  22. }
  23. */
  24. const currentNetwork = Network.BABYLON
  25. enum ProtobufEntity {
  26. Channel,
  27. }
  28. function readProtobuf(type: ProtobufEntity, metadata: string) {
  29. // TODO: implement protobuf read operations
  30. // - see npm package `google-protobuf`
  31. // - read format from folder `content-metadata-protobuf/compiled/`
  32. // - parse `metadata`
  33. if (type == ProtobufEntity.Channel) {
  34. return {
  35. coverPhoto: undefined, // TODO: read from protobuf
  36. avatarPhoto: undefined, // TODO: read from protobuf
  37. isPublic: true, // TODO: read from protobuf
  38. language: undefined, // TODO: read language from protobuf and connect it with existing Language (if any)
  39. }
  40. }
  41. throw `Not implemented type: ${type}`
  42. }
  43. // temporary function used before proper block is retrieved
  44. function convertblockNumberToBlock(block: number): Block {
  45. return new Block({
  46. block: block,
  47. executedAt: new Date(), // TODO get real block execution time
  48. network: currentNetwork,
  49. })
  50. }
  51. // eslint-disable-next-line @typescript-eslint/naming-convention
  52. export async function content_ChannelCreated(db: DatabaseManager, event: SubstrateEvent): Promise<void> {
  53. /* event arguments
  54. ChannelId,
  55. ChannelOwner<MemberId, CuratorGroupId, DAOId>,
  56. Vec<NewAsset>,
  57. ChannelCreationParameters<ContentParameters>,
  58. */
  59. const protobufContent = readProtobuf(ProtobufEntity.Channel, (event.params[3] as any).meta) // TODO: get rid of `any` typecast
  60. // TODO
  61. const channel = new Channel({
  62. id: event.params[0].toString(), // ChannelId
  63. title: 'TODO handle', // TODO
  64. description: 'TODO description', // TODO
  65. isCensored: false, // TODO: where this value comes from?
  66. videos: [],
  67. happenedIn: convertblockNumberToBlock(event.blockNumber),
  68. ...protobufContent
  69. })
  70. await db.save<Channel>(channel)
  71. }
  72. // eslint-disable-next-line @typescript-eslint/naming-convention
  73. export async function content_ChannelUpdated(
  74. db: DatabaseManager,
  75. event: SubstrateEvent
  76. ) {
  77. // TODO
  78. }
  79. // eslint-disable-next-line @typescript-eslint/naming-convention
  80. export async function content_ChannelDeleted(
  81. db: DatabaseManager,
  82. event: SubstrateEvent
  83. ) {
  84. // TODO
  85. }
  86. // eslint-disable-next-line @typescript-eslint/naming-convention
  87. export async function content_ChannelCensored(
  88. db: DatabaseManager,
  89. event: SubstrateEvent
  90. ) {
  91. // TODO
  92. }
  93. // eslint-disable-next-line @typescript-eslint/naming-convention
  94. export async function content_ChannelUncensored(
  95. db: DatabaseManager,
  96. event: SubstrateEvent
  97. ) {
  98. // TODO
  99. }
  100. // eslint-disable-next-line @typescript-eslint/naming-convention
  101. export async function content_ChannelOwnershipTransferRequested(
  102. db: DatabaseManager,
  103. event: SubstrateEvent
  104. ) {
  105. // TODO
  106. }
  107. // eslint-disable-next-line @typescript-eslint/naming-convention
  108. export async function content_ChannelOwnershipTransferRequestWithdrawn(
  109. db: DatabaseManager,
  110. event: SubstrateEvent
  111. ) {
  112. // TODO
  113. }
  114. // eslint-disable-next-line @typescript-eslint/naming-convention
  115. export async function content_ChannelOwnershipTransferred(
  116. db: DatabaseManager,
  117. event: SubstrateEvent
  118. ) {
  119. // TODO
  120. }
  121. // eslint-disable-next-line @typescript-eslint/naming-convention
  122. export async function content_ChannelCategoryCreated(
  123. db: DatabaseManager,
  124. event: SubstrateEvent
  125. ) {
  126. // TODO
  127. }
  128. // eslint-disable-next-line @typescript-eslint/naming-convention
  129. export async function content_ChannelCategoryUpdated(
  130. db: DatabaseManager,
  131. event: SubstrateEvent
  132. ) {
  133. // TODO
  134. }
  135. // eslint-disable-next-line @typescript-eslint/naming-convention
  136. export async function content_ChannelCategoryDeleted(
  137. db: DatabaseManager,
  138. event: SubstrateEvent
  139. ) {
  140. // TODO
  141. }
  142. // eslint-disable-next-line @typescript-eslint/naming-convention
  143. export async function content_VideoCategoryCreated(
  144. db: DatabaseManager,
  145. event: SubstrateEvent
  146. ) {
  147. // TODO
  148. }
  149. // eslint-disable-next-line @typescript-eslint/naming-convention
  150. export async function content_VideoCategoryUpdated(
  151. db: DatabaseManager,
  152. event: SubstrateEvent
  153. ) {
  154. // TODO
  155. }
  156. // eslint-disable-next-line @typescript-eslint/naming-convention
  157. export async function content_VideoCategoryDeleted(
  158. db: DatabaseManager,
  159. event: SubstrateEvent
  160. ) {
  161. // TODO
  162. }
  163. // eslint-disable-next-line @typescript-eslint/naming-convention
  164. export async function content_VideoCreated(
  165. db: DatabaseManager,
  166. event: SubstrateEvent
  167. ) {
  168. // TODO
  169. }
  170. // eslint-disable-next-line @typescript-eslint/naming-convention
  171. export async function content_VideoUpdated(
  172. db: DatabaseManager,
  173. event: SubstrateEvent
  174. ) {
  175. // TODO
  176. }
  177. // eslint-disable-next-line @typescript-eslint/naming-convention
  178. export async function content_VideoDeleted(
  179. db: DatabaseManager,
  180. event: SubstrateEvent
  181. ) {
  182. // TODO
  183. }
  184. // eslint-disable-next-line @typescript-eslint/naming-convention
  185. export async function content_VideoCensored(
  186. db: DatabaseManager,
  187. event: SubstrateEvent
  188. ) {
  189. // TODO
  190. }
  191. // eslint-disable-next-line @typescript-eslint/naming-convention
  192. export async function content_VideoUncensored(
  193. db: DatabaseManager,
  194. event: SubstrateEvent
  195. ) {
  196. // TODO
  197. }
  198. // eslint-disable-next-line @typescript-eslint/naming-convention
  199. export async function content_FeaturedVideosSet(
  200. db: DatabaseManager,
  201. event: SubstrateEvent
  202. ) {
  203. // TODO
  204. }
  205. // eslint-disable-next-line @typescript-eslint/naming-convention
  206. export async function content_PlaylistCreated(
  207. db: DatabaseManager,
  208. event: SubstrateEvent
  209. ) {
  210. // TODO
  211. }
  212. // eslint-disable-next-line @typescript-eslint/naming-convention
  213. export async function content_PlaylistUpdated(
  214. db: DatabaseManager,
  215. event: SubstrateEvent
  216. ) {
  217. // TODO
  218. }
  219. // eslint-disable-next-line @typescript-eslint/naming-convention
  220. export async function content_PlaylistDeleted(
  221. db: DatabaseManager,
  222. event: SubstrateEvent
  223. ) {
  224. // TODO
  225. }