Skip to content

Commit

Permalink
feat: 🎸 add v1/v2 dual version support
Browse files Browse the repository at this point in the history
support polymesh private chain v1/v2 (equal to public v6/v7)
  • Loading branch information
polymath-eric committed Nov 15, 2024
1 parent b73b508 commit e5d6f93
Show file tree
Hide file tree
Showing 26 changed files with 412 additions and 576 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@

A REST API wrapper for the Polymesh Private blockchain.

This version is compatible with chain versions 1.0.x
This version is compatible with polymesh private chain versions 1.x and 2.x

## Submodule Notice

This repo uses a submodule to avoid duplicating the public REST API. The submodules can be pulled with:

```
git submodule update --init --recursive
```

## Setup

Expand Down
8 changes: 0 additions & 8 deletions compose/chain-entry.sh

This file was deleted.

1 change: 1 addition & 0 deletions compose/init-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set -e

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE EXTENSION IF NOT EXISTS btree_gist;
SELECT 'CREATE DATABASE rest'
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'rest')\gexec
EOSQL
1 change: 1 addition & 0 deletions compose/pg-extensions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE EXTENSION IF NOT EXISTS btree_gist;
26 changes: 19 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
chain:
image: ${CHAIN_IMAGE}
image: ${CHAIN_IMAGE:-polymeshassociation/polymesh-private:2.0.0-main-debian}
init: true # Faster shutdown by container process not be PID 1
restart: unless-stopped
ports:
Expand All @@ -12,8 +12,11 @@ services:
- 'host.docker.internal:host-gateway'
volumes:
- './compose/chain-entry.sh:/chain-entry.sh'
entrypoint: '/chain-entry.sh'
command: [ '--alice --chain dev' ]
command:
- --dev
- --rpc-external
- --ws-external
- --base-path=/var/lib/polymesh-private
healthcheck:
test: "timeout 5 bash -c 'cat < /dev/null > /dev/tcp/localhost/9933' && exit 0 || exit 1"
interval: 10s
Expand All @@ -23,7 +26,7 @@ services:

subquery:
platform: 'linux/amd64'
image: '${SUBQUERY_IMAGE}'
image: '${SUBQUERY_IMAGE:-polymeshassociation/polymesh-subquery:v17.1.1}'
init: true
restart: unless-stopped
depends_on:
Expand All @@ -50,7 +53,7 @@ services:
timeout: 10s

graphql:
image: onfinality/subql-query:v1.0.0
image: onfinality/subql-query:v2.9.0
restart: unless-stopped
ports:
- ${SQ_PORT:-3001}:3000
Expand Down Expand Up @@ -91,8 +94,12 @@ services:
- db-data:/var/lib/postgresql/data
- ./compose/init-db.sh:/docker-entrypoint-initdb.d/init-db.sh
environment:
POSTGRES_USER: $REST_POSTGRES_USER
POSTGRES_PASSWORD: $REST_POSTGRES_PASSWORD
POSTGRES_USER: ${REST_POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${REST_POSTGRES_PASSWORD:-postgres}
configs:
- source: pg-extensions
target: /docker-entrypoint-initdb.d/btree_extension.sql
mode: 0555
healthcheck:
test: [ 'CMD-SHELL', 'pg_isready -U postgres' ]
interval: 5s
Expand All @@ -101,3 +108,8 @@ services:

volumes:
db-data:

configs:
pg-extensions:
external: false
file: ./compose/pg-extensions.sql
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polymesh-private-rest-api",
"version": "1.0.0-alpha.7",
"version": "2.0.0",
"description": "Provides a REST like interface for interacting with the Polymesh Private blockchain",
"author": "Polymesh Association",
"private": true,
Expand Down Expand Up @@ -49,7 +49,7 @@
"@polymeshassociation/fireblocks-signing-manager": "^2.3.0",
"@polymeshassociation/hashicorp-vault-signing-manager": "^3.1.0",
"@polymeshassociation/local-signing-manager": "^3.1.0",
"@polymeshassociation/polymesh-private-sdk": "2.0.0-alpha.3",
"@polymeshassociation/polymesh-private-sdk": "2.0.0",
"@polymeshassociation/signing-manager-types": "^3.1.0",
"class-transformer": "0.5.1",
"class-validator": "^0.14.0",
Expand Down
2 changes: 1 addition & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { ConfidentialTransactionsModule } from '~/confidential-transactions/conf
import { ExtendedIdentitiesModule } from '~/extended-identities/identities.module';
import { PolymeshModule } from '~/polymesh/polymesh.module';
import { AccountsModule } from '~/polymesh-rest-api/src/accounts/accounts.module';
import { ArtemisModule } from '~/polymesh-rest-api/src/artemis/artemis.module';
import { AssetsModule } from '~/polymesh-rest-api/src/assets/assets.module';
import { AuthModule } from '~/polymesh-rest-api/src/auth/auth.module';
import { AuthStrategy } from '~/polymesh-rest-api/src/auth/strategies/strategies.consts';
Expand All @@ -26,6 +25,7 @@ import { CorporateActionsModule } from '~/polymesh-rest-api/src/corporate-action
import { DeveloperTestingModule } from '~/polymesh-rest-api/src/developer-testing/developer-testing.module';
import { EventsModule } from '~/polymesh-rest-api/src/events/events.module';
import { IdentitiesModule } from '~/polymesh-rest-api/src/identities/identities.module';
import { ArtemisModule } from '~/polymesh-rest-api/src/message/artemis/artemis.module';
import { MetadataModule } from '~/polymesh-rest-api/src/metadata/metadata.module';
import { NetworkModule } from '~/polymesh-rest-api/src/network/network.module';
import { NftsModule } from '~/polymesh-rest-api/src/nfts/nfts.module';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ConfidentialProofsService } from '~/confidential-proofs/confidential-pr
import { AppNotFoundError } from '~/polymesh-rest-api/src/common/errors';
import { PaginatedResultsModel } from '~/polymesh-rest-api/src/common/models/paginated-results.model';
import { ServiceReturn } from '~/polymesh-rest-api/src/common/utils/functions';
import { getMockTransaction, testValues } from '~/test-utils/consts';
import { getMockTransaction, processedTxResult, testValues } from '~/test-utils/consts';
import {
createMockConfidentialAsset,
createMockIdentity,
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('ConfidentialAccountsController', () => {
);

const result = await controller.linkAccount({ confidentialAccount }, input);
expect(result).toEqual(txResult);
expect(result).toEqual(processedTxResult);
});
});

Expand Down Expand Up @@ -170,7 +170,7 @@ describe('ConfidentialAccountsController', () => {
const result = await controller.applyAllIncomingAssetBalances({ confidentialAccount }, input);
expect(result).toEqual(
new AppliedConfidentialAssetBalancesModel({
...txResult,
...processedTxResult,
transactions: [transaction],
appliedAssetBalances: [
new AppliedConfidentialAssetBalanceModel({
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('ConfidentialAccountsController', () => {
const result = await controller.applyAllIncomingAssetBalances({ confidentialAccount }, input);
expect(result).toEqual(
new AppliedConfidentialAssetBalancesModel({
...txResult,
...processedTxResult,
transactions: [transaction],
appliedAssetBalances: [
new AppliedConfidentialAssetBalanceModel({
Expand Down Expand Up @@ -306,7 +306,7 @@ describe('ConfidentialAccountsController', () => {
);

const result = await controller.moveFunds(input);
expect(result).toEqual(txResult);
expect(result).toEqual(processedTxResult);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
ApiArrayResponse,
ApiTransactionFailedResponse,
ApiTransactionResponse,
} from '~/polymesh-rest-api/src/common/decorators/swagger';
} from '~/polymesh-rest-api/src/common/decorators';
import { TransactionBaseDto } from '~/polymesh-rest-api/src/common/dto/transaction-base-dto';
import { PaginatedResultsModel } from '~/polymesh-rest-api/src/common/models/paginated-results.model';
import { TransactionQueueModel } from '~/polymesh-rest-api/src/common/models/transaction-queue.model';
Expand Down Expand Up @@ -404,6 +404,7 @@ export class ConfidentialAccountsController {
})
@ApiTransactionResponse({
description: 'Details about the transaction',
type: TransactionQueueModel,
})
@Post('move-funds')
public async moveFunds(@Body() args: MoveFundsDto): Promise<TransactionResponseModel> {
Expand Down
20 changes: 10 additions & 10 deletions src/confidential-assets/confidential-assets.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ConfidentialAssetsController } from '~/confidential-assets/confidential
import { ConfidentialAssetsService } from '~/confidential-assets/confidential-assets.service';
import { CreatedConfidentialAssetModel } from '~/confidential-assets/models/created-confidential-asset.model';
import { ServiceReturn } from '~/polymesh-rest-api/src/common/utils/functions';
import { getMockTransaction, testValues } from '~/test-utils/consts';
import { getMockTransaction, processedTxResult, testValues } from '~/test-utils/consts';
import {
createMockConfidentialAccount,
createMockConfidentialAsset,
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('ConfidentialAssetsController', () => {
const result = await controller.createConfidentialAsset(input);
expect(result).toEqual(
new CreatedConfidentialAssetModel({
...txResult,
...processedTxResult,
transactions: [transaction],
confidentialAsset: mockConfidentialAsset,
})
Expand All @@ -121,7 +121,7 @@ describe('ConfidentialAssetsController', () => {
);

const result = await controller.issueConfidentialAsset({ confidentialAssetId: id }, input);
expect(result).toEqual(txResult);
expect(result).toEqual(processedTxResult);
});
});

Expand Down Expand Up @@ -165,7 +165,7 @@ describe('ConfidentialAssetsController', () => {
{ confidentialAssetId: id },
input
);
expect(result).toEqual(txResult);
expect(result).toEqual(processedTxResult);
});
});

Expand All @@ -180,10 +180,10 @@ describe('ConfidentialAssetsController', () => {
);

let result = await controller.addAllowedVenues({ confidentialAssetId: id }, input);
expect(result).toEqual(txResult);
expect(result).toEqual(processedTxResult);

result = await controller.removeAllowedVenues({ confidentialAssetId: id }, input);
expect(result).toEqual(txResult);
expect(result).toEqual(processedTxResult);
});
});

Expand All @@ -197,10 +197,10 @@ describe('ConfidentialAssetsController', () => {
);

let result = await controller.freezeConfidentialAsset({ confidentialAssetId: id }, input);
expect(result).toEqual(txResult);
expect(result).toEqual(processedTxResult);

result = await controller.unfreezeConfidentialAsset({ confidentialAssetId: id }, input);
expect(result).toEqual(txResult);
expect(result).toEqual(processedTxResult);
});
});

Expand All @@ -215,10 +215,10 @@ describe('ConfidentialAssetsController', () => {
);

let result = await controller.freezeConfidentialAccount({ confidentialAssetId: id }, input);
expect(result).toEqual(txResult);
expect(result).toEqual(processedTxResult);

result = await controller.unfreezeConfidentialAccount({ confidentialAssetId: id }, input);
expect(result).toEqual(txResult);
expect(result).toEqual(processedTxResult);
});
});

Expand Down
7 changes: 6 additions & 1 deletion src/confidential-assets/confidential-assets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import { CreatedConfidentialAssetModel } from '~/confidential-assets/models/crea
import {
ApiTransactionFailedResponse,
ApiTransactionResponse,
} from '~/polymesh-rest-api/src/common/decorators/swagger';
} from '~/polymesh-rest-api/src/common/decorators/';
import { TransactionBaseDto } from '~/polymesh-rest-api/src/common/dto/transaction-base-dto';
import { TransactionQueueModel } from '~/polymesh-rest-api/src/common/models/transaction-queue.model';
import {
handleServiceResult,
TransactionResolver,
Expand Down Expand Up @@ -248,6 +249,7 @@ export class ConfidentialAssetsController {
})
@ApiTransactionResponse({
description: 'Details about the transaction',
type: TransactionQueueModel,
})
@ApiTransactionFailedResponse({
[HttpStatus.BAD_REQUEST]: [
Expand Down Expand Up @@ -276,6 +278,7 @@ export class ConfidentialAssetsController {
})
@ApiTransactionResponse({
description: 'Details about the transaction',
type: TransactionQueueModel,
})
@ApiTransactionFailedResponse({
[HttpStatus.BAD_REQUEST]: [
Expand Down Expand Up @@ -304,6 +307,7 @@ export class ConfidentialAssetsController {
})
@ApiTransactionResponse({
description: 'Details about the transaction',
type: TransactionQueueModel,
})
@ApiTransactionFailedResponse({
[HttpStatus.BAD_REQUEST]: [
Expand Down Expand Up @@ -333,6 +337,7 @@ export class ConfidentialAssetsController {
})
@ApiTransactionResponse({
description: 'Details about the transaction',
type: TransactionQueueModel,
})
@ApiTransactionFailedResponse({
[HttpStatus.BAD_REQUEST]: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { SenderAffirmationModel } from '~/confidential-proofs/models/sender-affi
import { ConfidentialTransactionsService } from '~/confidential-transactions/confidential-transactions.service';
import { VerifyAndAffirmDto } from '~/confidential-transactions/dto/verify-and-affirm.dto';
import { ServiceReturn } from '~/polymesh-rest-api/src/common/utils/functions';
import { testValues, txResult } from '~/test-utils/consts';
import { processedTxResult, testValues, txResult } from '~/test-utils/consts';
import {
mockConfidentialAssetsServiceProvider,
mockConfidentialProofsServiceProvider,
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('ConfidentialProofsController', () => {
const result = await controller.senderAffirmLeg({ id: transactionId }, input);
expect(result).toEqual(
new SenderAffirmationModel({
...txResult,
...processedTxResult,
proofs: [{ asset: 'someId', proof: 'someProof' }],
})
);
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('ConfidentialProofsController', () => {
.mockResolvedValue(txResult as unknown as ServiceReturn<ConfidentialAsset>);

const result = await controller.burnConfidentialAsset({ confidentialAssetId }, input);
expect(result).toEqual(txResult);
expect(result).toEqual(processedTxResult);
});
});

Expand Down Expand Up @@ -235,7 +235,7 @@ describe('ConfidentialProofsController', () => {

const result = await controller.verifyAndAffirmLeg({ id }, input);

expect(result).toEqual(txResult);
expect(result).toEqual(processedTxResult);
});
});
});
2 changes: 1 addition & 1 deletion src/confidential-proofs/models/sender-affirmation.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';

import { TransactionQueueModel } from '~/common/models/transaction-queue.model';
import { ConfidentialProofModel } from '~/confidential-transactions/models/confidential-proof.model';
import { TransactionQueueModel } from '~/polymesh-rest-api/src/common/models/transaction-queue.model';

export class SenderAffirmationModel extends TransactionQueueModel {
@ApiPropertyOptional({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ConfidentialTransactionsController } from '~/confidential-transactions/
import { ConfidentialTransactionsService } from '~/confidential-transactions/confidential-transactions.service';
import { ObserverAffirmConfidentialTransactionDto } from '~/confidential-transactions/dto/observer-affirm-confidential-transaction.dto';
import { ServiceReturn } from '~/polymesh-rest-api/src/common/utils/functions';
import { testValues } from '~/test-utils/consts';
import { processedTxResult, testValues } from '~/test-utils/consts';
import {
createMockConfidentialAccount,
createMockConfidentialAsset,
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('ConfidentialTransactionsController', () => {
.mockResolvedValue(txResult as unknown as ServiceReturn<ConfidentialTransaction>);

const result = await controller.observerAffirmLeg({ id: transactionId }, input);
expect(result).toEqual(txResult);
expect(result).toEqual(processedTxResult);
});
});

Expand All @@ -128,7 +128,7 @@ describe('ConfidentialTransactionsController', () => {
.mockResolvedValue(txResult as unknown as ServiceReturn<ConfidentialTransaction>);

const result = await controller.rejectConfidentialTransaction({ id: transactionId }, input);
expect(result).toEqual(txResult);
expect(result).toEqual(processedTxResult);
});
});

Expand All @@ -145,7 +145,7 @@ describe('ConfidentialTransactionsController', () => {
.mockResolvedValue(txResult as unknown as ServiceReturn<ConfidentialTransaction>);

const result = await controller.executeConfidentialTransaction({ id: transactionId }, input);
expect(result).toEqual(txResult);
expect(result).toEqual(processedTxResult);
});
});

Expand Down
Loading

0 comments on commit e5d6f93

Please sign in to comment.