Skip to content

Commit

Permalink
check for data
Browse files Browse the repository at this point in the history
  • Loading branch information
bryzettler committed Jan 23, 2025
1 parent f4924c5 commit aa6b4eb
Showing 1 changed file with 53 additions and 49 deletions.
102 changes: 53 additions & 49 deletions packages/helium-admin-cli/src/backfill-mobile-deployment-infos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,56 +183,60 @@ export async function run(args: any = process.argv) {
const ixs = (
await Promise.all(
accountInfosWithPk.map(async (acc) => {
let correction: {
location?: anchor.BN;
deploymentInfo?: MobileDeploymentInfoV0;
} = {};

const decodedAcc: MobileHotspotInfo = hem.coder.accounts.decode(
"MobileHotspotInfoV0",
acc.data as Buffer
);

const hasNewDeploymentInfo =
!decodedAcc.deploymentInfo && hasDeploymentInfo(acc.wifiInfo);
const deploymentInfoChanged = !deepEqual(
decodedAcc.deploymentInfo?.wifiInfoV0,
acc.wifiInfo.deploymentInfo
);

const locationMissing = !decodedAcc.location && acc.wifiInfo.location;
const locationChanged =
decodedAcc.location && !acc.wifiInfo.location.eq(decodedAcc.location);

if (hasNewDeploymentInfo || deploymentInfoChanged) {
correction = {
...correction,
deploymentInfo: {
wifiInfoV0: {
...acc.wifiInfo.deploymentInfo,
if (acc.data) {
let correction: {
location?: anchor.BN;
deploymentInfo?: MobileDeploymentInfoV0;
} = {};

const decodedAcc: MobileHotspotInfo = hem.coder.accounts.decode(
"MobileHotspotInfoV0",
acc.data as Buffer
);

const hasNewDeploymentInfo =
!decodedAcc.deploymentInfo && hasDeploymentInfo(acc.wifiInfo);
const deploymentInfoChanged = !deepEqual(
decodedAcc.deploymentInfo?.wifiInfoV0,
acc.wifiInfo.deploymentInfo
);

const locationMissing = !decodedAcc.location && acc.wifiInfo.location;
const locationChanged =
decodedAcc.location &&
!acc.wifiInfo.location.eq(decodedAcc.location);

if (hasNewDeploymentInfo || deploymentInfoChanged) {
correction = {
...correction,
deploymentInfo: {
wifiInfoV0: {
...acc.wifiInfo.deploymentInfo,
},
},
},
};
}

if (locationMissing || locationChanged) {
correction = {
...correction,
location: acc.wifiInfo.location,
};
}

if (Object.keys(correction).length > 0) {
return await hem.methods
.tempBackfillMobileInfo({
location: correction.location || null,
deploymentInfo: correction.deploymentInfo || null,
})
.accounts({
payer: wallet.publicKey,
mobileInfo: acc.pubkey,
})
.instruction();
};
}

if (locationMissing || locationChanged) {
correction = {
...correction,
location: acc.wifiInfo.location,
};
}

if (Object.keys(correction).length > 0) {
console.log("ERHE");
return await hem.methods
.tempBackfillMobileInfo({
location: correction.location || null,
deploymentInfo: correction.deploymentInfo || null,
})
.accounts({
payer: wallet.publicKey,
mobileInfo: acc.pubkey,
})
.instruction();
}
}
})
)
Expand Down

0 comments on commit aa6b4eb

Please sign in to comment.