Skip to content

Commit

Permalink
running off local ssh db
Browse files Browse the repository at this point in the history
  • Loading branch information
bryzettler committed Jan 28, 2025
1 parent b071bf6 commit 19d9a60
Showing 1 changed file with 18 additions and 39 deletions.
57 changes: 18 additions & 39 deletions packages/helium-admin-cli/src/backfill-mobile-deployment-infos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
MOBILE_MINT,
truthy,
} from "@helium/spl-utils";
import AWS from "aws-sdk";
import os from "os";
import { Client } from "pg";
import yargs from "yargs/yargs";
Expand All @@ -27,8 +26,6 @@ type WifiInfoRow = {
azimuth: number;
mechanical_down_tilt: number;
electrical_down_tilt: number;
lat: string;
lng: string;
};

type WifiInfo = {
Expand Down Expand Up @@ -82,13 +79,6 @@ export async function run(args: any = process.argv) {
pgPort: {
default: "5432",
},
awsRegion: {
default: "us-east-1",
},
noSsl: {
type: "boolean",
default: false,
},
commit: {
type: "boolean",
default: false,
Expand All @@ -105,29 +95,9 @@ export async function run(args: any = process.argv) {
const wallet = new anchor.Wallet(loadKeypair(argv.wallet));
const hem = await initHEM(provider);
const isRds = argv.pgHost.includes("rds.amazon.com");
let password = argv.pgPassword;

if (isRds && !password) {
const signer = new AWS.RDS.Signer({
region: argv.awsRegion,
hostname: argv.pgHost,
port: Number(argv.pgPort),
username: argv.pgUser,
});

password = await new Promise((resolve, reject) =>
signer.getAuthToken({}, (err, token) => {
if (err) {
return reject(err);
}
resolve(token);
})
);
}

const client = new Client({
user: argv.pgUser,
password,
password: argv.pgPassword,
host: argv.pgHost,
database: argv.pgDatabase,
port: Number(argv.pgPort),
Expand All @@ -141,7 +111,20 @@ export async function run(args: any = process.argv) {
await client.connect();
const [subDao] = subDaoKey(MOBILE_MINT);
const [rewardableEntityconfig] = rewardableEntityConfigKey(subDao, "MOBILE");
const wifiInfos = (await client.query(`SELECT * FROM wifi_infos`)).rows.map(
const wifiInfos = (
await client.query(`
SELECT c.hs_pubkey,
c.antenna,
c.height AS elevation,
c.azimuth AS azimuth,
c.mt AS mechanical_down_tilt,
c.et AS electrical_down_tilt
FROM radios AS r
JOIN calculations c ON r.last_success_calculation = c.id
WHERE r.is_active IS TRUE
AND radio_type = 'Wifi';
`)
).rows.map(
(wifiInfo: WifiInfoRow): WifiInfo => ({
...wifiInfo,
deploymentInfo: {
Expand Down Expand Up @@ -177,7 +160,6 @@ export async function run(args: any = process.argv) {
accountInfosWithPk.map(async (acc) => {
if (acc.data) {
let correction: {
location?: anchor.BN;
deploymentInfo?: MobileDeploymentInfoV0;
} = {};

Expand Down Expand Up @@ -207,7 +189,6 @@ export async function run(args: any = process.argv) {
if (Object.keys(correction).length > 0) {
return await hem.methods
.tempBackfillMobileInfo({
location: correction.location || null,
deploymentInfo: correction.deploymentInfo || null,
})
.accounts({
Expand All @@ -224,11 +205,9 @@ export async function run(args: any = process.argv) {
console.log(`Total corrections needed: ${ixs.length}`);
if (commit) {
try {
await Promise.all(
chunks(ixs, 100).map((chunk) =>
batchParallelInstructionsWithPriorityFee(provider, chunk)
)
);
for (const c of chunks(ixs, 250)) {
await batchParallelInstructionsWithPriorityFee(provider, c);
}
} catch (e) {
console.error("Failed to process mobile deployment info updates:", e);
process.exit(1);
Expand Down

0 comments on commit 19d9a60

Please sign in to comment.