Skip to content

Commit

Permalink
Improvments/add range for bid suggestion (#135)
Browse files Browse the repository at this point in the history
* Add range for bid suggestion

* Fix getBidSuggetions returns object when all is param

* Update services/validation-service.js

Co-authored-by: Nikola Todorovic <[email protected]>

* Version bump

* New version build

* Update package-lock

---------

Co-authored-by: Nikola Todorovic <[email protected]>
  • Loading branch information
Mihajlo-Pavlovic and NZT48 authored Apr 10, 2024
1 parent 4f1981e commit 93d0633
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 26 deletions.
16 changes: 16 additions & 0 deletions constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,17 @@ const DEFAULT_GAS_PRICE = {
OTP: '1',
};

const LOW_BID_SUGGESTION = 'low';
const MED_BID_SUGGESTION = 'med';
const HIGH_BID_SUGGESTION = 'high';
const ALL_BID_SUGGESTION = 'all';
const BID_SUGGESTION_RANGE_ENUM = [
LOW_BID_SUGGESTION,
MED_BID_SUGGESTION,
HIGH_BID_SUGGESTION,
ALL_BID_SUGGESTION,
];

module.exports = {
MAX_FILE_SIZE,
DID_PREFIX,
Expand All @@ -225,4 +236,9 @@ module.exports = {
DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS,
DEFAULT_PARAMETERS,
DEFAULT_GAS_PRICE,
LOW_BID_SUGGESTION,
MED_BID_SUGGESTION,
HIGH_BID_SUGGESTION,
ALL_BID_SUGGESTION,
BID_SUGGESTION_RANGE_ENUM,
};
2 changes: 1 addition & 1 deletion dist/dkg.min.js

Large diffs are not rendered by default.

36 changes: 22 additions & 14 deletions managers/network-operations-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,35 @@ class NetworkOperationsManager {
* @returns {BigInt} Suggested bid for publishing Knowledge Asset with given parameters.
*/
async getBidSuggestion(publicAssertionId, sizeInBytes, options = {}) {
const { blockchain, endpoint, port, epochsNum, hashFunctionId, authToken } =
this.inputService.getBidSuggestionArguments(options);
const {
blockchain,
endpoint,
port,
epochsNum,
hashFunctionId,
authToken,
bidSuggestionRange,
} = this.inputService.getBidSuggestionArguments(options);

const contentAssetStorageAddress = await this.blockchainService.getContractAddress(
'ContentAssetStorage',
blockchain,
);

return BigInt(
await this.nodeApiService.getBidSuggestion(
endpoint,
port,
authToken,
blockchain.name,
epochsNum,
sizeInBytes,
contentAssetStorageAddress,
publicAssertionId,
hashFunctionId,
),
const response = await this.nodeApiService.getBidSuggestion(
endpoint,
port,
authToken,
blockchain.name,
epochsNum,
sizeInBytes,
contentAssetStorageAddress,
publicAssertionId,
hashFunctionId,
bidSuggestionRange,
);

return typeof response === 'string' ? BigInt(response) : response;
}
}
module.exports = NetworkOperationsManager;
4 changes: 2 additions & 2 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
@@ -1,6 +1,6 @@
{
"name": "dkg.js",
"version": "6.2.0",
"version": "6.2.1",
"description": "Javascript library for interaction with the OriginTrail Decentralized Knowledge Graph",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 6 additions & 0 deletions services/input-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const {
DEFAULT_PARAMETERS,
DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS,
BLOCKCHAINS,
LOW_BID_SUGGESTION,
} = require('../constants');

class InputService {
Expand All @@ -17,6 +18,7 @@ class InputService {
epochsNum: this.getEpochsNum(options),
hashFunctionId: this.getHashFunctionId(options),
authToken: this.getAuthToken(options),
bidSuggestionRange: this.getBidSuggestionRange(options),
};
}

Expand Down Expand Up @@ -200,6 +202,10 @@ class InputService {
getAuthToken(options) {
return options.auth?.token ?? this.config?.auth?.token ?? null;
}

getBidSuggestionRange(options) {
return options.bidSuggestionRange ?? LOW_BID_SUGGESTION;
}
}

module.exports = InputService;
21 changes: 13 additions & 8 deletions services/node-api-service/implementations/http-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,24 @@ class HttpService {
contentAssetStorageAddress,
firstAssertionId,
hashFunctionId,
bidSuggestionRange,
) {
try {
const params = {
blockchain,
epochsNumber,
assertionSize,
contentAssetStorageAddress,
firstAssertionId,
hashFunctionId,
};
if (bidSuggestionRange != null) {
params.bidSuggestionRange = bidSuggestionRange;
}
const response = await axios({
method: 'get',
url: `${endpoint}:${port}/bid-suggestion`,
params: {
blockchain,
epochsNumber,
assertionSize,
contentAssetStorageAddress,
firstAssertionId,
hashFunctionId,
},
params,
headers: this.prepareRequestConfig(authToken),
});

Expand Down
13 changes: 13 additions & 0 deletions services/validation-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
OPERATIONS,
GET_OUTPUT_FORMATS,
QUERY_TYPES,
BID_SUGGESTION_RANGE_ENUM,
} = require('../constants.js');
const { nodeSupported } = require('./utilities.js');

Expand Down Expand Up @@ -402,5 +403,17 @@ class ValidationService {
this.validateRequiredParam('newOwner', newOwner);
this.validateParamType('newOwner', newOwner, 'string');
}

validateGetBidSuggestion(bidSuggestionRange) {
this.validateBidSuggestionRange(bidSuggestionRange);
}

validateBidSuggestionRange(bidSuggestionRange) {
if (!BID_SUGGESTION_RANGE_ENUM.includes(bidSuggestionRange)) {
throw Error(
`Invalid bidSuggestionRange parametar: supported parametars ${BID_SUGGESTION_RANGE_ENUM}`,
);
}
}
}
module.exports = ValidationService;

0 comments on commit 93d0633

Please sign in to comment.