Skip to content

Commit

Permalink
Fix pure proxy check, #919
Browse files Browse the repository at this point in the history
  • Loading branch information
wliyongfeng committed Aug 20, 2024
1 parent e2c7c46 commit b3a4e59
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
19 changes: 19 additions & 0 deletions backend/packages/mongo/src/palletProxy/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,27 @@ async function getAllActiveProxiesOfDelegator(delegator) {
return await col.find({ delegator, isRemoved: false }).toArray();
}

async function isPureProxyDelegator(delegator) {
if (!delegator) {
return false;
}

const col = await getProxyCol();
const proxies = await col
.find({ delegator })
.sort({ "indexer.blockHeight": 1 })
.toArray();
if ((proxies || []).length <= 0) {
return false;
}

const firstProxy = proxies[0];
return firstProxy.isPure;
}

module.exports = {
upsertProxyIfNo,
markProxyRemoved,
getAllActiveProxiesOfDelegator,
isPureProxyDelegator,
};
2 changes: 1 addition & 1 deletion backend/packages/pallet-proxy-scan/src/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
(async () => {
await initPalletProxyScanDb();
await subscribeFinalizedHeight();
const blockHeights = [2748486, 4197210];
const blockHeights = [247043, 2727281];

const api = await getApi();
for (const height of blockHeights) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {
} = require("@osn/scan-common");
const { generateProxyId } = require("../../common/hash");
const {
palletProxy: { upsertProxyIfNo, getProxyTimelineCol },
palletProxy: { upsertProxyIfNo, getProxyTimelineCol, isPureProxyDelegator },
} = require("@statescan/mongo");
const {
store: { setKnownHeightMark },
Expand Down Expand Up @@ -35,14 +35,15 @@ async function handleAddProxy(call, signer, extrinsicIndexer) {
const type = call.args[1].toString();
const proxyId = generateProxyId(signer, delegatee, type, delay);

const isPure = await isPureProxyDelegator(signer);
await upsertProxyIfNo({
proxyId,
delegator: signer,
delegatee,
type,
delay,
isRemoved: false,
isPure: false,
isPure,
indexer: extrinsicIndexer,
});

Expand Down

0 comments on commit b3a4e59

Please sign in to comment.