Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sdk): temporary disable data contracts and documents #1331

Merged
merged 6 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions packages/js-dash-sdk/src/SDK/Client/Client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ describe('Dash - Client', function suite() {
await createTransactionInAccount(account);
// create an identity in the account so we can sign state transitions
identityFixture = await createIdentityFixtureInAccount(account);
dataContractFixture = await getDataContractFixture();
documentsFixture = await getDocumentsFixture(dataContractFixture);
// dataContractFixture = await getDataContractFixture();
// documentsFixture = await getDocumentsFixture(dataContractFixture);

transportMock.getTransaction.resolves({
transaction: new Transaction('03000000019ecd68f367aba679209b9c912ff1d2ef9147f90eba2a47b5fb0158e27fb15476000000006b483045022100af2ca966eaeef8f5493fd8bcf2248d60b3f6b8236c137e2d099c8ba35878bf9402204f653232768eb8b06969b13f0aa3579d653163f757009e0c261c9ffd32332ffb0121034244016aa525c632408bc627923590cf136b47035cd57aa6f1fa8b696d717304ffffffff021027000000000000166a140f177a991f37fe6cbb08fb3f21b9629fa47330e3a85b0100000000001976a914535c005bfef672162aa2c53f0f6630a57ade344588ac00000000'),
Expand All @@ -71,11 +71,11 @@ describe('Dash - Client', function suite() {
transportMock.getBlockHeaderByHash
.returns(BlockHeader.fromString(blockHeaderFixture));

dapiClientMock.platform.getDataContract
.resolves(new GetDataContractResponse(
dataContractFixture.toBuffer(),
getResponseMetadataFixture(),
));
// dapiClientMock.platform.getDataContract
// .resolves(new GetDataContractResponse(
// dataContractFixture.toBuffer(),
// getResponseMetadataFixture(),
// ));
});

it('should provide expected class', () => {
Expand Down Expand Up @@ -249,6 +249,7 @@ describe('Dash - Client', function suite() {

const publicKeysToAdd = [
new IdentityPublicKeyWithWitness({
$version: '0',
id: 3,
type: IdentityPublicKey.TYPES.ECDSA_SECP256K1,
data: privateKey.toPublicKey().toBuffer(),
Expand Down Expand Up @@ -311,7 +312,7 @@ describe('Dash - Client', function suite() {
});
});

describe('#platform.documents.broadcast', () => {
describe.skip('#platform.documents.broadcast', () => {
it('should throw TransitionBroadcastError when transport resolves error', async () => {
const errorResponse = {
error: {
Expand Down Expand Up @@ -364,7 +365,7 @@ describe('Dash - Client', function suite() {
});
});

describe('#platform.contracts.publish', () => {
describe.skip('#platform.contracts.publish', () => {
it('should throw TransitionBroadcastError when transport resolves error', async () => {
const errorResponse = {
error: {
Expand Down
10 changes: 6 additions & 4 deletions packages/js-dash-sdk/src/SDK/Client/Platform/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,14 @@ export class Platform {
if (!this.dpp) {
await Platform.initializeDppModule();

const bls = await getBlsAdapter();
const stateRepository = new StateRepository(this.client);
// TODO(versioning): restore
// @ts-ignore
// const bls = await getBlsAdapter();
// const stateRepository = new StateRepository(this.client);

this.dpp = new DashPlatformProtocol(
bls,
stateRepository,
// bls,
// stateRepository,
{
generate: () => crypto.randomBytes(32),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO(versioning): restore
// @ts-ignore
import { DataContract, Identity, Identifier } from '@dashevo/wasm-dpp';
import Client from '../Client';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import crypto from 'crypto';
import { StateTransitionExecutionContext } from '@dashevo/wasm-dpp';
import { Platform } from './Platform';
import { StateTransitionBroadcastError } from '../../../errors/StateTransitionBroadcastError';
import { IStateTransitionResult } from './IStateTransitionResult';
Expand All @@ -25,24 +24,26 @@ export default async function broadcastStateTransition(
): Promise<IStateTransitionResult | void> {
const { client, dpp } = platform;

if (!options.skipValidation) {
const result = await dpp.stateTransition.validateBasic(
stateTransition,
// TODO(v0.24-backport): get rid of this once decided
// whether we need execution context in wasm bindings
new StateTransitionExecutionContext(),
);

if (!result.isValid()) {
const consensusError = result.getFirstError();

throw new StateTransitionBroadcastError(
consensusError.getCode(),
consensusError.message,
consensusError,
);
}
}
// TODO(versioning): restore
// @ts-ignore
// if (!options.skipValidation) {
// const result = await dpp.stateTransition.validateBasic(
// stateTransition,
// // TODO(v0.24-backport): get rid of this once decided
// // whether we need execution context in wasm bindings
// new StateTransitionExecutionContext(),
// );
//
// if (!result.isValid()) {
// const consensusError = result.getFirstError();
//
// throw new StateTransitionBroadcastError(
// consensusError.getCode(),
// consensusError.message,
// consensusError,
// );
// }
// }

// Subscribing to future result
const hash = crypto.createHash('sha256')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export async function create(

await this.initialize();

// TODO(versioning): restore
// @ts-ignore
const dataContract = this.dpp.dataContract.create(identity.getId(), contractDefinitions);

this.logger.debug(`[Contracts#create] created data contract "${dataContract.getId()}"`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export async function get(this: Platform, identifier: ContractIdentifier): Promi
throw e;
}

// TODO(versioning): restore
// @ts-ignore
const contract = await this.dpp.dataContract
.createFromBuffer(dataContractResponse.getDataContract() as Uint8Array);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export async function history(

// eslint-disable-next-line no-restricted-syntax
for (const [date, contractBytes] of Object.entries(rawContractHistory)) {
// TODO(versioning): restore
// @ts-ignore
contractHistory[date] = await this.dpp.dataContract
.createFromBuffer(contractBytes as Uint8Array);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO(versioning): restore
// @ts-ignore
import { Identity, DataContract, DataContractCreateTransition } from '@dashevo/wasm-dpp';
import { Platform } from '../../Platform';
import broadcastStateTransition from '../../broadcastStateTransition';
Expand All @@ -21,6 +23,8 @@ export default async function publish(

const { dpp } = this;

// TODO(versioning): restore
// @ts-ignore
const dataContractCreateTransition = dpp.dataContract
.createDataContractCreateTransition(dataContract);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export default async function update(

updatedDataContract.incrementVersion();

// TODO(versioning): restore
// @ts-ignore
const dataContractUpdateTransition = dpp.dataContract
.createDataContractUpdateTransition(updatedDataContract);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO(versioning): restore
// @ts-ignore
import { ExtendedDocument } from '@dashevo/wasm-dpp';
import { Platform } from '../../Platform';
import broadcastStateTransition from '../../broadcastStateTransition';
Expand Down Expand Up @@ -31,6 +33,8 @@ export default async function broadcast(

const { dpp } = this;

// TODO(versioning): restore
// @ts-ignore
const documentsBatchTransition = dpp.document.createStateTransition(documents);

this.logger.silly('[Document#broadcast] Created documents batch transition');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO(versioning): restore
// @ts-ignore
import { ExtendedDocument } from '@dashevo/wasm-dpp';
import { Platform } from '../../Platform';

Expand Down Expand Up @@ -39,6 +41,8 @@ export async function create(
throw new Error(`Contract ${appName} not found. Ensure contractId ${contractId} is correct.`);
}

// TODO(versioning): restore
// @ts-ignore
const document = dpp.document.create(
dataContract,
identity.getId(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO(versioning): restore
// @ts-ignore
import { Identifier, ExtendedDocument, Metadata } from '@dashevo/wasm-dpp';
import { GetDocumentsResponse } from '@dashevo/dapi-client/lib/methods/platform/getDocuments/GetDocumentsResponse';
import NotFoundError from '@dashevo/dapi-client/lib/transport/GrpcTransport/errors/NotFoundError';
Expand Down Expand Up @@ -144,6 +146,8 @@ export async function get(this: Platform, typeLocator: string, opts: QueryOption

const result = await Promise.all(
rawDocuments.map(async (rawDocument) => {
// TODO(versioning): restore
// @ts-ignore
const document = await this.dpp.document.createExtendedDocumentFromDocumentBuffer(
rawDocument as Uint8Array, fieldType, appDefinition.contract,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PrivateKey } from '@dashevo/dashcore-lib';
import { IdentityPublicKey, StateTransitionExecutionContext } from '@dashevo/wasm-dpp';
import { IdentityPublicKey } from '@dashevo/wasm-dpp';
import { Platform } from '../../../Platform';

/**
Expand Down Expand Up @@ -36,27 +36,33 @@ export async function createIdentityCreateTransition(

// Create Identity
const identity = dpp.identity.create(
assetLockProof, [{
assetLockProof.createIdentifier(),
[new IdentityPublicKey({
$version: '0',
id: 0,
data: identityMasterPublicKey.toBuffer(),
type: IdentityPublicKey.TYPES.ECDSA_SECP256K1,
purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION,
securityLevel: IdentityPublicKey.SECURITY_LEVELS.MASTER,
readOnly: false,
},
{
}),
new IdentityPublicKey({
$version: '0',
id: 1,
data: identitySecondPublicKey.toBuffer(),
type: IdentityPublicKey.TYPES.ECDSA_SECP256K1,
purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION,
securityLevel: IdentityPublicKey.SECURITY_LEVELS.HIGH,
readOnly: false,
},
}),
],
);

// Create ST
const identityCreateTransition = dpp.identity.createIdentityCreateTransition(identity);
const identityCreateTransition = dpp.identity.createIdentityCreateTransition(
identity,
assetLockProof,
);

// Create key proofs

Expand Down Expand Up @@ -84,17 +90,19 @@ export async function createIdentityCreateTransition(
await identityCreateTransition
.signByPrivateKey(assetLockPrivateKey.toBuffer(), IdentityPublicKey.TYPES.ECDSA_SECP256K1);

const result = await dpp.stateTransition.validateBasic(
identityCreateTransition,
// TODO(v0.24-backport): get rid of this once decided
// whether we need execution context in wasm bindings
new StateTransitionExecutionContext(),
);

if (!result.isValid()) {
const messages = result.getErrors().map((error) => error.message);
throw new Error(`StateTransition is invalid - ${JSON.stringify(messages)}`);
}
// TODO(versioning): restore
// @ts-ignore
// const result = await dpp.stateTransition.validateBasic(
// identityCreateTransition,
// // TODO(v0.24-backport): get rid of this once decided
// // whether we need execution context in wasm bindings
// new StateTransitionExecutionContext(),
// );

// if (!result.isValid()) {
// const messages = result.getErrors().map((error) => error.message);
// throw new Error(`StateTransition is invalid - ${JSON.stringify(messages)}`);
// }

return { identity, identityCreateTransition, identityIndex };
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PrivateKey } from '@dashevo/dashcore-lib';
import { IdentityPublicKey, StateTransitionExecutionContext } from '@dashevo/wasm-dpp';
import { IdentityPublicKey } from '@dashevo/wasm-dpp';
import { Platform } from '../../../Platform';

/**
Expand Down Expand Up @@ -30,19 +30,23 @@ export async function createIdentityTopUpTransition(
);

await identityTopUpTransition
// TODO(versioning): restore
// @ts-ignore
.signByPrivateKey(assetLockPrivateKey.toBuffer(), IdentityPublicKey.TYPES.ECDSA_SECP256K1);

const result = await dpp.stateTransition.validateBasic(
identityTopUpTransition,
// TODO(v0.24-backport): get rid of this once decided
// whether we need execution context in wasm bindings
new StateTransitionExecutionContext(),
);

if (!result.isValid()) {
const messages = result.getErrors().map((error) => error.message);
throw new Error(`StateTransition is invalid - ${JSON.stringify(messages)}`);
}
// TODO(versioning): restore
// @ts-ignore
// const result = await dpp.stateTransition.validateBasic(
// identityTopUpTransition,
// // TODO(v0.24-backport): get rid of this once decided
// // whether we need execution context in wasm bindings
// new StateTransitionExecutionContext(),
// );

// if (!result.isValid()) {
// const messages = result.getErrors().map((error) => error.message);
// throw new Error(`StateTransition is invalid - ${JSON.stringify(messages)}`);
// }

return identityTopUpTransition;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO(versioning): restore
// @ts-ignore
import { Identity, IdentityPublicKey, StateTransitionExecutionContext } from '@dashevo/wasm-dpp';
import { Platform } from '../../Platform';
import { signStateTransition } from '../../signStateTransition';
Expand Down Expand Up @@ -57,6 +59,8 @@ export async function update(

identityUpdateTransition.setSignaturePublicKeyId(signerKey.getId());

// TODO(versioning): restore
// @ts-ignore
await identityUpdateTransition.signByPrivateKey(privateKey.toBuffer(), publicKey.getType());

publicKey.setSignature(identityUpdateTransition.getSignature());
Expand All @@ -75,17 +79,19 @@ export async function update(
await signStateTransition(this, identityUpdateTransition, identity, signerKeyIndex);
this.logger.silly('[Identity#update] Signed IdentityUpdateTransition');

const result = await dpp.stateTransition.validateBasic(
identityUpdateTransition,
// TODO(v0.24-backport): get rid of this once decided
// whether we need execution context in wasm bindings
new StateTransitionExecutionContext(),
);

if (!result.isValid()) {
const messages = result.getErrors().map((error) => error.message);
throw new Error(`StateTransition is invalid - ${JSON.stringify(messages)}`);
}
// TODO(versioning): restore
// @ts-ignore
// const result = await dpp.stateTransition.validateBasic(
// identityUpdateTransition,
// // TODO(v0.24-backport): get rid of this once decided
// // whether we need execution context in wasm bindings
// new StateTransitionExecutionContext(),
// );

// if (!result.isValid()) {
// const messages = result.getErrors().map((error) => error.message);
// throw new Error(`StateTransition is invalid - ${JSON.stringify(messages)}`);
// }
this.logger.silly('[Identity#update] Validated IdentityUpdateTransition');

// Skipping validation because it's already done above
Expand Down
2 changes: 2 additions & 0 deletions packages/js-dash-sdk/src/SDK/Client/Platform/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO(versioning): restore
// @ts-ignore
import { Identifier, ExtendedDocument } from '@dashevo/wasm-dpp';

/**
Expand Down
Loading
Loading