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..a2fbf3e 100644 --- a/packages/permit-check/lib/node.ts +++ b/packages/permit-check/lib/node.ts @@ -41,16 +41,29 @@ class NodePermitHealthCheckParam extends AbstractPermitHealthCheckParam { }); boxes.forEach((box) => { - const R4 = box.additionalRegisters['R4']; + /** + * 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 + */ if ( - R4 && - Buffer.from( - wasm.Constant.decode_from_base16(R4).to_byte_array(), - ).toString('hex') === this.WID + box.address == this.permitAddress && + box.spentTransactionId == null ) { - RWTCount += - box.assets?.find((token) => token.tokenId === this.RWT)?.amount ?? - 0n; + 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; + } } }); 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: