Skip to content

Commit

Permalink
v2.2.0 - name field to contract manifests + latest eventsAfter API su…
Browse files Browse the repository at this point in the history
…pport
  • Loading branch information
taoeffect committed Mar 28, 2024
1 parent bcd340b commit 1fdf8e8
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 31 deletions.
3 changes: 2 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# HISTORY

### v2.1.2
### v2.2.0

- Add a `name` field to the manifest with the contract's name
- Updated `eventsAfter` API to support latest changes related to use of height and streaming

### v2.1.1

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ cp -r path/to/contracts/* test/assets/ && ls ./test/assets/*-slim.js | sed -En '
Current release hashes will always be listed here.

```
7560ff9459761030fa57aab206c6730395ab0f32acffd94fc52858fb9df89d98 dist/chel-v2.1.1-aarch64-apple-darwin.tar.gz
fbd8a6d19a63e4506fa22c3c4a7eb66379a571bef06c47ed0ab99cf60b86a524 dist/chel-v2.1.1-x86_64-apple-darwin.tar.gz
0f0014508aa61b6593e1626d63adbe713e8d7a8be51bec798a7f515ed2fc2966 dist/chel-v2.1.1-x86_64-pc-windows-msvc.tar.gz
20324f5a2d3bac5680ede772a8332f1563e87cd93ba18f6cc07d773e7e51fa16 dist/chel-v2.1.1-x86_64-unknown-linux-gnu.tar.gz
fb9b81db169cbba480c8a33ce807d5fdbb077813607cc9284f98b73c2ded9d76 dist/chel-v2.2.0-aarch64-apple-darwin.tar.gz
8e6b12e4ec9df02a3e18138ac14f7228dd1481ae172c33f43805eed0f2eded20 dist/chel-v2.2.0-x86_64-apple-darwin.tar.gz
e6331a9edf20de1df7aa5a78426f8f7a7068a5fc294140dab983947f13af6b04 dist/chel-v2.2.0-x86_64-pc-windows-msvc.tar.gz
70f83f77d39bb77eb523d70bd30a447f5c5a619b2a0150f0a95de12845d6f739 dist/chel-v2.2.0-x86_64-unknown-linux-gnu.tar.gz
```

## History
Expand Down
1 change: 0 additions & 1 deletion bin/chel

This file was deleted.

46 changes: 24 additions & 22 deletions build/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,17 @@ async function eventsAfter(args) {
const limit = Number(parsedArgs.limit ?? defaultLimit);
if (!isArrayLength(limit))
exit("argument --limit must be a valid array length");
const [urlOrLocalPath, contractID, hash2] = parsedArgs._.map(String);
const [urlOrLocalPath, contractID] = parsedArgs._.map(String);
const height = Number(parsedArgs._[2]);
const src = urlOrLocalPath;
try {
let messages;
if (isURL(src)) {
messages = await getRemoteMessagesSince(src, contractID, hash2, limit);
messages = await getRemoteMessagesSince(src, contractID, height, limit);
} else {
messages = await getMessagesSince(src, contractID, hash2, limit);
messages = await getMessagesSince(src, contractID, height, limit);
}
console.log(JSON.stringify(messages.map((s) => JSON.parse(s)), null, 2));
console.log(JSON.stringify(messages, null, 2));
} catch (error) {
exit(error.message);
}
Expand All @@ -389,44 +390,43 @@ async function getMessage(hash2) {
const value = await readString(hash2);
if (!value)
throw new Error(`no entry for ${hash2}!`);
return JSON.parse(value).message;
return JSON.parse(value);
}
async function getMessagesSince(src, contractID, since, limit) {
async function getMessagesSince(src, contractID, sinceHeight, limit) {
backend = await getBackend(src);
const contractHEAD = await readString(`${headPrefix}${contractID}`);
if (contractHEAD === void 0) {
throw new Deno.errors.NotFound(`contract ${contractID} doesn't exist!`);
}
const entries = [];
let currentHEAD = contractHEAD;
let currentHEAD = JSON.parse(contractHEAD).HEAD;
let currentHeight;
while (true) {
const entry = await getMessage(currentHEAD);
if (!entry) {
throw new Deno.errors.NotFound(`entry ${currentHEAD} no longer exists.`);
}
const head = JSON.parse(entry.head);
currentHeight = head.height;
entries.push(entry);
if (currentHEAD === since) {
if (currentHeight === sinceHeight) {
break;
} else {
currentHEAD = JSON.parse(entry).previousHEAD;
if (currentHEAD === null) {
throw new Deno.errors.NotFound(`entry ${since} was not found in contract ${contractID}.`);
}
}
currentHEAD = head.previousHEAD;
}
return entries.reverse().slice(0, limit);
}
async function getRemoteMessagesSince(src, contractID, since, limit) {
const response = await fetch(`${src}/eventsAfter/${contractID}/${since}`);
async function getRemoteMessagesSince(src, contractID, sinceHeight, limit) {
const response = await fetch(`${src}/eventsAfter/${contractID}/${sinceHeight}`);
if (!response.ok) {
const bodyText = await response.text().catch((_) => "") || ``;
throw new Error(`failed network request to ${src}: ${response.status} - ${response.statusText} - '${bodyText}'`);
}
const b64messages = (await response.json()).reverse();
const b64messages = await response.json();
if (b64messages.length > limit) {
b64messages.length = limit;
}
return b64messages.map((b64str) => JSON.parse(new TextDecoder().decode(base64.decode(b64str))).message);
return b64messages.map((b64str) => JSON.parse(new TextDecoder().decode(base64.decode(b64str))));
}
async function readString(key) {
const rv = await backend.readData(key);
Expand Down Expand Up @@ -480,11 +480,11 @@ function help(args) {
chel version
chel keygen [--out <key.json>] [--pubout <key.pub.json>]
chel verifySignature [-k <pubkey.json>] <manifest.json>
chel manifest [-k|--key <pubkey1.json> [-k|--key <pubkey2.json> ...]] [--out=<manifest.json>] [-s|--slim <contract-slim.js>] [-v|--version <version>] <key.json> <contract-bundle.js>
chel manifest [-k|--key <pubkey1.json> [-k|--key <pubkey2.json> ...]] [--out=<manifest.json>] [-s|--slim <contract-slim.js>] [-v|--version <version>] [-n|--name <name>] <key.json> <contract-bundle.js>
chel deploy <url-or-dir-or-sqlitedb> <contract-manifest.json> [<manifest2.json> [<manifest3.json> ...]]
chel upload <url-or-dir-or-sqlitedb> <file1> [<file2> [<file3> ...]]
chel latestState <url> <contractID>
chel eventsAfter [--limit N] <url-or-dir-or-sqlitedb> <contractID> <hash>
chel eventsAfter [--limit N] <url-or-dir-or-sqlitedb> <contractID> <height>
chel eventsBefore [--limit N] <url> <contractID> <hash>
chel get <url-or-dir-or-sqlitedb> <hash>
chel hash <file>
Expand Down Expand Up @@ -766,10 +766,11 @@ async function manifest(args) {
const parsedArgs = flags.parse(args, { collect: ["key"], alias: { "key": "k" } });
const [keyFile, contractFile] = parsedArgs._;
const parsedFilepath = path.parse(contractFile);
const { name: contractName, base: contractBasename, dir: contractDir } = parsedFilepath;
const { name: contractFileName, base: contractBasename, dir: contractDir } = parsedFilepath;
const name = parsedArgs.name || parsedArgs.n || contractFileName;
const version2 = parsedArgs.version || parsedArgs.v || "x";
const slim = parsedArgs.slim || parsedArgs.s;
const outFilepath = path.join(contractDir, `${contractName}.${version2}.manifest.json`);
const outFilepath = path.join(contractDir, `${contractFileName}.${version2}.manifest.json`);
if (!keyFile)
exit("Missing signing key file");
const signingKeyDescriptor = await readJsonFile(keyFile);
Expand All @@ -783,6 +784,7 @@ async function manifest(args) {
return serializeKey(key, false);
}) || []))));
const body = {
name,
version: version2,
contract: {
hash: await hash([contractFile], true),
Expand Down Expand Up @@ -934,7 +936,7 @@ var verifySignature2 = async (args, internal = false) => {

// src/version.ts
function version() {
console.log("2.1.1");
console.log("2.2.0");
}

// src/main.ts
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@chelonia/cli",
"version": "2.1.2",
"version": "2.2.0",
"description": "Chelonia Command-line Interface",
"main": "src/main.ts",
"scripts": {
Expand Down

0 comments on commit 1fdf8e8

Please sign in to comment.