From 5a1befe0e74b2118c5119d44036118d4d18b07a0 Mon Sep 17 00:00:00 2001 From: "fateme.r" Date: Sun, 15 Dec 2024 18:46:46 +0330 Subject: [PATCH 1/3] Add filter to ensure node api issue do not interefere with the permit check results --- .changeset/serious-yaks-cross.md | 5 ++++ packages/permit-check/lib/node.ts | 38 ++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 .changeset/serious-yaks-cross.md diff --git a/.changeset/serious-yaks-cross.md b/.changeset/serious-yaks-cross.md new file mode 100644 index 0000000..19097d3 --- /dev/null +++ b/.changeset/serious-yaks-cross.md @@ -0,0 +1,5 @@ +--- +'@rosen-bridge/permit-check': patch +--- + +Add filter to ensure node api issue do not interefere with the permit check results diff --git a/packages/permit-check/lib/node.ts b/packages/permit-check/lib/node.ts index a57c0d4..b769521 100644 --- a/packages/permit-check/lib/node.ts +++ b/packages/permit-check/lib/node.ts @@ -40,19 +40,31 @@ class NodePermitHealthCheckParam extends AbstractPermitHealthCheckParam { limit: this.API_REQUEST_LIMIT, }); - boxes.forEach((box) => { - const R4 = box.additionalRegisters['R4']; - if ( - R4 && - Buffer.from( - wasm.Constant.decode_from_base16(R4).to_byte_array(), - ).toString('hex') === this.WID - ) { - RWTCount += - box.assets?.find((token) => token.tokenId === this.RWT)?.amount ?? - 0n; - } - }); + boxes + /** + * The getBoxesByAddressUnspent node API has issues: it returns not only + * unspent boxes for the specified address but also unrelated boxes from + * different addresses + * This filter is added to ensure such boxes do not interfere with the + * results + */ + .filter( + (box) => + box.address == this.permitAddress && box.spentTransactionId == null, + ) + .forEach((box) => { + const R4 = box.additionalRegisters['R4']; + if ( + R4 && + Buffer.from( + wasm.Constant.decode_from_base16(R4).to_byte_array(), + ).toString('hex') === this.WID + ) { + RWTCount += + box.assets?.find((token) => token.tokenId === this.RWT)?.amount ?? + 0n; + } + }); offset += this.API_REQUEST_LIMIT; } while (boxes.length > 0); From 9afbe21a91f0f7f46712752be302656ec4c51de7 Mon Sep 17 00:00:00 2001 From: "fateme.r" Date: Sun, 15 Dec 2024 18:52:26 +0330 Subject: [PATCH 2/3] fix unit tests to contain address --- packages/permit-check/tests/testData.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/permit-check/tests/testData.ts b/packages/permit-check/tests/testData.ts index 1933f6e..3e4f1b7 100644 --- a/packages/permit-check/tests/testData.ts +++ b/packages/permit-check/tests/testData.ts @@ -61,6 +61,7 @@ export const explorerUnspentBoxesByAddress = { export const nodeUnspentBoxesByAddress = [ { + address: 'permitAddress', assets: [ { tokenId: @@ -74,6 +75,7 @@ export const nodeUnspentBoxesByAddress = [ }, }, { + address: 'permitAddress', assets: [ { tokenId: @@ -87,6 +89,7 @@ export const nodeUnspentBoxesByAddress = [ }, }, { + address: 'permitAddress', assets: [ { tokenId: @@ -100,6 +103,7 @@ export const nodeUnspentBoxesByAddress = [ }, }, { + address: 'permitAddress', assets: [ { tokenId: From dd00b84f4cc723dc8a02a1fa30b5a0cc74d1b9b4 Mon Sep 17 00:00:00 2001 From: "fateme.r" Date: Sun, 22 Dec 2024 11:34:07 +0330 Subject: [PATCH 3/3] Add todo to remove extra filter --- packages/permit-check/lib/node.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/permit-check/lib/node.ts b/packages/permit-check/lib/node.ts index b769521..a2fbf3e 100644 --- a/packages/permit-check/lib/node.ts +++ b/packages/permit-check/lib/node.ts @@ -40,19 +40,19 @@ class NodePermitHealthCheckParam extends AbstractPermitHealthCheckParam { limit: this.API_REQUEST_LIMIT, }); - boxes + boxes.forEach((box) => { /** + * TODO: remove extra filter (local:ergo/rosen-bridge/health-check/-/issues/43) * The getBoxesByAddressUnspent node API has issues: it returns not only * unspent boxes for the specified address but also unrelated boxes from * different addresses * This filter is added to ensure such boxes do not interfere with the * results */ - .filter( - (box) => - box.address == this.permitAddress && box.spentTransactionId == null, - ) - .forEach((box) => { + if ( + box.address == this.permitAddress && + box.spentTransactionId == null + ) { const R4 = box.additionalRegisters['R4']; if ( R4 && @@ -64,7 +64,8 @@ class NodePermitHealthCheckParam extends AbstractPermitHealthCheckParam { box.assets?.find((token) => token.tokenId === this.RWT)?.amount ?? 0n; } - }); + } + }); offset += this.API_REQUEST_LIMIT; } while (boxes.length > 0);