Skip to content

Commit

Permalink
fix(ref-imp): #820 - Deactivate not working
Browse files Browse the repository at this point in the history
  • Loading branch information
thehenrytsai committed Sep 10, 2020
1 parent 438ff11 commit 97b31ac
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 66 deletions.
4 changes: 2 additions & 2 deletions lib/bitcoin/lock/LockMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ export default class LockMonitor {
await this.handlePeriodicPolling();

} catch (e) {
const message = `An error occured during periodic poll: ${SidetreeError.stringify(e)}`;
const message = `An error occurred during periodic poll: ${SidetreeError.stringify(e)}`;
console.error(message);

// Rethrow if the error is in the initialization phase. We don't want to conitinue with the
// Rethrow if the error is in the initialization phase. We don't want to continue with the
// service during initialization.
if (!this.initialized) {
throw e;
Expand Down
2 changes: 1 addition & 1 deletion lib/core/versions/0.11.0/DeactivateOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class DeactivateOperation implements OperationModel {
public readonly signedData: SignedDataModel;

/**
* NOTE: should only be used by `parse()` and `parseObject()` else the contructed instance could be invalid.
* NOTE: should only be used by `parse()` and `parseObject()` else the constructed instance could be invalid.
*/
private constructor (
operationBuffer: Buffer,
Expand Down
39 changes: 16 additions & 23 deletions lib/core/versions/0.11.0/TransactionProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import IVersionMetadataFetcher from '../../interfaces/IVersionMetadataFetcher';
import JsonAsync from './util/JsonAsync';
import LogColor from '../../../common/LogColor';
import MapFile from './MapFile';
import OperationType from '../../enums/OperationType';
import ProtocolParameters from './ProtocolParameters';
import SidetreeError from '../../../common/SidetreeError';
import TransactionModel from '../../../common/models/TransactionModel';
Expand Down Expand Up @@ -222,37 +223,29 @@ export default class TransactionProcessor implements ITransactionProcessor {
operations.push(...updateOperations);
operations.push(...deactivateOperations);

// If chunk file is found/given, we need to add `type` and `delta` from chunk file to each operation.
// NOTE: there is no delta for deactivate operations.
const patchedOperationBuffers: Buffer[] = [];
if (chunkFile !== undefined) {

// TODO: Issue 442 - https://github.com/decentralized-identity/sidetree/issues/442
// Use actual operation request object instead of buffer.

const operationCountExcludingDeactivates = createOperations.length + recoverOperations.length + updateOperations.length;
for (let i = 0; i < operationCountExcludingDeactivates &&
i < chunkFile.deltas.length; i++) {
const operation = operations[i];
const operationJsonString = operation.operationBuffer.toString();
const operationObject = await JsonAsync.parse(operationJsonString);
operationObject.type = operation.type;
operationObject.delta = chunkFile.deltas[i];

const patchedOperationBuffer = Buffer.from(JSON.stringify(operationObject));
patchedOperationBuffers.push(patchedOperationBuffer);
}
}
// TODO: Issue 442 - https://github.com/decentralized-identity/sidetree/issues/442
// Use actual operation request object instead of buffer.

// Add anchored timestamp to each operation.
// NOTE: The last set of `operations` are deactivates, they don't have `delta` property.
const anchoredOperationModels = [];
for (let i = 0; i < operations.length; i++) {
const operation = operations[i];
const operationJsonString = operation.operationBuffer.toString();
const operationObject = await JsonAsync.parse(operationJsonString);
operationObject.type = operation.type;

// Add `delta` property read from chunk file to each operation if chunk file exists.
// NOTE: Deactivate operation does not have delta.
if (chunkFile !== undefined &&
operation.type !== OperationType.Deactivate) {
operationObject.delta = chunkFile.deltas[i];
}

const patchedOperationBuffer = Buffer.from(JSON.stringify(operationObject));
const anchoredOperationModel: AnchoredOperationModel = {
didUniqueSuffix: operation.didUniqueSuffix,
type: operation.type,
operationBuffer: patchedOperationBuffers[i],
operationBuffer: patchedOperationBuffer,
operationIndex: i,
transactionNumber: transaction.transactionNumber,
transactionTime: transaction.transactionTime
Expand Down
2 changes: 1 addition & 1 deletion lib/core/versions/latest/DeactivateOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class DeactivateOperation implements OperationModel {
public readonly signedData: SignedDataModel;

/**
* NOTE: should only be used by `parse()` and `parseObject()` else the contructed instance could be invalid.
* NOTE: should only be used by `parse()` and `parseObject()` else the constructed instance could be invalid.
*/
private constructor (
operationBuffer: Buffer,
Expand Down
39 changes: 16 additions & 23 deletions lib/core/versions/latest/TransactionProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import IVersionMetadataFetcher from '../../interfaces/IVersionMetadataFetcher';
import JsonAsync from './util/JsonAsync';
import LogColor from '../../../common/LogColor';
import MapFile from './MapFile';
import OperationType from '../../enums/OperationType';
import ProtocolParameters from './ProtocolParameters';
import SidetreeError from '../../../common/SidetreeError';
import TransactionModel from '../../../common/models/TransactionModel';
Expand Down Expand Up @@ -222,37 +223,29 @@ export default class TransactionProcessor implements ITransactionProcessor {
operations.push(...updateOperations);
operations.push(...deactivateOperations);

// If chunk file is found/given, we need to add `type` and `delta` from chunk file to each operation.
// NOTE: there is no delta for deactivate operations.
const patchedOperationBuffers: Buffer[] = [];
if (chunkFile !== undefined) {

// TODO: Issue 442 - https://github.com/decentralized-identity/sidetree/issues/442
// Use actual operation request object instead of buffer.

const operationCountExcludingDeactivates = createOperations.length + recoverOperations.length + updateOperations.length;
for (let i = 0; i < operationCountExcludingDeactivates &&
i < chunkFile.deltas.length; i++) {
const operation = operations[i];
const operationJsonString = operation.operationBuffer.toString();
const operationObject = await JsonAsync.parse(operationJsonString);
operationObject.type = operation.type;
operationObject.delta = chunkFile.deltas[i];

const patchedOperationBuffer = Buffer.from(JSON.stringify(operationObject));
patchedOperationBuffers.push(patchedOperationBuffer);
}
}
// TODO: Issue 442 - https://github.com/decentralized-identity/sidetree/issues/442
// Use actual operation request object instead of buffer.

// Add anchored timestamp to each operation.
// NOTE: The last set of `operations` are deactivates, they don't have `delta` property.
const anchoredOperationModels = [];
for (let i = 0; i < operations.length; i++) {
const operation = operations[i];
const operationJsonString = operation.operationBuffer.toString();
const operationObject = await JsonAsync.parse(operationJsonString);
operationObject.type = operation.type;

// Add `delta` property read from chunk file to each operation if chunk file exists.
// NOTE: Deactivate operation does not have delta.
if (chunkFile !== undefined &&
operation.type !== OperationType.Deactivate) {
operationObject.delta = chunkFile.deltas[i];
}

const patchedOperationBuffer = Buffer.from(JSON.stringify(operationObject));
const anchoredOperationModel: AnchoredOperationModel = {
didUniqueSuffix: operation.didUniqueSuffix,
type: operation.type,
operationBuffer: patchedOperationBuffers[i],
operationBuffer: patchedOperationBuffer,
operationIndex: i,
transactionNumber: transaction.transactionNumber,
transactionTime: transaction.transactionTime
Expand Down
184 changes: 176 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
Expand Up @@ -37,7 +37,7 @@
"copyfiles": "2.3.0",
"cz-conventional-changelog": "3.1.0",
"husky": "1.3.1",
"jasmine": "3.4.0",
"jasmine": "^3.6.1",
"jasmine-reporters": "2.3.2",
"jasmine-spec-reporter": "4.2.1",
"nyc": "15.0.1",
Expand Down
Loading

0 comments on commit 97b31ac

Please sign in to comment.