-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…h backward compatibility (#273) * Issue #269 - Added VersionManager and TransactionProcessor. * Issue #269 - Introduced IProtocolVersion. * Issue #269 - Implemented version loading. * Issue #269 - Fixed incomplete initialization for VersionManager. * Issue #269 & #166 - Split Operation class into an additional AnchoredOperation class. * Issue #269 & #272 - Moved Resolver to orchestration layer & Renamed interfaces. * Issue #269 - Removed dummy test file. * #272 - Updated README.
- Loading branch information
1 parent
3e840e8
commit 7d66cf5
Showing
101 changed files
with
1,730 additions
and
1,512 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Common error codes used across services. | ||
*/ | ||
export default { | ||
InvalidTransactionNumberOrTimeHash: 'invalid_transaction_number_or_time_hash' | ||
}; |
4 changes: 2 additions & 2 deletions
4
lib/common/IFetchResult.ts → lib/common/models/FetchResult.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/common/ITransaction.ts → lib/common/models/TransactionModel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import IBatchWriter from './interfaces/IBatchWriter'; | ||
import IBlockchain from './interfaces/IBlockchain'; | ||
import timeSpan = require('time-span'); | ||
|
||
/** | ||
* Class that performs periodic writing of batches of Sidetree operations to CAS and blockchain. | ||
*/ | ||
export default class BatchScheduler { | ||
/** | ||
* Flag indicating if this Batch Writer is currently processing a batch of operations. | ||
*/ | ||
private processing: boolean = false; | ||
|
||
public constructor ( | ||
private getBatchWriter: (blockchainTime: number) => IBatchWriter, | ||
private blockchain: IBlockchain, | ||
private batchingIntervalInSeconds: number) { | ||
} | ||
|
||
/** | ||
* The function that starts periodically anchoring operation batches to blockchain. | ||
*/ | ||
public startPeriodicBatchWriting () { | ||
setInterval(async () => this.writeOperationBatch(), this.batchingIntervalInSeconds * 1000); | ||
} | ||
|
||
/** | ||
* Processes the operations in the queue. | ||
*/ | ||
public async writeOperationBatch () { | ||
const endTimer = timeSpan(); // For calcuating time taken to write operations. | ||
|
||
// Wait until the next interval if the Batch Writer is still processing a batch. | ||
if (this.processing) { | ||
return; | ||
} | ||
|
||
try { | ||
console.info('Start operation batch writing...'); | ||
this.processing = true; | ||
|
||
// Get the correct version of the `BatchWriter`. | ||
const currentTime = this.blockchain.approximateTime.time; | ||
const batchWriter = this.getBatchWriter(currentTime); | ||
|
||
await batchWriter.write(); | ||
} catch (error) { | ||
console.error('Unexpected and unhandled error during batch writing, investigate and fix:'); | ||
console.error(error); | ||
} finally { | ||
this.processing = false; | ||
|
||
console.info(`End batch writing. Duration: ${endTimer.rounded()} ms.`); | ||
} | ||
} | ||
} |
Oops, something went wrong.