Skip to content

Commit 749eb48

Browse files
authored
Merge pull request #119 from Agoric/ta/cosmic-proto
adopt cosmic-proto types
2 parents 8cc7122 + c123dc9 commit 749eb48

File tree

9 files changed

+835
-74
lines changed

9 files changed

+835
-74
lines changed

packages/synthetic-chain/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
"name": "@agoric/synthetic-chain",
33
"version": "0.1.0",
44
"description": "Utilities to build a chain and test proposals atop it",
5-
"bin": {
6-
"synthetic-chain": "dist/cli/cli.js"
7-
},
5+
"bin": "dist/cli/cli.js",
86
"main": "./dist/lib/index.js",
97
"type": "module",
108
"module": "./dist/lib/index.js",
@@ -25,9 +23,11 @@
2523
"@endo/zip": "^1.0.1",
2624
"better-sqlite3": "^9.4.0",
2725
"chalk": "^5.3.0",
26+
"cosmjs-types": "^0.9.0",
2827
"execa": "^8.0.1"
2928
},
3029
"devDependencies": {
30+
"@agoric/cosmic-proto": "^0.4.1-dev-c5284e4.0",
3131
"@types/better-sqlite3": "^7.6.9",
3232
"@types/node": "^18.19.14",
3333
"ava": "^5.3.1",

packages/synthetic-chain/src/cli/dockerfileGen.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import fs from 'node:fs';
2+
import { Platform } from './build.js';
23
import {
3-
type CoreEvalProposal,
4-
type ProposalInfo,
5-
type SoftwareUpgradeProposal,
64
encodeUpgradeInfo,
75
imageNameForProposal,
86
isPassed,
9-
ParameterChangeProposal,
7+
type CoreEvalPackage,
8+
type ParameterChangePackage,
9+
type ProposalInfo,
10+
type SoftwareUpgradePackage,
1011
} from './proposals.js';
11-
import { Platform } from './build.js';
1212

1313
/**
1414
* Templates for Dockerfile stages
@@ -58,7 +58,7 @@ FROM ghcr.io/agoric/agoric-3-proposals:${fromTag} as use-${fromTag}
5858
proposalName,
5959
upgradeInfo,
6060
releaseNotes,
61-
}: SoftwareUpgradeProposal,
61+
}: SoftwareUpgradePackage,
6262
lastProposal: ProposalInfo,
6363
) {
6464
const skipProposalValidation = !releaseNotes;
@@ -89,7 +89,7 @@ RUN ./run_prepare.sh ${path}
8989
planName,
9090
proposalName,
9191
sdkImageTag,
92-
}: SoftwareUpgradeProposal) {
92+
}: SoftwareUpgradePackage) {
9393
return `
9494
# EXECUTE ${proposalName}
9595
FROM ghcr.io/agoric/agoric-sdk:${sdkImageTag} as execute-${proposalName}
@@ -112,7 +112,7 @@ RUN ./run_execute.sh ${planName}
112112
* - Run the core-eval scripts from the proposal. They are only guaranteed to have started, not completed.
113113
*/
114114
EVAL(
115-
{ path, proposalName }: CoreEvalProposal | ParameterChangeProposal,
115+
{ path, proposalName }: CoreEvalPackage | ParameterChangePackage,
116116
lastProposal: ProposalInfo,
117117
) {
118118
return `

packages/synthetic-chain/src/cli/proposals.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type ProposalCommon = {
1010
proposalIdentifier: string;
1111
};
1212

13-
export type SoftwareUpgradeProposal = ProposalCommon & {
13+
export type SoftwareUpgradePackage = ProposalCommon & {
1414
sdkImageTag: string;
1515
planName: string;
1616
upgradeInfo?: unknown;
@@ -22,7 +22,7 @@ export type SoftwareUpgradeProposal = ProposalCommon & {
2222
type: 'Software Upgrade Proposal';
2323
};
2424

25-
export type CoreEvalProposal = ProposalCommon & {
25+
export type CoreEvalPackage = ProposalCommon & {
2626
type: '/agoric.swingset.CoreEvalProposal';
2727
} & (
2828
| { source: 'build'; buildScript: string }
@@ -32,14 +32,14 @@ export type CoreEvalProposal = ProposalCommon & {
3232
}
3333
);
3434

35-
export type ParameterChangeProposal = ProposalCommon & {
35+
export type ParameterChangePackage = ProposalCommon & {
3636
type: '/cosmos.params.v1beta1.ParameterChangeProposal';
3737
};
3838

3939
export type ProposalInfo =
40-
| SoftwareUpgradeProposal
41-
| CoreEvalProposal
42-
| ParameterChangeProposal;
40+
| SoftwareUpgradePackage
41+
| CoreEvalPackage
42+
| ParameterChangePackage;
4343

4444
function readInfo(proposalPath: string): ProposalInfo {
4545
assert(

packages/synthetic-chain/src/lib/cliHelper.js renamed to packages/synthetic-chain/src/lib/cliHelper.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { $, execaCommand } from 'execa';
22
import { BINARY } from './constants.js';
33

4-
export const executeCommand = async (command, params, options = {}) => {
4+
export const executeCommand = async (
5+
command: string,
6+
params: string[],
7+
options = {},
8+
) => {
59
const { stdout } = await execaCommand(
610
`${command} ${params.join(' ')}`,
711
options,
@@ -10,12 +14,12 @@ export const executeCommand = async (command, params, options = {}) => {
1014
};
1115

1216
export const agd = {
13-
query: async (...params) => {
17+
query: async (...params: string[]) => {
1418
const newParams = ['query', ...params, '-o json'];
1519
const data = await executeCommand(BINARY, newParams);
1620
return JSON.parse(data);
1721
},
18-
tx: async (...params) => {
22+
tx: async (...params: string[]) => {
1923
const newParams = [
2024
'tx',
2125
'-bblock',
@@ -27,7 +31,7 @@ export const agd = {
2731
const data = await executeCommand(BINARY, newParams, { shell: true });
2832
return JSON.parse(data);
2933
},
30-
keys: async (...params) => {
34+
keys: async (...params: string[]) => {
3135
let newParams = ['keys', ...params];
3236
let shouldParse = true;
3337

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

4953
return JSON.parse(data);
5054
},
51-
export: async (...params) => {
55+
export: async (...params: string[]) => {
5256
const newParams = ['export', ...params];
5357
const data = await executeCommand(BINARY, newParams);
5458
return JSON.parse(data);
5559
},
5660
};
5761

5862
export const agoric = {
59-
follow: async (...params) => {
63+
follow: async (...params: string[]) => {
6064
let newParams = ['follow', ...params];
6165
let parseJson = false;
6266

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

7377
return data;
7478
},
75-
wallet: async (...params) => {
79+
wallet: async (...params: string[]) => {
7680
const newParams = ['wallet', ...params];
7781
return executeCommand('agoric', newParams);
7882
},
79-
run: async (...params) => {
83+
run: async (...params: string[]) => {
8084
const newParams = ['run', ...params];
8185
return executeCommand('agoric', newParams);
8286
},
@@ -88,7 +92,7 @@ export const { stdout: agopsLocation } = await $({
8892
})`yarn bin agops`;
8993

9094
export const agops = {
91-
vaults: async (...params) => {
95+
vaults: async (...params: string[]) => {
9296
const newParams = ['vaults', ...params];
9397

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

102106
return result;
103107
},
104-
ec: async (...params) => {
108+
ec: async (...params: string[]) => {
105109
const newParams = ['ec', ...params];
106110
return executeCommand(agopsLocation, newParams);
107111
},
108-
oracle: async (...params) => {
112+
oracle: async (...params: string[]) => {
109113
const newParams = ['oracle', ...params];
110114
return executeCommand(agopsLocation, newParams);
111115
},
112-
perf: async (...params) => {
116+
perf: async (...params: string[]) => {
113117
const newParams = ['perf', ...params];
114118
return executeCommand(agopsLocation, newParams);
115119
},
116-
auctioneer: async (...params) => {
120+
auctioneer: async (...params: string[]) => {
117121
const newParams = ['auctioneer', ...params];
118122
return executeCommand(agopsLocation, newParams);
119123
},
@@ -125,23 +129,23 @@ export const { stdout: bundleSourceLocation } = await $({
125129
})`yarn bin bundle-source`;
126130

127131
/**
128-
* @param {string} filePath
129-
* @param {string} bundleName
130-
* @returns {Promise<string>} Returns the filepath of the bundle
132+
* @returns Returns the filepath of the bundle
131133
*/
132-
export const bundleSource = async (filePath, bundleName) => {
134+
export const bundleSource = async (filePath: string, bundleName: string) => {
133135
const output =
134136
await $`${bundleSourceLocation} --cache-json /tmp ${filePath} ${bundleName}`;
135137
console.log(output.stderr);
136138
return `/tmp/bundle-${bundleName}.json`;
137139
};
138140

139141
export const wellKnownIdentities = async (io = {}) => {
142+
// @ts-expect-error
140143
const { agoric: { follow = agoric.follow } = {} } = io;
141-
const zip = (xs, ys) => xs.map((x, i) => [x, ys[i]]);
142-
const fromSmallCapsEntries = txt => {
144+
const zip = (xs: unknown[], ys: unknown[]) => xs.map((x, i) => [x, ys[i]]);
145+
const fromSmallCapsEntries = (txt: string) => {
143146
const { body, slots } = JSON.parse(txt);
144147
const theEntries = zip(JSON.parse(body.slice(1)), slots).map(
148+
// @ts-expect-error
145149
([[name, ref], boardID]) => {
146150
const iface = ref.replace(/^\$\d+\./, '');
147151
return [name, { iface, boardID }];
@@ -166,11 +170,11 @@ export const wellKnownIdentities = async (io = {}) => {
166170
};
167171

168172
export const smallCapsContext = () => {
169-
const slots = []; // XXX global mutable state
173+
const slots = [] as string[]; // XXX global mutable state
170174
const smallCaps = {
171-
Nat: n => `+${n}`,
175+
Nat: (n: number | bigint) => `+${n}`,
172176
// XXX mutates obj
173-
ref: obj => {
177+
ref: (obj: any) => {
174178
if (obj.ix) return obj.ix;
175179
const ix = slots.length;
176180
slots.push(obj.boardID);
@@ -179,7 +183,7 @@ export const smallCapsContext = () => {
179183
},
180184
};
181185

182-
const toCapData = body => {
186+
const toCapData = (body: unknown) => {
183187
const capData = { body: `#${JSON.stringify(body)}`, slots };
184188
return JSON.stringify(capData);
185189
};

0 commit comments

Comments
 (0)