Skip to content

Commit

Permalink
fix: 🐛 encoding issues with member handle (#214)
Browse files Browse the repository at this point in the history
* fix: 🐛 encoding issues with member handle

* fix: 🐛 pr issues

* fix: 🐛 refactor and update changelog

* docs: update version number
  • Loading branch information
Ignazio Bovo authored Oct 30, 2023
1 parent c9f6e5a commit 4484149
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 136 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 3.0.2
### Bug Fixes:
- Store membership handles both as utf-8 string and raw bytes - [#4950](https://github.com/Joystream/joystream/pull/4950)
# 3.0.1
### Misc
- add migration for the `Account` id field
Expand Down

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orion",
"version": "3.0.1",
"version": "3.0.2",
"engines": {
"node": ">=16"
},
Expand Down
7 changes: 5 additions & 2 deletions schema/membership.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ type Membership @entity {
"Timestamp of the block the membership was created at"
createdAt: DateTime!

"The unique handle chosen by member"
handle: String! @unique
"The handle coming from decoded handleRaw if possible"
handle: String!

"The handle chosen by member coming from event deposit"
handleRaw: String! @unique

"Member's metadata"
metadata: MemberMetadata @derivedFrom(field: "member")
Expand Down
2 changes: 2 additions & 0 deletions src/auth-server/tests/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,13 @@ export async function signedAction<T extends components['schemas']['ActionExecut

async function insertFakeMember(controllerAccount: string) {
const em = await globalEm
const handle = uniqueId()
return em.getRepository(Membership).save({
createdAt: new Date(),
id: uniqueId(),
controllerAccount,
handle: uniqueId(),
handleRaw: '0x' + Buffer.from(handle).toString('hex'),
totalChannelsCreated: 0,
})
}
Expand Down
14 changes: 11 additions & 3 deletions src/mappings/membership/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { u8aToHex } from '@polkadot/util'
import {
Event,
Membership,
Expand All @@ -20,16 +21,18 @@ export async function processNewMember({
| 'Members.MembershipGifted'
>) {
const [memberId, params] = 'isV2001' in event && event.isV2001 ? event.asV2001 : event.asV1000
const { controllerAccount, handle, metadata: metadataBytes } = params
const { controllerAccount, handle: handleBytes, metadata: metadataBytes } = params
const metadata = deserializeMetadata(MembershipMetadata, metadataBytes)

const member = overlay.getRepository(Membership).new({
createdAt: new Date(block.timestamp),
id: memberId.toString(),
controllerAccount: toAddress(controllerAccount),
handle: handle && bytesToString(handle),
totalChannelsCreated: 0,
})
if (handleBytes) {
updateMemberHandle(member as Membership, handleBytes)
}

if (metadata) {
await processMembershipMetadata(overlay, member.id, metadata)
Expand Down Expand Up @@ -57,7 +60,7 @@ export async function processMemberProfileUpdatedEvent({
const member = await overlay.getRepository(Membership).getByIdOrFail(memberId.toString())

if (newHandle) {
member.handle = newHandle.toString()
updateMemberHandle(member as Membership, newHandle)
}

if (newMetadata) {
Expand All @@ -68,6 +71,11 @@ export async function processMemberProfileUpdatedEvent({
}
}

function updateMemberHandle(member: Membership, newHandle: Uint8Array) {
member.handleRaw = u8aToHex(newHandle)
member.handle = bytesToString(newHandle)
}

export async function processMemberRemarkedEvent({
overlay,
block,
Expand Down

0 comments on commit 4484149

Please sign in to comment.