Skip to content

Commit

Permalink
Merge pull request #3527 from OriginTrail/v8/fix/enable-bid-suggestio…
Browse files Browse the repository at this point in the history
…n-v0

Implement bid suggestion for backwards compatiblity
  • Loading branch information
Mihajlo-Pavlovic authored Dec 18, 2024
2 parents a14f1ba + 7b57bc2 commit 8147705
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,43 +1,18 @@
import BaseController from '../base-http-api-controller.js';
import { LOW_BID_SUGGESTION } from '../../../constants/constants.js';

class BidSuggestionController extends BaseController {
constructor(ctx) {
super(ctx);
this.repositoryModuleManager = ctx.repositoryModuleManager;
this.shardingTableService = ctx.shardingTableService;
this.blockchainModuleManager = ctx.blockchainModuleManager;
}

// TODO: We should use new on chain calculation
async handleRequest(req, res) {
if ((await this.repositoryModuleManager.getPeersCount(req.query.blockchain)) === 0) {
const message = `Unable to get bid suggestion. Empty sharding table for blockchain id: ${req.query.blockchain}`;
this.logger.error(message);
this.returnResponse(res, 406, {
code: 406,
message,
});
return;
}

let { bidSuggestionRange } = req.query;
try {
if (!bidSuggestionRange) {
bidSuggestionRange = LOW_BID_SUGGESTION;
}
// TODO: This isn't backwards compatible
// const bidSuggestion = await this.shardingTableService.getBidSuggestion(
// blockchain,
// epochsNumber,
// assertionSize,
// contentAssetStorageAddress,
// firstAssertionId,
// hashFunctionId,
// proximityScoreFunctionsPairId,
// bidSuggestionRange,
// );

const bidSuggestion = {};
const { blockchain, epochsNumber, assertionSize } = req.body;
const bidSuggestion =
(await this.blockchainModuleManager.getStakeWeightedAverageAsk(blockchain)) *
epochsNumber *
assertionSize;
this.returnResponse(res, 200, { bidSuggestion });
} catch (error) {
this.logger.error(`Unable to get bid suggestion. Error: ${error}`);
Expand Down
5 changes: 4 additions & 1 deletion src/modules/blockchain/blockchain-module-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,11 @@ class BlockchainModuleManager extends BaseModuleManager {
return this.callImplementationFunction(blockchain, 'signMessage', [messageHash]);
}

async getStakeWeightedAverageAsk(blockchain) {
return this.callImplementationFunction(blockchain, 'getStakeWeightedAverageAsk', []);
}

// SUPPORT FOR OLD CONTRACTS

async getLatestAssertionId(blockchain, assetContractAddress, tokenId) {
return this.callImplementationFunction(blockchain, 'getLatestAssertionId', [
assetContractAddress,
Expand Down
8 changes: 8 additions & 0 deletions src/modules/blockchain/implementation/web3-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,14 @@ class Web3Service {
return wallet.signMessage(ethers.utils.arrayify(messageHash));
}


async getStakeWeightedAverageAsk() {
return this.callContractFunction(
this.contracts.ShardingTableStorage,
'getStakeWeightedAverageAsk',
[],
);
}
// SUPPORT FOR OLD CONTRACTS

async getLatestAssertionId(assetContractAddress, tokenId) {
Expand Down

0 comments on commit 8147705

Please sign in to comment.