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: improve Orch Core dapp support #9540

Closed
wants to merge 8 commits into from
13 changes: 10 additions & 3 deletions packages/async-flow/src/async-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { annotateError, Fail, makeError, q, X } from '@endo/errors';
import { E } from '@endo/eventual-send';
import { M } from '@endo/patterns';
import { makeScalarWeakMapStore } from '@agoric/store';
import { PromiseWatcherI } from '@agoric/base-zone';
import { prepareVowTools, toPassableCap, VowShape } from '@agoric/vow';
import {
prepareVowTools,
toPassableCap,
ReactionGuard,
VowShape,
} from '@agoric/vow';
import { makeReplayMembrane } from './replay-membrane.js';
import { prepareLogStore } from './log-store.js';
import { prepareBijection } from './bijection.js';
Expand Down Expand Up @@ -33,7 +37,10 @@ const AsyncFlowIKit = harden({
complete: M.call().returns(),
panic: M.call(M.error()).returns(M.not(M.any())), // only throws
}),
wakeWatcher: PromiseWatcherI,
wakeWatcher: M.interface('WakeWatcher', {
onFulfilled: ReactionGuard,
onRejected: ReactionGuard,
}),
});

const AdminAsyncFlowI = M.interface('AsyncFlowAdmin', {
Expand Down
2 changes: 1 addition & 1 deletion packages/base-zone/src/watch-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { Fail } = assert;
const { apply } = Reflect;

/**
* A PromiseWatcher method guard callable with or more arguments, returning void.
* A PromiseWatcher method guard callable with one or more arguments, returning void.
*/
export const PromiseWatcherHandler = M.call(M.raw()).rest(M.raw()).returns();

Expand Down
4 changes: 4 additions & 0 deletions packages/cosmic-proto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
"types": "./dist/codegen/ibc/applications/interchain_accounts/v1/packet.d.ts",
"default": "./dist/codegen/ibc/applications/interchain_accounts/v1/packet.js"
},
"./ibc/applications/transfer/v1/tx.js": {
"types": "./dist/codegen/ibc/applications/transfer/v1/tx.d.ts",
"default": "./dist/codegen/ibc/applications/transfer/v1/tx.js"
},
"./ibc/core/channel/v1/channel.js": {
"types": "./dist/codegen/ibc/core/channel/v1/channel.d.ts",
"default": "./dist/codegen/ibc/core/channel/v1/channel.js"
Expand Down
5 changes: 2 additions & 3 deletions packages/network/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@
"dependencies": {
"@agoric/assert": "^0.6.0",
"@agoric/internal": "^0.3.2",
"@agoric/store": "^0.9.2",
"@agoric/vat-data": "^0.5.2",
"@agoric/vow": "^0.1.0",
"@endo/base64": "^1.0.5",
"@endo/far": "^1.1.2",
"@endo/pass-style": "^1.4.0",
"@endo/patterns": "^1.4.0",
"@endo/promise-kit": "^1.1.2"
},
"devDependencies": {
"@agoric/store": "^0.9.2",
"@agoric/swingset-liveslots": "^0.10.2",
"@agoric/swingset-vat": "^0.32.2",
"@agoric/vow": "^0.1.0",
"@agoric/zone": "^0.2.2",
"@endo/bundle-source": "^3.2.3",
"ava": "^5.3.0",
Expand Down
10 changes: 3 additions & 7 deletions packages/network/src/shapes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check
import { M } from '@endo/patterns';
import { VowShape, OrVow$ } from '@agoric/vow';

const Shape1 = /** @type {const} */ ({
/**
Expand All @@ -9,12 +10,8 @@ const Shape1 = /** @type {const} */ ({
Data: M.string(),
Bytes: M.string(),
Endpoint: M.string(),
Vow: M.tagged(
'Vow',
harden({
vowV0: M.remotable('VowV0'),
}),
),
Vow$: OrVow$,
Vow: VowShape,
ConnectionHandler: M.remotable('ConnectionHandler'),
Connection: M.remotable('Connection'),
InboundAttempt: M.remotable('InboundAttempt'),
Expand All @@ -27,7 +24,6 @@ const Shape1 = /** @type {const} */ ({

const Shape2 = /** @type {const} */ ({
...Shape1,
Vow$: shape => M.or(shape, Shape1.Vow),
AttemptDescription: M.splitRecord(
{ handler: Shape1.ConnectionHandler },
{ remoteAddress: Shape1.Endpoint, localAddress: Shape1.Endpoint },
Expand Down
21 changes: 10 additions & 11 deletions packages/vats/src/localchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { AmountShape, BrandShape, PaymentShape } from '@agoric/ertp';
import { Shape as NetworkShape } from '@agoric/network';
import { OrVow$ } from '@agoric/vow';

const { Fail } = assert;
const { Vow$ } = NetworkShape;

/**
* @import {TypedJson, ResponseTo, JsonSafe} from '@agoric/cosmic-proto';
Expand Down Expand Up @@ -46,17 +45,17 @@ const { Vow$ } = NetworkShape;
*/

export const LocalChainAccountI = M.interface('LocalChainAccount', {
getAddress: M.callWhen().returns(Vow$(M.string())),
getBalance: M.callWhen(BrandShape).returns(Vow$(AmountShape)),
getAddress: M.callWhen().returns(OrVow$(M.string())),
getBalance: M.callWhen(BrandShape).returns(OrVow$(AmountShape)),
deposit: M.callWhen(PaymentShape)
.optional(M.pattern())
.returns(Vow$(AmountShape)),
withdraw: M.callWhen(AmountShape).returns(Vow$(PaymentShape)),
.returns(OrVow$(AmountShape)),
withdraw: M.callWhen(AmountShape).returns(OrVow$(PaymentShape)),
executeTx: M.callWhen(M.arrayOf(M.record())).returns(
Vow$(M.arrayOf(M.record())),
OrVow$(M.arrayOf(M.record())),
),
monitorTransfers: M.callWhen(M.remotable('TransferTap')).returns(
Vow$(M.remotable('TargetRegistration')),
OrVow$(M.remotable('TargetRegistration')),
),
});

Expand Down Expand Up @@ -195,10 +194,10 @@ export const prepareLocalChainAccountKit = (zone, { watch }) =>
/** @typedef {LocalChainAccountKit['account']} LocalChainAccount */

export const LocalChainI = M.interface('LocalChain', {
makeAccount: M.callWhen().returns(Vow$(M.remotable('LocalChainAccount'))),
query: M.callWhen(M.record()).returns(Vow$(M.record())),
makeAccount: M.callWhen().returns(OrVow$(M.remotable('LocalChainAccount'))),
query: M.callWhen(M.record()).returns(OrVow$(M.record())),
queryMany: M.callWhen(M.arrayOf(M.record())).returns(
Vow$(M.arrayOf(M.record())),
OrVow$(M.arrayOf(M.record())),
),
});

Expand Down
7 changes: 1 addition & 6 deletions packages/vats/src/transfer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { ReactionGuard } from '@agoric/vow';
import { VTRANSFER_IBC_EVENT } from '@agoric/internal';
import { coerceToByteSource, byteSourceToBase64 } from '@agoric/network';
import { TargetAppI, AppTransformerI } from './bridge-target.js';
Expand All @@ -11,12 +12,6 @@ import { TargetAppI, AppTransformerI } from './bridge-target.js';

const { Fail, bare } = assert;

/**
* The least possibly restrictive guard for a `watch` watcher's `onFulfilled` or
* `onRejected` reaction
*/
const ReactionGuard = M.call(M.any()).optional(M.any()).returns(M.any());

/**
* @param {import('@agoric/base-zone').Zone} zone
* @param {import('@agoric/vow').VowTools} vowTools
Expand Down
35 changes: 25 additions & 10 deletions packages/vats/tools/fake-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ export const makeFakeBankBridge = (zone, opts = { balances: {} }) => {
});
};

/** @param {any} obj */
const toBridgeIbcMethod = obj => {
const { type, method, ...params } = obj;
assert.equal(type, 'IBC_METHOD');
if (method === 'sendPacket') {
const { packet } = params;
return harden({ ...packet, sequence: '39' });
}
return undefined;
};

/**
* @param {import('@agoric/zone').Zone} zone
* @param {(obj) => void} onToBridge
Expand All @@ -132,13 +143,7 @@ export const makeFakeIbcBridge = (zone, onToBridge) => {
getBridgeId: () => 'dibc',
toBridge: async obj => {
onToBridge(obj);
const { method, type, ...params } = obj;
assert.equal(type, 'IBC_METHOD');
if (method === 'sendPacket') {
const { packet } = params;
return { ...packet, sequence: '39' };
}
return undefined;
return toBridgeIbcMethod(obj);
},
fromBridge: async obj => {
if (!hndlr) throw Error('no handler!');
Expand All @@ -159,10 +164,17 @@ export const LOCALCHAIN_DEFAULT_ADDRESS = 'agoric1fakeLCAAddress';

/**
* @param {import('@agoric/zone').Zone} zone
* @param {(obj) => void} [onToBridge]
* @param {(obj: any) => void} [onToBridge]
* @param {object} [opts]
* @param {(obj: any) => string} [opts.allocateAddress]
* @returns {ScopedBridgeManager<'vlocalchain'>}
*/
export const makeFakeLocalchainBridge = (zone, onToBridge = () => {}) => {
export const makeFakeLocalchainBridge = (
zone,
onToBridge = () => {},
opts = {},
) => {
const { allocateAddress = () => LOCALCHAIN_DEFAULT_ADDRESS } = opts;
/** @type {Remote<BridgeHandler>} */
let hndlr;
let lcaExecuteTxSequence = 0;
Expand All @@ -174,7 +186,7 @@ export const makeFakeLocalchainBridge = (zone, onToBridge = () => {}) => {
trace('toBridge', type, method, params);
switch (type) {
case 'VLOCALCHAIN_ALLOCATE_ADDRESS':
return LOCALCHAIN_DEFAULT_ADDRESS;
return allocateAddress(obj);
case 'VLOCALCHAIN_EXECUTE_TX': {
lcaExecuteTxSequence += 1;
return obj.messages.map(message => {
Expand Down Expand Up @@ -253,6 +265,9 @@ export const makeFakeTransferBridge = (zone, onToBridge = () => {}) => {
registered.delete(params.target);
return undefined;
}
case 'IBC_METHOD': {
return toBridgeIbcMethod(obj);
}
default:
Fail`unknown type ${type}`;
}
Expand Down
Loading
Loading