Skip to content

Commit

Permalink
chore(types): use cosmic-proto
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed May 28, 2024
1 parent f537e02 commit c123dc9
Show file tree
Hide file tree
Showing 4 changed files with 726 additions and 6 deletions.
5 changes: 2 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 @@ -29,6 +27,7 @@
"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
37 changes: 37 additions & 0 deletions packages/synthetic-chain/src/lib/vstorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { assert, Fail } from './assert.js';

const { freeze: harden } = Object; // XXX

// from '@agoric/internal/src/lib-chainStorage.js';
const isStreamCell = cell =>
cell &&
typeof cell === 'object' &&
Array.isArray(cell.values) &&
typeof cell.blockHeight === 'string' &&
/^0$|^[1-9][0-9]*$/.test(cell.blockHeight);
harden(isStreamCell);

/**
* Extract one value from a the vstorage stream cell in a QueryDataResponse
*
* @param {import('@agoric/cosmic-proto/dist/codegen/agoric/vstorage/query.js').QueryDataResponse} data
* @param {number} [index] index of the desired value in a deserialized stream cell
*/
export const extractStreamCellValue = (data, index = -1) => {
const { value: serialized } = data;

serialized.length > 0 || Fail`no StreamCell values: ${data}`;

const streamCell = JSON.parse(serialized);
if (!isStreamCell(streamCell)) {
throw Fail`not a StreamCell: ${streamCell}`;
}

const { values } = streamCell;
values.length > 0 || Fail`no StreamCell values: ${streamCell}`;

const value = values.at(index);
assert.typeof(value, 'string');
return value;
};
harden(extractStreamCellValue);
4 changes: 2 additions & 2 deletions packages/synthetic-chain/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"checkJs": false, // opt in
"strict": true,
"maxNodeModuleJsDepth": 2,
"module": "NodeNext",
"moduleResolution": "nodenext",
"module": "ES2022",
"moduleResolution": "Node",
"noEmit": true,
"target": "ESNext"
},
Expand Down
Loading

0 comments on commit c123dc9

Please sign in to comment.