Skip to content

Commit

Permalink
Add hotspot config to chain
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewcarlreetz committed Jul 18, 2024
1 parent 88e591d commit ac3bf14
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 149 deletions.
99 changes: 47 additions & 52 deletions packages/onboarding/src/HotspotOnboardingUtil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import OnboardingClient from './OnboardingClient'
import OnboardingClient, { OnboardingResponse } from './OnboardingClient'
import BN from 'bn.js'
import {
DC_MINT,
Expand All @@ -19,20 +19,10 @@ import {
rewardableEntityConfigKey,
} from '@helium/helium-entity-manager-sdk'
import * as Currency from '@helium/currency-utils'
import { HNT_AS_BONES, DcProgram, DeviceType, HemProgram, Maker, NetworkType } from './types'
import { HNT_AS_BONES, DcProgram, HemProgram, Maker, NetworkType } from './types'

const lowerFirst = (str: string) => str.charAt(0).toLowerCase() + str.slice(1)

const deviceTypeToNetworkType = (deviceType: DeviceType): NetworkType => {
// deviceType is null for IOT hotspots
// cbrs devices are both IOT and MOBILE hotspots, but the location, gain, and elevation are all stored on the IOT side
if (deviceType === null || deviceType === 'Cbrs') {
return 'IOT'
}

return 'MOBILE'
}

const hotspotInfoToDetails = (value: {
asset: PublicKey
bumpSeed: number
Expand All @@ -55,18 +45,12 @@ const hotspotInfoToDetails = (value: {
export const getHotspotNetworkDetails = async ({
address,
hemProgram,
...opts
}:
| {
address: string
networkType: NetworkType
hemProgram: HemProgram
}
| {
address: string
deviceType: DeviceType
hemProgram: HemProgram
}): Promise<
networkType,
}: {
address: string
networkType: NetworkType
hemProgram: HemProgram
}): Promise<
| {
elevation?: number
gain?: number
Expand All @@ -77,16 +61,6 @@ export const getHotspotNetworkDetails = async ({
}
| undefined
> => {
const types = { networkType: undefined, deviceType: undefined, ...opts }
let networkType = types.networkType
if (!networkType && types.deviceType !== undefined) {
networkType = deviceTypeToNetworkType(types.deviceType)
}

if (!networkType) {
throw new Error('Could not determine network type')
}

const mint = networkType === 'IOT' ? IOT_MINT : MOBILE_MINT
const subDao = subDaoKey(mint)[0]

Expand Down Expand Up @@ -208,9 +182,10 @@ const burnHNTForDataCredits = async ({
return txn
}

export const getAssertData = async ({
deviceType,
export const getUpdateMetaData = async ({
networkType,
gateway,
antenna,
azimuth,
hemProgram,
onboardingClient,
Expand All @@ -228,9 +203,10 @@ export const getAssertData = async ({
owner: PublicKey
decimalGain?: number
elevation?: number
antenna?: number
azimuth?: number
nextLocation: string
deviceType: DeviceType
networkType: NetworkType
onboardingClient: OnboardingClient
dcProgram: DcProgram
cluster: Cluster
Expand All @@ -246,22 +222,41 @@ export const getAssertData = async ({
makerKey = heliumAddressToSolPublicKey(onboardingRecord.data?.maker.address)
}

const networkType = deviceTypeToNetworkType(deviceType)
const solanaAddress = owner.toBase58()
let gain: number | undefined = undefined
if (decimalGain) {
gain = Math.round((decimalGain || 0) * 10.0)
}

const solResponse = await onboardingClient.updateMetadata({
type: networkType,
solanaAddress,
hotspotAddress: gateway,
location: nextLocation,
elevation,
gain,
azimuth,
})
let solResponse: OnboardingResponse<{
solanaTransactions: number[][]
}>

if (networkType === 'IOT') {
let gain: number | undefined = undefined
if (decimalGain) {
gain = Math.round((decimalGain || 0) * 10.0)
}

solResponse = await onboardingClient.updateIotMetadata({
solanaAddress,
hotspotAddress: gateway,
location: nextLocation,
elevation,
gain,
})
} else {
solResponse = await onboardingClient.updateMobileMetadata({
solanaAddress,
hotspotAddress: gateway,
location: nextLocation,
deploymentInfo: {
wifiInfoV0: {
elevation: elevation || 0,
azimuth: azimuth || 0,
antenna: antenna || 0,
mechanicalDownTilt: 0,
electricalDownTilt: 0,
},
},
})
}

const errFound = !solResponse.success ? solResponse : undefined

Expand All @@ -274,7 +269,7 @@ export const getAssertData = async ({
)

const networkDetails = await getHotspotNetworkDetails({
deviceType,
networkType,
address: gateway,
hemProgram,
})
Expand Down
56 changes: 25 additions & 31 deletions packages/onboarding/src/MobileHotspotOnboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
DeviceType,
HeightType,
ManufacturedDeviceType,
NetworkType,
OutdoorManufacturedDeviceType,
ProgressKeys,
ProgressStep,
Expand Down Expand Up @@ -198,47 +199,29 @@ export default class MobileHotspotOnboarding {
return this.getWifiClient().getApiVersion()
}

getWifiAssertData = async ({
getAssertData = async ({
gateway,
elevation,
location,
deviceType,
networkType,
azimuth,
antenna,
}: {
azimuth?: number
gateway: string
elevation?: number
location: string
deviceType: 'WifiIndoor' | 'WifiOutdoor'
}) => {
return this._solanaOnboarding.getAssertData({
azimuth,
gateway,
elevation,
location,
deviceType,
})
}

getCbrsAssertData = async ({
gateway,
decimalGain,
elevation,
location,
}: {
gateway: string
antenna?: number
networkType: NetworkType
decimalGain?: number
elevation?: number
location: string
}) => {
// We update assert data for the IOT network only
// For the MOBILE network we don't set location. They must update their radio location at https://hotspots.hellohelium.com
return this._solanaOnboarding.getAssertData({
return this._solanaOnboarding.getUpdateMetaData({
antenna,
azimuth,
gateway,
decimalGain,
elevation,
location,
deviceType: 'Cbrs',
networkType,
})
}

Expand All @@ -247,21 +230,29 @@ export default class MobileHotspotOnboarding {
azimuth,
location,
elevation,
antenna,
}: {
hotspotAddress: string
location?: string
elevation?: number
antenna?: number
azimuth?: number
}) => {
this.writeLog('Getting MOBILE onboard txns')
this.setProgressToStep('fetch_mobile')

const onboardTxns = await this._onboardingClient.onboard({
const onboardTxns = await this._onboardingClient.onboardMobile({
hotspotAddress,
location,
type: 'MOBILE',
elevation,
azimuth,
deploymentInfo: {
wifiInfoV0: {
elevation: elevation || 0,
azimuth: azimuth || 0,
antenna: antenna || 0,
mechanicalDownTilt: 0,
electricalDownTilt: 0,
},
},
})

if (!onboardTxns.data?.solanaTransactions?.length) {
Expand Down Expand Up @@ -455,9 +446,11 @@ export default class MobileHotspotOnboarding {
azimuth,
location,
elevation,
antenna,
...opts
}: AddToOnboardingServerOpts & {
addGatewayTxn: string
antenna?: number
location?: string
azimuth?: number | undefined
elevation?: number | undefined
Expand Down Expand Up @@ -520,6 +513,7 @@ export default class MobileHotspotOnboarding {
hotspotAddress,
azimuth,
elevation,
antenna,
})

return txns
Expand Down
Loading

0 comments on commit ac3bf14

Please sign in to comment.