Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/alpha' into master-into-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
polymath-eric committed Aug 28, 2023
2 parents e2ce146 + ca8342a commit 0ce1ac6
Show file tree
Hide file tree
Showing 32 changed files with 490 additions and 656 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.git
.env*
node_modules/
37 changes: 30 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
FROM node:18
FROM node:lts-alpine3.17 AS builder

RUN apk add --no-cache \
python3 \
make \
cmake \
g++ \
jq

WORKDIR /app/builder
RUN chown -R node: /app

USER node

COPY --chown=node:node . .

RUN yarn install \
--ignore-scripts \
--frozen-lockfile \
--no-progress && \
yarn build && \
yarn remove $(cat package.json | jq -r '.devDependencies | keys | join(" ")') && \
rm -r /home/node/.cache/

FROM node:lts-alpine3.17
WORKDIR /home/node
ENV NODE_ENV production

# cache yarn install step
COPY --chown=node:node package.json /home/node
COPY --chown=node:node yarn.lock /home/node
RUN yarn --frozen-lockfile
COPY --from=builder --chown=node:node /app/builder/node_modules ./node_modules
COPY --from=builder --chown=node:node /app/builder/dist/ ./dist

COPY --chown=node:node . /home/node

USER node
RUN yarn build
ENTRYPOINT ["/bin/bash", "./docker-entrypoint.sh"]
CMD [ "node", "dist/main.js" ]

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

A REST API wrapper for the Polymesh blockchain.

This version is compatible with chain versions 5.2.x
This version is compatible with chain versions 5.4.x - 6.0.x

## Setup

Expand Down
8 changes: 8 additions & 0 deletions chain-entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

/usr/local/bin/polymesh \
-d /var/lib/polymesh \
--unsafe-ws-external --unsafe-rpc-external --wasm-execution=compiled \
--no-prometheus --no-telemetry --pruning=archive --no-mdns \
--validator --rpc-cors=all --rpc-methods=unsafe --force-authoring \
--port 30333 $1
18 changes: 17 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
services:
chain:
image: ${CHAIN_IMAGE}
init: true # Faster shutdown by container process not be PID 1
restart: unless-stopped
ports:
# expose ports to localhost
- '9944:9944' # ws://
- '9933:9933' # http://
- '30333:30333' # for other nodes
extra_hosts:
- 'host.docker.internal:host-gateway'
volumes:
- './chain-entry.sh:/chain-entry.sh'
entrypoint: '/chain-entry.sh'
command: [ '--alice --chain dev' ]

postgres:
image: postgres:15
ports:
Expand All @@ -9,7 +25,7 @@ services:
POSTGRES_USER: $REST_POSTGRES_USER
POSTGRES_PASSWORD: $REST_POSTGRES_PASSWORD
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U postgres']
test: [ 'CMD-SHELL', 'pg_isready -U postgres' ]
interval: 5s
timeout: 5s
retries: 5
Expand Down
1 change: 0 additions & 1 deletion docker-entrypoint.sh

This file was deleted.

15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "NODE_ENV='production' node dist/main",
"start:repl": "yarn start --entryFile commands/repl",
"generate:swagger": "yarn start --entryFile commands/write-swagger",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
Expand Down Expand Up @@ -45,11 +44,11 @@
"@nestjs/schedule": "^2.2.0",
"@nestjs/swagger": "^6.2.1",
"@nestjs/typeorm": "^9.0.1",
"@polymeshassociation/fireblocks-signing-manager": "^1.0.3",
"@polymeshassociation/hashicorp-vault-signing-manager": "^1.1.6",
"@polymeshassociation/local-signing-manager": "^1.3.0",
"@polymeshassociation/polymesh-sdk": "20.1.0",
"@polymeshassociation/signing-manager-types": "^1.2.1",
"@polymeshassociation/fireblocks-signing-manager": "^2.2.0",
"@polymeshassociation/hashicorp-vault-signing-manager": "^2.1.0",
"@polymeshassociation/local-signing-manager": "^2.1.0",
"@polymeshassociation/polymesh-sdk": "22.0.0-alpha.3",
"@polymeshassociation/signing-manager-types": "^2.1.0",
"class-transformer": "0.5.1",
"class-validator": "^0.14.0",
"joi": "17.4.0",
Expand All @@ -63,13 +62,13 @@
"rimraf": "3.0.2",
"rxjs": "^7.5.7",
"swagger-ui-express": "4.4.0",
"typeorm": "^0.3.10"
"typeorm": "^0.3.10",
"@golevelup/ts-jest": "^0.3.3"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "7.15.0",
"@commitlint/cli": "12.1.4",
"@commitlint/config-conventional": "12.1.4",
"@golevelup/ts-jest": "^0.3.3",
"@nestjs/cli": "^9.3.0",
"@nestjs/schematics": "^9.0.3",
"@nestjs/testing": "^9.3.0",
Expand Down
20 changes: 19 additions & 1 deletion prepareRelease.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
#!/bin/bash

set -exu -o pipefail

declare nextVersion=$1

# This needs to be set to and SDK compatible value
CHAIN_TAG='6.0.0-develop-debian'

# This lets it work on arm64, like Mac Books
ARCHITECTURE=$(uname -m)
CHAIN_REPO=polymeshassociation/polymesh
if [ "$ARCHITECTURE" = "arm64" ]; then
CHAIN_REPO="polymeshassociation/polymesh-arm64"
fi

sed -i.bak -e "s/.setVersion('.*')/.setVersion('$nextVersion')/g" src/main.ts
rm src/main.ts.bak

SWAGGER_VERSION=$nextVersion POLYMESH_NODE_URL='wss://testnet-rpc.polymesh.live' yarn generate:swagger > /dev/null 2>&1
export CHAIN_IMAGE="$CHAIN_REPO:$CHAIN_TAG"

docker compose up -d chain

SWAGGER_VERSION=$nextVersion POLYMESH_NODE_URL='ws://localhost:9944' yarn generate:swagger > /dev/null 2>&1

docker compose down chain
20 changes: 1 addition & 19 deletions src/claims/claims.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DeepMocked } from '@golevelup/ts-jest';
import { Test } from '@nestjs/testing';
import { ClaimType, ScopeType } from '@polymeshassociation/polymesh-sdk/types';
import { ClaimType } from '@polymeshassociation/polymesh-sdk/types';

import { ClaimsController } from '~/claims/claims.controller';
import { ClaimsService } from '~/claims/claims.service';
Expand Down Expand Up @@ -76,22 +76,4 @@ describe('ClaimsController', () => {
expect(result).toEqual({ ...txResult, results: undefined });
});
});

describe('addInvestorUniqueness', () => {
it('should call addInvestorUniqueness method and return transaction data', async () => {
mockClaimsService.addInvestorUniqueness.mockResolvedValue({ ...txResult, result: undefined });
const mockArgs = {
scope: { type: ScopeType.Identity, value: did },
cddId: '0x1',
proof: 'proof',
scopeId: 'id',
signer,
};
const result = await controller.addInvestorUniqueness(mockArgs);

expect(mockClaimsService.addInvestorUniqueness).toHaveBeenCalledWith(mockArgs);

expect(result).toEqual({ ...txResult, results: undefined });
});
});
});
21 changes: 0 additions & 21 deletions src/claims/claims.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Body, Controller, HttpStatus, Post } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';

import { ClaimsService } from '~/claims/claims.service';
import { AddInvestorUniquenessDto } from '~/claims/dto/add-investor-uniqueness.dto';
import { ModifyClaimsDto } from '~/claims/dto/modify-claims.dto';
import { ApiTransactionFailedResponse, ApiTransactionResponse } from '~/common/decorators/swagger';
import { TransactionQueueModel } from '~/common/models/transaction-queue.model';
Expand Down Expand Up @@ -78,24 +77,4 @@ export class ClaimsController {

return handleServiceResult(serviceResult);
}

@ApiOperation({
summary: 'Add Investor uniqueness Claims to the signing Identity',
description: 'This endpoint will add Investor uniqueness Claims to the signing Identity',
})
@ApiTransactionResponse({
description: 'Transaction response',
type: TransactionQueueModel,
})
@ApiTransactionFailedResponse({
[HttpStatus.UNPROCESSABLE_ENTITY]: ['Account does not have the required roles or permissions'],
})
@Post('add-investor-uniqueness')
async addInvestorUniqueness(
@Body() args: AddInvestorUniquenessDto
): Promise<TransactionResponseModel> {
const serviceResult = await this.claimsService.addInvestorUniqueness(args);

return handleServiceResult(serviceResult);
}
}
51 changes: 1 addition & 50 deletions src/claims/claims.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { Test, TestingModule } from '@nestjs/testing';
import { BigNumber } from '@polymeshassociation/polymesh-sdk';
import {
ClaimData,
ClaimType,
ResultSet,
ScopeType,
TxTags,
} from '@polymeshassociation/polymesh-sdk/types';
import { ClaimData, ClaimType, ResultSet, TxTags } from '@polymeshassociation/polymesh-sdk/types';

import { ClaimsService } from '~/claims/claims.service';
import { POLYMESH_API } from '~/polymesh/polymesh.consts';
Expand Down Expand Up @@ -254,47 +248,4 @@ describe('ClaimsService', () => {
expect(mockPolymeshApi.claims.getClaimScopes).toHaveBeenCalledWith({ target: did });
});
});

describe('addInvestorUniqueness', () => {
it('should run a addInvestorUniquenessClaim procedure and return the queue results', async () => {
const mockTransactions = {
blockHash: '0x1',
txHash: '0x2',
blockNumber: new BigNumber(1),
tag: TxTags.identity.AddInvestorUniquenessClaim,
};

const mockArgs = {
scope: { type: ScopeType.Identity, value: did },
cddId: '0x1',
proof: 'proof',
scopeId: 'id',
};
const mockTransaction = new MockTransaction(mockTransactions);

mockTransactionsService.submit.mockResolvedValue(mockTransaction);

const result = await claimsService.addInvestorUniqueness({ signer, ...mockArgs });

expect(result).toBe(mockTransaction);

expect(mockTransactionsService.submit).toHaveBeenCalledWith(
mockPolymeshApi.claims.addInvestorUniquenessClaim,
mockArgs,
{ signer }
);
});
});

describe('getInvestorUniqueness', () => {
it('should run a getInvestorUniquenessClaims procedure and return the result', async () => {
const claimsResult = [] as ClaimData[];

mockPolymeshApi.claims.getInvestorUniquenessClaims.mockResolvedValue(claimsResult);

const result = await claimsService.getInvestorUniquenessClaims(did, true);

expect(result).toBe(claimsResult);
});
});
});
29 changes: 1 addition & 28 deletions src/claims/claims.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ import { Injectable } from '@nestjs/common';
import { BigNumber } from '@polymeshassociation/polymesh-sdk';
import {
AddClaimsParams,
AddInvestorUniquenessClaimParams,
CddClaim,
ClaimData,
ClaimScope,
ClaimType,
InvestorUniquenessClaim,
ModifyClaimsParams,
ResultSet,
RevokeClaimsParams,
Scope,
} from '@polymeshassociation/polymesh-sdk/types';

import { AddInvestorUniquenessDto } from '~/claims/dto/add-investor-uniqueness.dto';
import { ModifyClaimsDto } from '~/claims/dto/modify-claims.dto';
import { extractTxBase, ServiceReturn } from '~/common/utils';
import { PolymeshService } from '~/polymesh/polymesh.service';
Expand Down Expand Up @@ -44,7 +41,7 @@ export class ClaimsService {
public async findAssociatedByDid(
target: string,
scope?: Scope,
claimTypes?: Exclude<ClaimType, ClaimType.InvestorUniquenessV2>[],
claimTypes?: ClaimType[],
includeExpired?: boolean,
size?: BigNumber,
start?: BigNumber
Expand Down Expand Up @@ -95,20 +92,6 @@ export class ClaimsService {
});
}

public async addInvestorUniqueness(
modifyClaimsDto: AddInvestorUniquenessDto
): ServiceReturn<void> {
const { base, args } = extractTxBase(modifyClaimsDto);

const { addInvestorUniquenessClaim } = this.polymeshService.polymeshApi.claims;

return this.transactionsService.submit(
addInvestorUniquenessClaim,
args as AddInvestorUniquenessClaimParams,
base
);
}

public async findCddClaimsByDid(
target: string,
includeExpired = true
Expand All @@ -118,14 +101,4 @@ export class ClaimsService {
includeExpired,
});
}

public async getInvestorUniquenessClaims(
target: string,
includeExpired = true
): Promise<ClaimData<InvestorUniquenessClaim>[]> {
return await this.polymeshService.polymeshApi.claims.getInvestorUniquenessClaims({
target,
includeExpired,
});
}
}
Loading

0 comments on commit 0ce1ac6

Please sign in to comment.