Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adopt cosmic-proto types #119

Merged
merged 6 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/synthetic-chain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"name": "@agoric/synthetic-chain",
"version": "0.1.0",
"description": "Utilities to build a chain and test proposals atop it",
"bin": {
"synthetic-chain": "dist/cli/cli.js"
},
"bin": "dist/cli/cli.js",
"main": "./dist/lib/index.js",
"type": "module",
"module": "./dist/lib/index.js",
Expand All @@ -25,9 +23,11 @@
"@endo/zip": "^1.0.1",
"better-sqlite3": "^9.4.0",
"chalk": "^5.3.0",
"cosmjs-types": "^0.9.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why prefer cosmjs-types to @agoric/cosmic-proto or @cosmology/telescope?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fewer build layers

"execa": "^8.0.1"
},
"devDependencies": {
"@agoric/cosmic-proto": "^0.4.1-dev-c5284e4.0",
"@types/better-sqlite3": "^7.6.9",
"@types/node": "^18.19.14",
"ava": "^5.3.1",
Expand Down
16 changes: 8 additions & 8 deletions packages/synthetic-chain/src/cli/dockerfileGen.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import fs from 'node:fs';
import { Platform } from './build.js';
import {
type CoreEvalProposal,
type ProposalInfo,
type SoftwareUpgradeProposal,
encodeUpgradeInfo,
imageNameForProposal,
isPassed,
ParameterChangeProposal,
type CoreEvalPackage,
type ParameterChangePackage,
type ProposalInfo,
type SoftwareUpgradePackage,
} from './proposals.js';
import { Platform } from './build.js';

/**
* Templates for Dockerfile stages
Expand Down Expand Up @@ -58,7 +58,7 @@ FROM ghcr.io/agoric/agoric-3-proposals:${fromTag} as use-${fromTag}
proposalName,
upgradeInfo,
releaseNotes,
}: SoftwareUpgradeProposal,
}: SoftwareUpgradePackage,
lastProposal: ProposalInfo,
) {
const skipProposalValidation = !releaseNotes;
Expand Down Expand Up @@ -89,7 +89,7 @@ RUN ./run_prepare.sh ${path}
planName,
proposalName,
sdkImageTag,
}: SoftwareUpgradeProposal) {
}: SoftwareUpgradePackage) {
return `
# EXECUTE ${proposalName}
FROM ghcr.io/agoric/agoric-sdk:${sdkImageTag} as execute-${proposalName}
Expand All @@ -112,7 +112,7 @@ RUN ./run_execute.sh ${planName}
* - Run the core-eval scripts from the proposal. They are only guaranteed to have started, not completed.
*/
EVAL(
{ path, proposalName }: CoreEvalProposal | ParameterChangeProposal,
{ path, proposalName }: CoreEvalPackage | ParameterChangePackage,
lastProposal: ProposalInfo,
) {
return `
Expand Down
12 changes: 6 additions & 6 deletions packages/synthetic-chain/src/cli/proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type ProposalCommon = {
proposalIdentifier: string;
};

export type SoftwareUpgradeProposal = ProposalCommon & {
export type SoftwareUpgradePackage = ProposalCommon & {
sdkImageTag: string;
planName: string;
upgradeInfo?: unknown;
Expand All @@ -22,7 +22,7 @@ export type SoftwareUpgradeProposal = ProposalCommon & {
type: 'Software Upgrade Proposal';
};

export type CoreEvalProposal = ProposalCommon & {
export type CoreEvalPackage = ProposalCommon & {
type: '/agoric.swingset.CoreEvalProposal';
} & (
| { source: 'build'; buildScript: string }
Expand All @@ -32,14 +32,14 @@ export type CoreEvalProposal = ProposalCommon & {
}
);

export type ParameterChangeProposal = ProposalCommon & {
export type ParameterChangePackage = ProposalCommon & {
type: '/cosmos.params.v1beta1.ParameterChangeProposal';
};

export type ProposalInfo =
| SoftwareUpgradeProposal
| CoreEvalProposal
| ParameterChangeProposal;
| SoftwareUpgradePackage
| CoreEvalPackage
| ParameterChangePackage;

function readInfo(proposalPath: string): ProposalInfo {
assert(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { $, execaCommand } from 'execa';
import { BINARY } from './constants.js';

export const executeCommand = async (command, params, options = {}) => {
export const executeCommand = async (
command: string,
params: string[],
options = {},
) => {
const { stdout } = await execaCommand(
`${command} ${params.join(' ')}`,
options,
Expand All @@ -10,12 +14,12 @@ export const executeCommand = async (command, params, options = {}) => {
};

export const agd = {
query: async (...params) => {
query: async (...params: string[]) => {
const newParams = ['query', ...params, '-o json'];
const data = await executeCommand(BINARY, newParams);
return JSON.parse(data);
},
tx: async (...params) => {
tx: async (...params: string[]) => {
const newParams = [
'tx',
'-bblock',
Expand All @@ -27,7 +31,7 @@ export const agd = {
const data = await executeCommand(BINARY, newParams, { shell: true });
return JSON.parse(data);
},
keys: async (...params) => {
keys: async (...params: string[]) => {
let newParams = ['keys', ...params];
let shouldParse = true;

Expand All @@ -48,15 +52,15 @@ export const agd = {

return JSON.parse(data);
},
export: async (...params) => {
export: async (...params: string[]) => {
const newParams = ['export', ...params];
const data = await executeCommand(BINARY, newParams);
return JSON.parse(data);
},
};

export const agoric = {
follow: async (...params) => {
follow: async (...params: string[]) => {
let newParams = ['follow', ...params];
let parseJson = false;

Expand All @@ -72,11 +76,11 @@ export const agoric = {

return data;
},
wallet: async (...params) => {
wallet: async (...params: string[]) => {
const newParams = ['wallet', ...params];
return executeCommand('agoric', newParams);
},
run: async (...params) => {
run: async (...params: string[]) => {
const newParams = ['run', ...params];
return executeCommand('agoric', newParams);
},
Expand All @@ -88,7 +92,7 @@ export const { stdout: agopsLocation } = await $({
})`yarn bin agops`;

export const agops = {
vaults: async (...params) => {
vaults: async (...params: string[]) => {
const newParams = ['vaults', ...params];

const result = await executeCommand(agopsLocation, newParams);
Expand All @@ -101,19 +105,19 @@ export const agops = {

return result;
},
ec: async (...params) => {
ec: async (...params: string[]) => {
const newParams = ['ec', ...params];
return executeCommand(agopsLocation, newParams);
},
oracle: async (...params) => {
oracle: async (...params: string[]) => {
const newParams = ['oracle', ...params];
return executeCommand(agopsLocation, newParams);
},
perf: async (...params) => {
perf: async (...params: string[]) => {
const newParams = ['perf', ...params];
return executeCommand(agopsLocation, newParams);
},
auctioneer: async (...params) => {
auctioneer: async (...params: string[]) => {
const newParams = ['auctioneer', ...params];
return executeCommand(agopsLocation, newParams);
},
Expand All @@ -125,23 +129,23 @@ export const { stdout: bundleSourceLocation } = await $({
})`yarn bin bundle-source`;

/**
* @param {string} filePath
* @param {string} bundleName
* @returns {Promise<string>} Returns the filepath of the bundle
* @returns Returns the filepath of the bundle
*/
export const bundleSource = async (filePath, bundleName) => {
export const bundleSource = async (filePath: string, bundleName: string) => {
const output =
await $`${bundleSourceLocation} --cache-json /tmp ${filePath} ${bundleName}`;
console.log(output.stderr);
return `/tmp/bundle-${bundleName}.json`;
};

export const wellKnownIdentities = async (io = {}) => {
// @ts-expect-error
const { agoric: { follow = agoric.follow } = {} } = io;
const zip = (xs, ys) => xs.map((x, i) => [x, ys[i]]);
const fromSmallCapsEntries = txt => {
const zip = (xs: unknown[], ys: unknown[]) => xs.map((x, i) => [x, ys[i]]);
const fromSmallCapsEntries = (txt: string) => {
const { body, slots } = JSON.parse(txt);
const theEntries = zip(JSON.parse(body.slice(1)), slots).map(
// @ts-expect-error
([[name, ref], boardID]) => {
const iface = ref.replace(/^\$\d+\./, '');
return [name, { iface, boardID }];
Expand All @@ -166,11 +170,11 @@ export const wellKnownIdentities = async (io = {}) => {
};

export const smallCapsContext = () => {
const slots = []; // XXX global mutable state
const slots = [] as string[]; // XXX global mutable state
const smallCaps = {
Nat: n => `+${n}`,
Nat: (n: number | bigint) => `+${n}`,
// XXX mutates obj
ref: obj => {
ref: (obj: any) => {
if (obj.ix) return obj.ix;
const ix = slots.length;
slots.push(obj.boardID);
Expand All @@ -179,7 +183,7 @@ export const smallCapsContext = () => {
},
};

const toCapData = body => {
const toCapData = (body: unknown) => {
const capData = { body: `#${JSON.stringify(body)}`, slots };
return JSON.stringify(capData);
};
Expand Down
Loading