-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
2,091 additions
and
913 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,20 @@ | ||
import { Registry } from './registry'; | ||
import { allJsonRegistries, JsonRegistry } from './json'; | ||
import { sha256Hash } from './utils/sha256'; | ||
import { allJsonRegistries } from './json'; | ||
import { swapIfPreviewChain } from './preview'; | ||
import * as GlobalsJson from '../../registry/globals.json'; | ||
import { globalsFromJson, RegistryGlobals } from './globals'; | ||
import { RegistryGlobals } from './globals'; | ||
|
||
export class BundledClient { | ||
get(chainId: string): Registry { | ||
const jsonRegistry = this.getJsonRegistry(chainId); | ||
return new Registry(jsonRegistry); | ||
} | ||
|
||
private getJsonRegistry(chainId: string): JsonRegistry { | ||
const chainIdToIndex = swapIfPreviewChain(chainId); | ||
const jsonRegistry = allJsonRegistries[chainIdToIndex]; | ||
if (!jsonRegistry) { | ||
throw new Error(`Registry not found for ${chainIdToIndex}`); | ||
} | ||
return jsonRegistry; | ||
return new Registry(jsonRegistry); | ||
} | ||
|
||
globals(): RegistryGlobals { | ||
return globalsFromJson(GlobalsJson); | ||
} | ||
|
||
async version(chainId: string) { | ||
const registry = this.getJsonRegistry(chainId); | ||
const globals = this.globals(); | ||
const registryHash = await sha256Hash(JSON.stringify(registry)); | ||
const globalsHash = await sha256Hash(JSON.stringify(globals)); | ||
|
||
return await sha256Hash(registryHash + globalsHash); | ||
return new RegistryGlobals(GlobalsJson); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { RegistryGlobals } from './globals'; | ||
import { JsonGlobals } from './json'; | ||
|
||
const testGlobals: JsonGlobals = { | ||
rpcs: [{ name: 'rpc1', images: [], url: 'http://rpc1.com' }], | ||
frontends: ['frontend1', 'frontend2', 'frontend3'], | ||
stakingAssetId: { | ||
inner: 'KeqcLzNx9qSH5+lcJHBB9KNW+YPrBk5dKzvPMiypahA=', | ||
}, | ||
}; | ||
|
||
describe('Globals', () => { | ||
it('versions correctly', async () => { | ||
const registry = new RegistryGlobals(testGlobals); | ||
const version = await registry.version(); | ||
expect(version).toEqual('7e4059f5641482cfc817222cb5cbd6f62174d578d8473ff4b0a13ef643363b7e'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
import { Rpc } from './registry'; | ||
import { AssetId } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb'; | ||
import { JsonGlobals } from './json'; | ||
import { sha256Hash } from './utils/sha256'; | ||
|
||
export interface RegistryGlobals { | ||
rpcs: Rpc[]; | ||
frontends: string[]; | ||
stakingAssetId: AssetId; | ||
} | ||
export class RegistryGlobals { | ||
readonly stakingAssetId: AssetId; | ||
readonly rpcs: Rpc[]; | ||
readonly frontends: string[]; | ||
|
||
constructor(json: JsonGlobals) { | ||
this.rpcs = json.rpcs; | ||
this.frontends = json.frontends; | ||
this.stakingAssetId = AssetId.fromJson(json.stakingAssetId); | ||
} | ||
|
||
export const globalsFromJson = (json: JsonGlobals): RegistryGlobals => { | ||
return { | ||
...json, | ||
stakingAssetId: AssetId.fromJson(json.stakingAssetId), | ||
}; | ||
}; | ||
async version(): Promise<string> { | ||
return sha256Hash(JSON.stringify(this)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters