Skip to content

Commit

Permalink
Merge branch 'develop' of github.com-Vojimirovich:IntersectMBO/cc-por…
Browse files Browse the repository at this point in the history
…tal into develop
  • Loading branch information
Vojimirovich committed Nov 22, 2024
2 parents b00bc32 + fc071d3 commit 98a850f
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 176 deletions.
19 changes: 0 additions & 19 deletions backend/migrations/1731525371919-rename-rationales-title-field.ts

This file was deleted.

This file was deleted.

8 changes: 4 additions & 4 deletions backend/postman/CC Portal develop.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
],
"body": {
"mode": "raw",
"raw": "{\n \"name\":\"Aca|Mitrovic\",\n \"description\":\"\",\n \"hotAddress\":\"\"\n}",
"raw": "{\n \"name\":\"Andjy\",\n \"description\":\"\",\n \"hotAddress\":\"newone\"\n}",
"options": {
"raw": {
"language": "json"
Expand Down Expand Up @@ -887,15 +887,15 @@
],
"body": {
"mode": "raw",
"raw": "{\n \"summary\": \"Summary of rationale 1\",\n \"rationale_statement\": \"Rationale statement 1\"\n}",
"raw": "{\n \"title\": \"test rationale 2\",\n \"content\": \"some text of rationale 2\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{base-url}}/api/governance/users/{{userId}}/proposals/1/rationale",
"raw": "{{base-url}}/api/governance/users/{{userId}}/proposals/2/rationale",
"host": [
"{{base-url}}"
],
Expand All @@ -905,7 +905,7 @@
"users",
"{{userId}}",
"proposals",
"1",
"2",
"rationale"
]
}
Expand Down
16 changes: 5 additions & 11 deletions backend/src/governance/api/request/rationale.request.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString, MaxLength } from 'class-validator';
import { IsString } from 'class-validator';

export class RationaleRequest {
@ApiProperty({ description: 'Summary' })
@IsNotEmpty()
@MaxLength(200, { message: `Maximum character length is 200` })
@ApiProperty({ description: 'Rationale title' })
@IsString()
summary: string;
title: string;

@ApiProperty({
description: 'Rationale statement',
name: 'rationale_statement',
})
@IsNotEmpty()
@ApiProperty({ description: 'Rationale content' })
@IsString()
rationaleStatement: string;
content: string;
}
4 changes: 4 additions & 0 deletions backend/src/governance/api/response/rationale.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export class RationaleResponse {
@Expose({ name: 'blake2b' })
blake2b: string;

@ApiProperty({ description: 'Title of a rationale' })
@Expose({ name: 'title' })
title: string;

@ApiProperty({ description: 'Contents of a rationale in json format' })
@Expose({ name: 'contents' })
contents: string;
Expand Down
41 changes: 41 additions & 0 deletions backend/src/governance/constants/cip100.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export const CIP100 = {
contextLanguage: 'en-us',
contextHashAlgorithm:
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#hashAlgorithm',
contextBody:
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#body',
contextBodyReferences:
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#references',
contextBodyReferencesGovernanceMetadata:
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#GovernanceMetadataReference',
contextBodyReferencesOther:
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#OtherReference',
contextBodyReferencesLabel:
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#reference-label',
contextBodyReferencesUri:
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#reference-uri',
contextBodyComment:
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#comment',
contextBodyExternalUpdates:
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#externalUpdates',
contextUpdateTitle:
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#update-title',
contextUpdateUri:
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#update-uri',
contextAuthors:
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#authors',
contextAuthorsName: 'http://xmlns.com/foaf/0.1/name',
contextAuthorsWitness:
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#witness',
contextWitnessAlgorithm:
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#witnessAlgorithm',
contextWitnessPublicKey:
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#publicKey',
contextWitnessSignature:
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#signature',
hashAlgorithm: 'blake2b-256',
bodyReferencesType: 'Other',
bodyReferencesLaber: 'CIP-100',
bodyReferencesUri:
'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md',
};
32 changes: 0 additions & 32 deletions backend/src/governance/constants/cip136.constants.ts

This file was deleted.

4 changes: 2 additions & 2 deletions backend/src/governance/dto/rationale.dto.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export class RationaleDto {
userId: string;
govActionProposalId: string;
summary: string;
rationaleStatement: string;
title: string;
content: string;
cid: string;
blake2b: string;
url: string;
Expand Down
8 changes: 4 additions & 4 deletions backend/src/governance/entities/rationale.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ export class Rationale extends CommonEntity {
govActionProposalId: string;

@Column({
name: 'summary',
name: 'title',
type: 'varchar',
})
summary: string;
title: string;

@Column({
name: 'rationale_statement',
name: 'content',
type: 'varchar',
})
rationaleStatement: string;
content: string;

@Column({
name: 'cid',
Expand Down
86 changes: 32 additions & 54 deletions backend/src/governance/facade/governance.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { IpfsService } from 'src/ipfs/services/ipfs.service';
import { RationaleRequest } from '../api/request/rationale.request';
import { IpfsContentDto } from 'src/ipfs/dto/ipfs-content.dto';
import { GovActionProposalDto } from '../dto/gov-action-proposal-dto';
import { ICIP136 } from '../interfaces/icip136.interface';
import { CIP136 } from '../constants/cip136.constants';
import { ICIP100 } from '../interfaces/icip100.interface';
import { CIP100 } from '../constants/cip100.constants';

@Injectable()
export class GovernanceFacade {
Expand All @@ -33,10 +33,8 @@ export class GovernanceFacade {
proposalId: string,
rationaleRequest: RationaleRequest,
): Promise<RationaleResponse> {
const rationaleJson = await this.createRationaleJsonCip100(
rationaleRequest,
userId,
);
const rationaleJson =
await this.createRationaleJsonCip100(rationaleRequest);
const ipfsContentDto = await this.addRationaleToIpfs(rationaleJson);
const rationaleDto = GovernanceMapper.ipfsContentDtoToRationaleDto(
ipfsContentDto,
Expand All @@ -48,85 +46,65 @@ export class GovernanceFacade {
return GovernanceMapper.rationaleDtoToResponse(response);
}
/**
* Creates a CIP 136 compatible JSON object.
* CIP 136 example:
* https://github.com/Ryun1/CIPs/blob/governance-metadata-cc-rationale/CIP-0136/examples/treasury-withdrawal-unconstitutional.jsonld
* Creates a CIP 100 compatible JSON object.
* CIP 100 example:
* https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/example.body.json
**/
private async createRationaleJsonCip100(
rationaleRequest: RationaleRequest,
userId: string,
): Promise<string> {
const cip136: ICIP136 = {
const cip100: ICIP100 = {
'@context': {
'@language': CIP136.contextLanguage,
CIP100: CIP136.contextCIP100,
CIP136: CIP136.contextCIP136,
hashAlgorithm: CIP136.contextHashAlgorithm,
'@language': CIP100.contextLanguage,
hashAlgorithm: CIP100.contextHashAlgorithm,
body: {
'@id': CIP136.contextBody,
'@id': CIP100.contextBody,
'@context': {
references: {
'@id': CIP136.contextBodyReferences,
'@id': CIP100.contextBodyReferences,
'@container': '@set',
'@context': {
GovernanceMetadata:
CIP136.contextBodyReferencesGovernanceMetadata,
Other: CIP136.contextBodyReferencesOther,
label: CIP136.contextBodyReferencesLabel,
uri: CIP136.contextBodyReferencesUri,
RelevantArticles: CIP136.contextBodyReferencesRelevantArticles,
governanceMetadata:
CIP100.contextBodyReferencesGovernanceMetadata,
other: CIP100.contextBodyReferencesOther,
label: CIP100.contextBodyReferencesLabel,
uri: CIP100.contextBodyReferencesUri,
},
},
summary: CIP136.contextBodySummary,
rationaleStatement: CIP136.contextBodyRationaleStatement,
precedentDiscussion: CIP136.contextBodyPrecedentDiscussion,
counterargumentDiscussion:
CIP136.contextBodyCounterargumentDiscussion,
conclusion: CIP136.contextBodyConclusion,
internalVote: {
'@id': CIP136.contextBodyInternalVote,
'@container': '@set',
comment: CIP100.contextBodyComment,
externalUpdates: {
'@id': CIP100.contextBodyExternalUpdates,
'@context': {
constitutional: CIP136.contextBodyInternalVoteConstitutional,
unconstitutional:
CIP136.contextBodyInternalVoteUnconstitutional,
abstain: CIP136.contextBodyInternalVoteAbstain,
didNotVote: CIP136.contextBodyInternalVoteDidNotVote,
title: CIP100.contextUpdateTitle,
uri: CIP100.contextUpdateUri,
},
},
},
},
authors: {
'@id': CIP136.contextAuthors,
'@id': CIP100.contextAuthors,
'@container': '@set',
'@context': {
did: '@id',
name: CIP136.contextAuthorsName,
name: CIP100.contextAuthorsName,
witness: {
'@id': CIP136.contextAuthorsWitness,
'@id': CIP100.contextAuthorsWitness,
'@context': {
witnessAlgorithm: CIP136.contextWitnessAlgorithm,
publicKey: CIP136.contextWitnessPublicKey,
signature: CIP136.contextWitnessSignature,
witnessAlgorithm: CIP100.contextWitnessAlgorithm,
publicKey: CIP100.contextWitnessPublicKey,
signature: CIP100.contextWitnessSignature,
},
},
},
},
},
hashAlgorithm: CIP136.hashAlgorithm,
hashAlgorithm: CIP100.hashAlgorithm,
authors: [],
body: {
summary: rationaleRequest.summary,
rationaleStatement: rationaleRequest.rationaleStatement,
comment: rationaleRequest.content,
},
authors: [],
};
const user = await this.usersService.findById(userId);
if (user.name) {
cip136.authors.push({
name: user.name,
});
}
return JSON.stringify(cip136);
return JSON.stringify(cip100);
}

private async addRationaleToIpfs(
Expand Down
Loading

0 comments on commit 98a850f

Please sign in to comment.