Skip to content

Commit

Permalink
Merge pull request #75 from OriginTrail/fix/extend-storing-period
Browse files Browse the repository at this point in the history
fix extend storing period
  • Loading branch information
NZT48 authored May 31, 2023
2 parents 4c49d44 + b7c4508 commit 1178bcb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 35 deletions.
2 changes: 1 addition & 1 deletion dist/dkg.min.js

Large diffs are not rendered by default.

39 changes: 18 additions & 21 deletions managers/asset-operations-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ class AssetOperationsManager {
);
return {
UAL,
publicAssertionId: publicAssertionId,
publicAssertionId,
operation: getOperationStatusObject(operationResult, operationId),
};
}
Expand Down Expand Up @@ -914,7 +914,14 @@ class AssetOperationsManager {
const blockchain = this.inputService.getBlockchain(options);
const tokenAmount = this.inputService.getTokenAmount(options);

const { tokenId } = resolveUAL(UAL);
this.validationService.validateExtendAssetStoringPeriod(
UAL,
epochsNumber,
tokenAmount,
blockchain,
);

const { tokenId, contract } = resolveUAL(UAL);

let tokenAmountInWei;

Expand All @@ -936,29 +943,19 @@ class AssetOperationsManager {
blockchain,
);

tokenAmountInWei = await this._getUpdateBidSuggestion(
UAL,
blockchain,
tokenAmountInWei = await this.nodeApiService.getBidSuggestion(
endpoint,
port,
authToken,
latestFinalizedState,
blockchain.name.startsWith('otp') ? 'otp' : blockchain.name,
epochsNumber,
latestFinalizedStateSize,
contract,
latestFinalizedState,
hashFunctionId,
);

if (tokenAmountInWei < 0) {
tokenAmountInWei = 0;
}
}

this.validationService.validateExtendAssetStoringPeriod(
UAL,
epochsNumber,
tokenAmountInWei,
blockchain,
);

await this.blockchainService.extendAssetStoringPeriod(
tokenId,
epochsNumber,
Expand All @@ -976,6 +973,8 @@ class AssetOperationsManager {
const blockchain = this.inputService.getBlockchain(options);
const tokenAmount = this.inputService.getTokenAmount(options);

this.validationService.validateAddTokens(UAL, tokenAmount, blockchain);

const { tokenId } = resolveUAL(UAL);

let tokenAmountInWei;
Expand Down Expand Up @@ -1016,8 +1015,6 @@ class AssetOperationsManager {
}
}

this.validationService.validateAddTokens(UAL, tokenAmountInWei, blockchain);

await this.blockchainService.addTokens(tokenId, tokenAmountInWei, blockchain);

return {
Expand All @@ -1030,6 +1027,8 @@ class AssetOperationsManager {
const blockchain = this.inputService.getBlockchain(options);
const tokenAmount = this.inputService.getTokenAmount(options);

this.validationService.validateAddTokens(UAL, tokenAmount, blockchain);

const { tokenId } = resolveUAL(UAL);

let tokenAmountInWei;
Expand Down Expand Up @@ -1069,8 +1068,6 @@ class AssetOperationsManager {
}
}

this.validationService.validateAddTokens(UAL, tokenAmountInWei, blockchain);

await this.blockchainService.addUpdateTokens(tokenId, tokenAmountInWei, blockchain);

return {
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dkg.js",
"version": "6.0.5",
"version": "6.0.6",
"description": "Javascript library for interaction with the OriginTrail Decentralized Knowledge Graph",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -29,7 +29,7 @@
},
"homepage": "https://github.com/OriginTrail/dkg.js/tree/master#readme",
"dependencies": {
"assertion-tools": "^2.0.2",
"assertion-tools": "^2.0.3",
"axios": "^0.27.2",
"dkg-evm-module": "^4.0.4",
"ethers": "^6.1.0",
Expand Down
4 changes: 2 additions & 2 deletions services/blockchain-service/blockchain-service-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class BlockchainServiceBase {
blockchain,
);

let tokensNeeded = BigInt(requestData.tokenAmount) - BigInt(allowance);
const tokensNeeded = BigInt(requestData.tokenAmount) - BigInt(allowance);

if (tokensNeeded > 0) {
await this.executeContractFunction(
Expand Down Expand Up @@ -217,7 +217,7 @@ class BlockchainServiceBase {
blockchain,
);

let tokensNeeded = BigInt(tokenAmount) - BigInt(allowance);
const tokensNeeded = BigInt(tokenAmount) - BigInt(allowance);

if (tokensNeeded > 0) {
await this.executeContractFunction(
Expand Down

0 comments on commit 1178bcb

Please sign in to comment.