Skip to content

Commit

Permalink
Merge pull request #2993 from OriginTrail/fix/proximityScoreFunctions…
Browse files Browse the repository at this point in the history
…PairId-is-0

Backwards compatibility fix for proximity score function pair id
  • Loading branch information
NZT48 authored Feb 14, 2024
2 parents 4cb3749 + e0ba273 commit ef269c8
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/commands/protocols/common/find-nodes-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class FindNodesCommand extends Command {
networkProtocols,
hashFunctionId,
minAckResponses,
proximityScoreFunctionsPairId,
} = command.data;
const proximityScoreFunctionsPairId = command.data.proximityScoreFunctionsPairId ?? 1;

this.errorType = errorType;
this.logger.debug(
Expand Down
10 changes: 2 additions & 8 deletions src/commands/protocols/common/protocol-init-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ import { NETWORK_MESSAGE_TYPES } from '../../../constants/constants.js';

class ProtocolInitCommand extends ProtocolMessageCommand {
async prepareMessage(command) {
const {
assertionId,
contract,
tokenId,
keyword,
hashFunctionId,
proximityScoreFunctionsPairId,
} = command.data;
const { assertionId, contract, tokenId, keyword, hashFunctionId } = command.data;
const proximityScoreFunctionsPairId = command.data.proximityScoreFunctionsPairId ?? 1;

// TODO: Backwards compatibility, send blockchain without chainId
const blockchain = command.data.blockchain.split(':')[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,8 @@ class ProtocolScheduleMessagesCommand extends Command {
}

getNextCommandData(command) {
const {
assertionId,
blockchain,
contract,
tokenId,
hashFunctionId,
proximityScoreFunctionsPairId,
} = command.data;
const { assertionId, blockchain, contract, tokenId, hashFunctionId } = command.data;
const proximityScoreFunctionsPairId = command.data.proximityScoreFunctionsPairId ?? 1;
return {
assertionId,
blockchain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ class GetInitCommand extends ProtocolInitCommand {
}

async prepareMessage(command) {
const { contract, tokenId, keyword, assertionId, state, proximityScoreFunctionsPairId } =
command.data;

const { contract, tokenId, keyword, assertionId, state } = command.data;
const proximityScoreFunctionsPairId = command.data.proximityScoreFunctionsPairId ?? 1;
// TODO: Backwards compatibility, send blockchain without chainId
const blockchain = command.data.blockchain.split(':')[0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,8 @@ class GetRequestCommand extends ProtocolRequestCommand {
}

async prepareMessage(command) {
const {
contract,
tokenId,
assertionId,
state,
hashFunctionId,
proximityScoreFunctionsPairId,
} = command.data;
const { contract, tokenId, assertionId, state, hashFunctionId } = command.data;
const proximityScoreFunctionsPairId = command.data.proximityScoreFunctionsPairId ?? 1;

// TODO: Backwards compatibility, send blockchain without chainId
const blockchain = command.data.blockchain.split(':')[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@ class HandleStoreInitCommand extends HandleProtocolMessageCommand {
}

async prepareMessage(commandData) {
const {
operationId,
assertionId,
blockchain,
contract,
tokenId,
keyword,
hashFunctionId,
proximityScoreFunctionsPairId,
} = commandData;
const { operationId, assertionId, blockchain, contract, tokenId, keyword, hashFunctionId } =
commandData;
const proximityScoreFunctionsPairId = commandData.proximityScoreFunctionsPairId ?? 1;

await this.operationIdService.updateOperationIdStatus(
operationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,9 @@ class HandleUpdateInitCommand extends HandleProtocolMessageCommand {
}

async prepareMessage(commandData) {
const {
operationId,
assertionId,
blockchain,
contract,
tokenId,
keyword,
hashFunctionId,
proximityScoreFunctionsPairId,
} = commandData;
const { operationId, assertionId, blockchain, contract, tokenId, keyword, hashFunctionId } =
commandData;
const proximityScoreFunctionsPairId = commandData.proximityScoreFunctionsPairId ?? 1;
await this.operationIdService.updateOperationIdStatus(
operationId,
blockchain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ class HandleUpdateRequestCommand extends HandleProtocolMessageCommand {
agreementId,
keyword,
hashFunctionId,
proximityScoreFunctionsPairId,
agreementData,
} = commandData;

const proximityScoreFunctionsPairId = commandData.proximityScoreFunctionsPairId ?? 1;

await this.operationIdService.updateOperationIdStatus(
operationId,
blockchain,
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/rpc/publish-rpc-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class PublishController extends BaseController {
tokenId: dataSource.tokenId,
keyword: dataSource.keyword,
hashFunctionId: message.data.hashFunctionId ?? CONTENT_ASSET_HASH_FUNCTION_ID,
proximityScoreFunctionsPairId: dataSource.proximityScoreFunctionsPairId,
proximityScoreFunctionsPairId: dataSource.proximityScoreFunctionsPairId ?? 1,
};

await this.commandExecutor.add(command);
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/rpc/update-rpc-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class UpdateController extends BaseController {
command.period = 5000;
command.retries = 3;
command.data.proximityScoreFunctionsPairId =
dataSource.proximityScoreFunctionsPairId;
dataSource.proximityScoreFunctionsPairId ?? 1;
break;
case NETWORK_MESSAGE_TYPES.REQUESTS.PROTOCOL_REQUEST:
// eslint-disable-next-line no-case-declarations
Expand All @@ -39,7 +39,7 @@ class UpdateController extends BaseController {
command.data.agreementId = dataSource.agreementId;
command.data.agreementData = dataSource.agreementData;
command.data.proximityScoreFunctionsPairId =
dataSource.agreementData.scoreFunctionId;
dataSource.agreementData.scoreFunctionId ?? 1;
break;
default:
throw Error('unknown message type');
Expand Down

0 comments on commit ef269c8

Please sign in to comment.