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

feat(orchestration): return unwrapped vows #9454

Merged
merged 12 commits into from
Jun 19, 2024
Merged
2 changes: 2 additions & 0 deletions packages/orchestration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"prepack": "tsc --build tsconfig.build.json",
"postpack": "git clean -f '*.d.ts*'",
"test": "ava",
"test:c8": "c8 $C8_OPTIONS ava --config=ava-nesm.config.js",
"test:xs": "exit 0",
"lint": "run-s --continue-on-error lint:*",
"lint:types": "tsc",
Expand Down Expand Up @@ -57,6 +58,7 @@
"@cosmjs/proto-signing": "^0.32.3",
"@endo/ses-ava": "^1.2.2",
"ava": "^5.3.1",
"c8": "^9.1.0",
"prettier": "^3.3.2"
},
"ava": {
Expand Down
4 changes: 3 additions & 1 deletion packages/orchestration/src/examples/stakeBld.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport/record
import { withdrawFromSeat } from '@agoric/zoe/src/contractSupport/zoeHelpers.js';
import { InvitationShape } from '@agoric/zoe/src/typeGuards.js';
import { makeDurableZone } from '@agoric/zone/durable.js';
import { V } from '@agoric/vow/vat.js';
import { prepareVowTools, V } from '@agoric/vow/vat.js';
import { E } from '@endo/far';
import { deeplyFulfilled } from '@endo/marshal';
import { M } from '@endo/patterns';
Expand Down Expand Up @@ -40,12 +40,14 @@ export const start = async (zcf, privateArgs, baggage) => {
baggage,
privateArgs.marshaller,
);
const vowTools = prepareVowTools(zone.subZone('vows'));

const makeLocalOrchestrationAccountKit = prepareLocalOrchestrationAccountKit(
zone,
makeRecorderKit,
zcf,
privateArgs.timerService,
vowTools,
makeChainHub(privateArgs.agoricNames),
);

Expand Down
5 changes: 4 additions & 1 deletion packages/orchestration/src/examples/stakeIca.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { makeTracer, StorageNodeShape } from '@agoric/internal';
import { TimerServiceShape } from '@agoric/time';
import { V as E } from '@agoric/vow/vat.js';
import { V as E, prepareVowTools } from '@agoric/vow/vat.js';
import {
prepareRecorderKitMakers,
provideAll,
Expand Down Expand Up @@ -76,9 +76,12 @@ export const start = async (zcf, privateArgs, baggage) => {

const { makeRecorderKit } = prepareRecorderKitMakers(baggage, marshaller);

const vowTools = prepareVowTools(zone.subZone('vows'));

const makeCosmosOrchestrationAccount = prepareCosmosOrchestrationAccount(
zone,
makeRecorderKit,
vowTools,
zcf,
);

Expand Down
48 changes: 35 additions & 13 deletions packages/orchestration/src/exos/chain-account-kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { NonNullish } from '@agoric/assert';
import { PurseShape } from '@agoric/ertp';
import { makeTracer } from '@agoric/internal';
import { V as E } from '@agoric/vow/vat.js';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import {
ChainAddressShape,
Expand All @@ -15,7 +15,7 @@ import { makeTxPacket, parseTxPacket } from '../utils/packet.js';
/**
* @import {Zone} from '@agoric/base-zone';
* @import {Connection, Port} from '@agoric/network';
* @import {Remote} from '@agoric/vow';
* @import {Remote, VowTools} from '@agoric/vow';
* @import {AnyJson} from '@agoric/cosmic-proto';
* @import {TxBody} from '@agoric/cosmic-proto/cosmos/tx/v1beta1/tx.js';
* @import {LocalIbcAddress, RemoteIbcAddress} from '@agoric/vats/tools/ibc-utils.js';
Expand Down Expand Up @@ -55,11 +55,22 @@ export const ChainAccountI = M.interface('ChainAccount', {
* }} State
*/

/** @param {Zone} zone */
export const prepareChainAccountKit = zone =>
/**
* @param {Zone} zone
* @param {VowTools} vowTools
*/
export const prepareChainAccountKit = (zone, { watch, when }) =>
zone.exoClassKit(
'ChainAccountKit',
{ account: ChainAccountI, connectionHandler: ConnectionHandlerI },
{
account: ChainAccountI,
connectionHandler: ConnectionHandlerI,
parseTxPacketWatcher: M.interface('ParseTxPacketWatcher', {
onFulfilled: M.call(M.string())
.optional(M.arrayOf(M.undefined())) // does not need watcherContext
.returns(M.string()),
}),
},
/**
* @param {string} chainId
* @param {Port} port
Expand All @@ -76,6 +87,12 @@ export const prepareChainAccountKit = zone =>
localAddress: undefined,
}),
{
parseTxPacketWatcher: {
/** @param {string} ack */
onFulfilled(ack) {
return parseTxPacket(ack);
},
},
account: {
/** @returns {ChainAddress} */
getAddress() {
Expand Down Expand Up @@ -120,23 +137,28 @@ export const prepareChainAccountKit = zone =>
* decoded using the corresponding `Msg*Response` object.
* @throws {Error} if packet fails to send or an error is returned
*/
executeEncodedTx(msgs, opts) {
async executeEncodedTx(msgs, opts) {
const { connection } = this.state;
// TODO #9281 do not throw synchronously when returning a promise; return a rejected Vow
/// see https://github.com/Agoric/agoric-sdk/pull/9454#discussion_r1626898694
if (!connection) throw Fail`connection not available`;
return E.when(
E(connection).send(makeTxPacket(msgs, opts)),
// if parseTxPacket cannot find a `result` key, it throws
ack => parseTxPacket(ack),
return when(
watch(
E(connection).send(makeTxPacket(msgs, opts)),
this.facets.parseTxPacketWatcher,
),
);
},
/** Close the remote account */
async close() {
// FIXME what should the behavior be here? and `onClose`?
/// TODO #9192 what should the behavior be here? and `onClose`?
// - retrieve assets?
// - revoke the port?
const { connection } = this.state;
// TODO #9281 do not throw synchronously when returning a promise; return a rejected Vow
/// see https://github.com/Agoric/agoric-sdk/pull/9454#discussion_r1626898694
if (!connection) throw Fail`connection not available`;
await E(connection).close();
return when(watch(E(connection).close()));
},
/**
* get Purse for a brand to .withdraw() a Payment from the account
Expand Down Expand Up @@ -169,7 +191,7 @@ export const prepareChainAccountKit = zone =>
},
async onClose(_connection, reason) {
trace(`ICA Channel closed. Reason: ${reason}`);
// FIXME handle connection closing
// FIXME handle connection closing https://github.com/Agoric/agoric-sdk/issues/9192
// XXX is there a scenario where a connection will unexpectedly close? _I think yes_
},
async onReceive(connection, bytes) {
Expand Down
Loading
Loading