Skip to content

Commit

Permalink
Merge branch 'filter-unspent-address-api' into 'dev'
Browse files Browse the repository at this point in the history
Add filter to ensure node api issue do not interefere with the permit check results

Closes #42

See merge request ergo/rosen-bridge/health-check!39
  • Loading branch information
vorujack committed Dec 23, 2024
2 parents 844aa41 + dd00b84 commit 4adaf03
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-yaks-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/permit-check': patch
---

Add filter to ensure node api issue do not interefere with the permit check results
29 changes: 21 additions & 8 deletions packages/permit-check/lib/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
});

Expand Down
4 changes: 4 additions & 0 deletions packages/permit-check/tests/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const explorerUnspentBoxesByAddress = {

export const nodeUnspentBoxesByAddress = [
{
address: 'permitAddress',
assets: [
{
tokenId:
Expand All @@ -74,6 +75,7 @@ export const nodeUnspentBoxesByAddress = [
},
},
{
address: 'permitAddress',
assets: [
{
tokenId:
Expand All @@ -87,6 +89,7 @@ export const nodeUnspentBoxesByAddress = [
},
},
{
address: 'permitAddress',
assets: [
{
tokenId:
Expand All @@ -100,6 +103,7 @@ export const nodeUnspentBoxesByAddress = [
},
},
{
address: 'permitAddress',
assets: [
{
tokenId:
Expand Down

0 comments on commit 4adaf03

Please sign in to comment.