@agoric/vats 0.15.2-dev-c19f1b5.0 → 0.15.2-dev-27cc9b8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +17 -18
- package/src/bridge-target.d.ts +193 -0
- package/src/bridge-target.d.ts.map +1 -0
- package/src/bridge-target.js +316 -0
- package/src/core/types-ambient.d.ts +3 -2
- package/src/ibc.d.ts +3 -33
- package/src/ibc.d.ts.map +1 -1
- package/src/ibc.js +3 -3
- package/src/localchain.d.ts +7 -0
- package/src/localchain.d.ts.map +1 -1
- package/src/localchain.js +11 -2
- package/src/proposals/localchain-proposal.d.ts +4 -1
- package/src/proposals/localchain-proposal.d.ts.map +1 -1
- package/src/proposals/localchain-proposal.js +5 -0
- package/src/proposals/localchain-test.d.ts.map +1 -1
- package/src/proposals/localchain-test.js +7 -4
- package/src/proposals/restart-vats-proposal.d.ts.map +1 -1
- package/src/proposals/restart-vats-proposal.js +6 -2
- package/src/proposals/transfer-proposal.d.ts +41 -0
- package/src/proposals/transfer-proposal.d.ts.map +1 -0
- package/src/proposals/transfer-proposal.js +120 -0
- package/src/proposals/vtransfer-echoer.d.ts +24 -0
- package/src/proposals/vtransfer-echoer.d.ts.map +1 -0
- package/src/proposals/vtransfer-echoer.js +42 -0
- package/src/transfer.d.ts +124 -0
- package/src/transfer.d.ts.map +1 -0
- package/src/transfer.js +271 -0
- package/src/types.d.ts +4 -3
- package/src/vat-ibc.d.ts +0 -28
- package/src/vat-ibc.d.ts.map +1 -1
- package/src/vat-localchain.d.ts +2 -0
- package/src/vat-localchain.d.ts.map +1 -1
- package/src/vat-transfer.d.ts +81 -0
- package/src/vat-transfer.d.ts.map +1 -0
- package/src/vat-transfer.js +63 -0
- package/tools/fake-bridge.d.ts +1 -0
- package/tools/fake-bridge.d.ts.map +1 -1
- package/tools/fake-bridge.js +45 -0
package/src/transfer.js
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { E } from '@endo/far';
|
|
3
|
+
import { M } from '@endo/patterns';
|
|
4
|
+
import { VTRANSFER_IBC_EVENT } from '@agoric/internal';
|
|
5
|
+
import { coerceToByteSource, byteSourceToBase64 } from '@agoric/network';
|
|
6
|
+
import {
|
|
7
|
+
prepareBridgeTargetModule,
|
|
8
|
+
TargetAppI,
|
|
9
|
+
AppTransformerI,
|
|
10
|
+
} from './bridge-target.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @import {TargetApp, TargetHost} from './bridge-target.js'
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const { Fail, bare } = assert;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The least possibly restrictive guard for a `watch` watcher's `onFulfilled` or
|
|
20
|
+
* `onRejected` reaction
|
|
21
|
+
*/
|
|
22
|
+
const ReactionGuard = M.call(M.any()).optional(M.any()).returns(M.any());
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {import('@agoric/base-zone').Zone} zone
|
|
26
|
+
* @param {import('@agoric/vow').VowTools} vowTools
|
|
27
|
+
*/
|
|
28
|
+
const prepareTransferInterceptor = (zone, vowTools) => {
|
|
29
|
+
const { watch } = vowTools;
|
|
30
|
+
const makeTransferInterceptorKit = zone.exoClassKit(
|
|
31
|
+
'TransferInterceptorKit',
|
|
32
|
+
{
|
|
33
|
+
public: TargetAppI,
|
|
34
|
+
encodeAckWatcher: M.interface('EncodeAckWatcher', {
|
|
35
|
+
onFulfilled: ReactionGuard,
|
|
36
|
+
}),
|
|
37
|
+
sendErrorWatcher: M.interface('SendErrorWatcher', {
|
|
38
|
+
onRejected: ReactionGuard,
|
|
39
|
+
}),
|
|
40
|
+
logErrorWatcher: M.interface('LogErrorWatcher', {
|
|
41
|
+
onRejected: ReactionGuard,
|
|
42
|
+
}),
|
|
43
|
+
},
|
|
44
|
+
/**
|
|
45
|
+
* @param {ERef<TargetApp>} tap
|
|
46
|
+
* @param {ERef<TargetHost>} targetHost
|
|
47
|
+
* @param {boolean} [isActiveTap] Whether the tap is active (can modify
|
|
48
|
+
* acknowledgements), or passive (can't cause delays in the middleware).
|
|
49
|
+
*/
|
|
50
|
+
(tap, targetHost, isActiveTap = false) => ({
|
|
51
|
+
isActiveTap,
|
|
52
|
+
tap,
|
|
53
|
+
targetHost,
|
|
54
|
+
}),
|
|
55
|
+
{
|
|
56
|
+
public: {
|
|
57
|
+
async receiveUpcall(obj) {
|
|
58
|
+
const { isActiveTap, tap, targetHost } = this.state;
|
|
59
|
+
|
|
60
|
+
obj.type === VTRANSFER_IBC_EVENT ||
|
|
61
|
+
Fail`Invalid upcall argument type ${obj.type}; expected ${bare(VTRANSFER_IBC_EVENT)}`;
|
|
62
|
+
|
|
63
|
+
// First, call our target contract listener.
|
|
64
|
+
// A VTransfer active interceptor can return a write acknowledgement
|
|
65
|
+
/** @type {import('@agoric/vow').Vow<unknown>} */
|
|
66
|
+
let retP = watch(E(tap).receiveUpcall(obj));
|
|
67
|
+
|
|
68
|
+
// See if the upcall result needs special handling.
|
|
69
|
+
if (obj.event === 'writeAcknowledgement') {
|
|
70
|
+
const ackMethodData = {
|
|
71
|
+
type: 'IBC_METHOD',
|
|
72
|
+
method: 'receiveExecuted',
|
|
73
|
+
packet: obj.packet,
|
|
74
|
+
};
|
|
75
|
+
if (isActiveTap) {
|
|
76
|
+
retP = watch(retP, this.facets.encodeAckWatcher, {
|
|
77
|
+
ackMethodData,
|
|
78
|
+
});
|
|
79
|
+
} else {
|
|
80
|
+
// This is a passive tap, so forward the ack without intervention.
|
|
81
|
+
ackMethodData.ack = obj.acknowledgement;
|
|
82
|
+
retP = watch(E(targetHost).sendDowncall(ackMethodData));
|
|
83
|
+
}
|
|
84
|
+
retP = watch(retP, this.facets.sendErrorWatcher, { ackMethodData });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Log errors in the upcall handling.
|
|
88
|
+
retP = watch(retP, this.facets.logErrorWatcher, { obj });
|
|
89
|
+
|
|
90
|
+
if (isActiveTap) {
|
|
91
|
+
// If the tap is active, return the promiseVow to the caller. This
|
|
92
|
+
// will delay the middleware until fulfilment of the retP chain.
|
|
93
|
+
return retP;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Otherwise, passively return nothing.
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* `watch` callback for encoding the raw `ack` return value from an active
|
|
101
|
+
* `writeAcknowledgement` tap as base64, then sending down to the
|
|
102
|
+
* targetHost.
|
|
103
|
+
*/
|
|
104
|
+
encodeAckWatcher: {
|
|
105
|
+
onFulfilled(rawAck, { ackMethodData }) {
|
|
106
|
+
// Encode the tap's ack and write it out.
|
|
107
|
+
const ack = byteSourceToBase64(coerceToByteSource(rawAck));
|
|
108
|
+
ackMethodData = { ...ackMethodData, ack };
|
|
109
|
+
return E(this.state.targetHost).sendDowncall(ackMethodData);
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
/**
|
|
113
|
+
* `watch` callback for handling errors in the sending of an ack and
|
|
114
|
+
* reifying it as an error acknowledgement.
|
|
115
|
+
*/
|
|
116
|
+
sendErrorWatcher: {
|
|
117
|
+
onRejected(error, { ackMethodData }) {
|
|
118
|
+
console.error(`Error sending ack:`, error);
|
|
119
|
+
const rawAck = JSON.stringify({ error: error.message });
|
|
120
|
+
ackMethodData = { ...ackMethodData, ack: byteSourceToBase64(rawAck) };
|
|
121
|
+
return E(this.state.targetHost).sendDowncall(ackMethodData);
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
/** `watch` callback for logging errors in the upcall handling. */
|
|
125
|
+
logErrorWatcher: {
|
|
126
|
+
onRejected(error, { obj }) {
|
|
127
|
+
console.error(`Error in handling of`, obj, error);
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A TransferInterceptor wraps a TargetApp that is specialized for handling
|
|
135
|
+
* asynchronous callbacks from the IBC transfer protocol as implemented by
|
|
136
|
+
* `x/vtransfer`. By using this interceptor, the TargetApp is prevented from
|
|
137
|
+
* sending messages which may violate the transfer protocol directly to the
|
|
138
|
+
* `targetHost`.
|
|
139
|
+
*
|
|
140
|
+
* @param {Parameters<typeof makeTransferInterceptorKit>} args
|
|
141
|
+
*/
|
|
142
|
+
const makeTransferInterceptor = (...args) =>
|
|
143
|
+
makeTransferInterceptorKit(...args).public;
|
|
144
|
+
return makeTransferInterceptor;
|
|
145
|
+
};
|
|
146
|
+
harden(prepareTransferInterceptor);
|
|
147
|
+
|
|
148
|
+
const TransferMiddlewareKitFinisherI = M.interface(
|
|
149
|
+
'TransferMiddlewareKitFinisher',
|
|
150
|
+
{
|
|
151
|
+
useRegistry: M.call(M.remotable('TargetRegistry')).returns(),
|
|
152
|
+
},
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
const TransferMiddlewareI = M.interface('TransferMiddleware', {
|
|
156
|
+
registerTap: M.callWhen(
|
|
157
|
+
M.string(),
|
|
158
|
+
M.remotable('TransferInterceptor'),
|
|
159
|
+
).returns(M.remotable('TargetRegistration')),
|
|
160
|
+
registerActiveTap: M.callWhen(
|
|
161
|
+
M.string(),
|
|
162
|
+
M.remotable('TransferInterceptor'),
|
|
163
|
+
).returns(M.remotable('TargetRegistration')),
|
|
164
|
+
unregisterTap: M.callWhen(M.string()).returns(),
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @callback RegisterTap
|
|
169
|
+
* @param {string} target String identifying the bridge target.
|
|
170
|
+
* @param {ERef<import('./bridge-target.js').TargetApp>} tap The "application
|
|
171
|
+
* tap" to register for the target.
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* A TransferMiddlewareKit has a `transferMiddleware` facet with methods for
|
|
176
|
+
* registering and unregistering active and passive "taps" in a BridgeTargetKit
|
|
177
|
+
* registry that must use the `interceptorFactory` facet as its appTransfomer to
|
|
178
|
+
* enforce IBC transfer protocol conformance. Before registering any taps, the
|
|
179
|
+
* backing BridgeTargetKit must be set with the `finisher` facet (i.e., the
|
|
180
|
+
* expected setup pattern is to pass in `interceptorFactory` as the
|
|
181
|
+
* appTransformer argument when making a BridgeTargetKit and then to invoke
|
|
182
|
+
* `finisher.useRegistry` with the `targetRegistry` of that BridgeTargetKit
|
|
183
|
+
* before making further use of the TransferMiddlewareKit or connecting the
|
|
184
|
+
* BridgeTargetKit to a bridge).
|
|
185
|
+
*
|
|
186
|
+
* @param {import('@agoric/base-zone').Zone} zone
|
|
187
|
+
* @param {ReturnType<typeof prepareTransferInterceptor>} makeTransferInterceptor
|
|
188
|
+
*/
|
|
189
|
+
const prepareTransferMiddlewareKit = (zone, makeTransferInterceptor) =>
|
|
190
|
+
zone.exoClassKit(
|
|
191
|
+
'TransferMiddlewareKit',
|
|
192
|
+
{
|
|
193
|
+
finisher: TransferMiddlewareKitFinisherI,
|
|
194
|
+
interceptorFactory: AppTransformerI,
|
|
195
|
+
transferMiddleware: TransferMiddlewareI,
|
|
196
|
+
},
|
|
197
|
+
() => ({
|
|
198
|
+
/** @type {import('./bridge-target').TargetRegistry | undefined} */
|
|
199
|
+
targetRegistry: undefined,
|
|
200
|
+
}),
|
|
201
|
+
{
|
|
202
|
+
finisher: {
|
|
203
|
+
/**
|
|
204
|
+
* @param {import('./bridge-target').TargetRegistry} registry
|
|
205
|
+
*/
|
|
206
|
+
useRegistry(registry) {
|
|
207
|
+
this.state.targetRegistry = registry;
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
interceptorFactory: {
|
|
211
|
+
wrapApp: makeTransferInterceptor,
|
|
212
|
+
},
|
|
213
|
+
transferMiddleware: {
|
|
214
|
+
/**
|
|
215
|
+
* Register a tap to intercept the vtransfer target account address
|
|
216
|
+
* messages, without granting that tap the ability to delay or interfere
|
|
217
|
+
* with the underlying IBC transfer protocol.
|
|
218
|
+
*
|
|
219
|
+
* @type {RegisterTap}
|
|
220
|
+
*/
|
|
221
|
+
async registerTap(target, tap) {
|
|
222
|
+
const { targetRegistry } = this.state;
|
|
223
|
+
if (!targetRegistry) throw Fail`Registry not initialized`;
|
|
224
|
+
return E(targetRegistry).register(target, tap, []);
|
|
225
|
+
},
|
|
226
|
+
/**
|
|
227
|
+
* Similar to `registerTap`, but allows the tap to inject async
|
|
228
|
+
* acknowledgements in the IBC transfer protocol.
|
|
229
|
+
*
|
|
230
|
+
* @type {RegisterTap}
|
|
231
|
+
*/
|
|
232
|
+
async registerActiveTap(target, tap) {
|
|
233
|
+
const { targetRegistry } = this.state;
|
|
234
|
+
if (!targetRegistry) throw Fail`Registry not initialized`;
|
|
235
|
+
return E(targetRegistry).register(target, tap, [true]);
|
|
236
|
+
},
|
|
237
|
+
/**
|
|
238
|
+
* Unregister the target.
|
|
239
|
+
*
|
|
240
|
+
* @param {string} target String identifying the bridge target to stop
|
|
241
|
+
* tapping.
|
|
242
|
+
*/
|
|
243
|
+
async unregisterTap(target) {
|
|
244
|
+
const { targetRegistry } = this.state;
|
|
245
|
+
if (!targetRegistry) throw Fail`Registry not initialized`;
|
|
246
|
+
await E(targetRegistry).unregister(target);
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
);
|
|
251
|
+
/** @typedef {ReturnType<ReturnType<typeof prepareTransferMiddlewareKit>>} TransferMiddlewareKit */
|
|
252
|
+
/** @typedef {TransferMiddlewareKit['transferMiddleware']} TransferMiddleware */
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* @param {import('@agoric/base-zone').Zone} zone
|
|
256
|
+
* @param {import('@agoric/vow').VowTools} vowTools
|
|
257
|
+
*/
|
|
258
|
+
export const prepareTransferTools = (zone, vowTools) => {
|
|
259
|
+
const makeTransferInterceptor = prepareTransferInterceptor(zone, vowTools);
|
|
260
|
+
const { makeBridgeTargetKit } = prepareBridgeTargetModule(
|
|
261
|
+
zone.subZone('bridge-target'),
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
const makeTransferMiddlewareKit = prepareTransferMiddlewareKit(
|
|
265
|
+
zone,
|
|
266
|
+
makeTransferInterceptor,
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
return harden({ makeTransferMiddlewareKit, makeBridgeTargetKit });
|
|
270
|
+
};
|
|
271
|
+
harden(prepareTransferTools);
|
package/src/types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { BridgeIdValue, Remote } from '@agoric/internal';
|
|
2
2
|
import type { Bytes } from '@agoric/network';
|
|
3
|
-
import type { PromiseVow } from '@agoric/vow';
|
|
4
3
|
import type { Guarded } from '@endo/exo';
|
|
5
4
|
|
|
6
5
|
export type Board = ReturnType<
|
|
@@ -92,7 +91,7 @@ export type NamesByAddressAdmin = NameAdmin & {
|
|
|
92
91
|
/** An object that can receive messages from the bridge device */
|
|
93
92
|
export type BridgeHandler = {
|
|
94
93
|
/** Handle an inbound message */
|
|
95
|
-
fromBridge: (obj: any) =>
|
|
94
|
+
fromBridge: (obj: any) => Promise<unknown>;
|
|
96
95
|
};
|
|
97
96
|
|
|
98
97
|
/** An object which handles messages for a specific bridge */
|
|
@@ -103,8 +102,10 @@ export type ScopedBridgeManager<BridgeId extends BridgeIdValue> = Guarded<{
|
|
|
103
102
|
* system to hang the bridgeId
|
|
104
103
|
*/
|
|
105
104
|
getBridgeId?: () => BridgeId;
|
|
105
|
+
/** Downcall from the VM into Golang */
|
|
106
106
|
toBridge: (obj: any) => Promise<any>;
|
|
107
|
-
|
|
107
|
+
/** Upcall from Golang into the VM */
|
|
108
|
+
fromBridge: (obj: any) => Promise<unknown>;
|
|
108
109
|
initHandler: (handler: Remote<BridgeHandler>) => void;
|
|
109
110
|
setHandler: (handler: Remote<BridgeHandler>) => void;
|
|
110
111
|
}>;
|
package/src/vat-ibc.d.ts
CHANGED
|
@@ -2,20 +2,6 @@ export function buildRootObject(_vatPowers: any, _args: any, baggage: any): {
|
|
|
2
2
|
createHandlers: (callbacks: any) => {
|
|
3
3
|
protocolHandler: import("@agoric/network").ProtocolHandler;
|
|
4
4
|
bridgeHandler: import("./types.js").BridgeHandler;
|
|
5
|
-
} | {
|
|
6
|
-
protocolHandler: import("@endo/exo").Guarded<{
|
|
7
|
-
onCreate(protocol: import("@agoric/internal").Remote<import("@agoric/network").ProtocolImpl>, p: import("@agoric/internal").Remote<import("@agoric/network").ProtocolHandler>): import("@agoric/vow").PromiseVow<void>;
|
|
8
|
-
onInstantiate(port: import("@agoric/internal").Remote<import("@agoric/network").Port>, localAddr: Endpoint, remote: Endpoint, p: import("@agoric/internal").Remote<import("@agoric/network").ProtocolHandler>): import("@agoric/vow").PromiseVow<string>;
|
|
9
|
-
generatePortID(localAddr: Endpoint, p: import("@agoric/internal").Remote<import("@agoric/network").ProtocolHandler>): import("@agoric/vow").PromiseVow<string>;
|
|
10
|
-
onBind(port: import("@agoric/internal").Remote<import("@agoric/network").Port>, localAddr: Endpoint, p: import("@agoric/internal").Remote<import("@agoric/network").ProtocolHandler>): import("@agoric/vow").PromiseVow<void>;
|
|
11
|
-
onConnect(port: import("@agoric/internal").Remote<import("@agoric/network").Port>, localAddr: Endpoint, remote: Endpoint, c: import("@agoric/internal").Remote<import("@agoric/network").ConnectionHandler>, p: import("@agoric/internal").Remote<import("@agoric/network").ProtocolHandler>): import("@agoric/vow").PromiseVow<import("@agoric/network").AttemptDescription>;
|
|
12
|
-
onListen(port: import("@agoric/internal").Remote<import("@agoric/network").Port>, localAddr: Endpoint, listenHandler: import("@agoric/internal").Remote<import("@agoric/network").ListenHandler>, p: import("@agoric/internal").Remote<import("@agoric/network").ProtocolHandler>): import("@agoric/vow").PromiseVow<void>;
|
|
13
|
-
onListenRemove(port: import("@agoric/internal").Remote<import("@agoric/network").Port>, localAddr: Endpoint, listenHandler: import("@agoric/internal").Remote<import("@agoric/network").ListenHandler>, p: import("@agoric/internal").Remote<import("@agoric/network").ProtocolHandler>): import("@agoric/vow").PromiseVow<void>;
|
|
14
|
-
onRevoke(port: import("@agoric/internal").Remote<import("@agoric/network").Port>, localAddr: Endpoint, p: import("@agoric/internal").Remote<import("@agoric/network").ProtocolHandler>): import("@agoric/vow").PromiseVow<void>;
|
|
15
|
-
}>;
|
|
16
|
-
bridgeHandler: import("@endo/exo").Guarded<{
|
|
17
|
-
fromBridge(obj: import("./types.js").IBCEvent<import("./types.js").IBCBridgeEvent>): Promise<import("@agoric/vow").Vow<any> | undefined>;
|
|
18
|
-
}>;
|
|
19
5
|
};
|
|
20
6
|
makeCallbacks: (dibcBridgeManager: import("./types.js").ScopedBridgeManager<"dibc">) => import("@endo/exo").Guarded<{
|
|
21
7
|
downcall(method: string, obj: any): Promise<any>;
|
|
@@ -24,20 +10,6 @@ export function buildRootObject(_vatPowers: any, _args: any, baggage: any): {
|
|
|
24
10
|
createHandlers: (callbacks: any) => {
|
|
25
11
|
protocolHandler: import("@agoric/network").ProtocolHandler;
|
|
26
12
|
bridgeHandler: import("./types.js").BridgeHandler;
|
|
27
|
-
} | {
|
|
28
|
-
protocolHandler: import("@endo/exo").Guarded<{
|
|
29
|
-
onCreate(protocol: import("@agoric/internal").Remote<import("@agoric/network").ProtocolImpl>, p: import("@agoric/internal").Remote<import("@agoric/network").ProtocolHandler>): import("@agoric/vow").PromiseVow<void>;
|
|
30
|
-
onInstantiate(port: import("@agoric/internal").Remote<import("@agoric/network").Port>, localAddr: Endpoint, remote: Endpoint, p: import("@agoric/internal").Remote<import("@agoric/network").ProtocolHandler>): import("@agoric/vow").PromiseVow<string>;
|
|
31
|
-
generatePortID(localAddr: Endpoint, p: import("@agoric/internal").Remote<import("@agoric/network").ProtocolHandler>): import("@agoric/vow").PromiseVow<string>;
|
|
32
|
-
onBind(port: import("@agoric/internal").Remote<import("@agoric/network").Port>, localAddr: Endpoint, p: import("@agoric/internal").Remote<import("@agoric/network").ProtocolHandler>): import("@agoric/vow").PromiseVow<void>;
|
|
33
|
-
onConnect(port: import("@agoric/internal").Remote<import("@agoric/network").Port>, localAddr: Endpoint, remote: Endpoint, c: import("@agoric/internal").Remote<import("@agoric/network").ConnectionHandler>, p: import("@agoric/internal").Remote<import("@agoric/network").ProtocolHandler>): import("@agoric/vow").PromiseVow<import("@agoric/network").AttemptDescription>;
|
|
34
|
-
onListen(port: import("@agoric/internal").Remote<import("@agoric/network").Port>, localAddr: Endpoint, listenHandler: import("@agoric/internal").Remote<import("@agoric/network").ListenHandler>, p: import("@agoric/internal").Remote<import("@agoric/network").ProtocolHandler>): import("@agoric/vow").PromiseVow<void>;
|
|
35
|
-
onListenRemove(port: import("@agoric/internal").Remote<import("@agoric/network").Port>, localAddr: Endpoint, listenHandler: import("@agoric/internal").Remote<import("@agoric/network").ListenHandler>, p: import("@agoric/internal").Remote<import("@agoric/network").ProtocolHandler>): import("@agoric/vow").PromiseVow<void>;
|
|
36
|
-
onRevoke(port: import("@agoric/internal").Remote<import("@agoric/network").Port>, localAddr: Endpoint, p: import("@agoric/internal").Remote<import("@agoric/network").ProtocolHandler>): import("@agoric/vow").PromiseVow<void>;
|
|
37
|
-
}>;
|
|
38
|
-
bridgeHandler: import("@endo/exo").Guarded<{
|
|
39
|
-
fromBridge(obj: import("./types.js").IBCEvent<import("./types.js").IBCBridgeEvent>): Promise<import("@agoric/vow").Vow<any> | undefined>;
|
|
40
|
-
}>;
|
|
41
13
|
};
|
|
42
14
|
makeCallbacks: (dibcBridgeManager: import("./types.js").ScopedBridgeManager<"dibc">) => import("@endo/exo").Guarded<{
|
|
43
15
|
downcall(method: string, obj: any): Promise<any>;
|
package/src/vat-ibc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vat-ibc.d.ts","sourceRoot":"","sources":["vat-ibc.js"],"names":[],"mappings":"AAKA
|
|
1
|
+
{"version":3,"file":"vat-ibc.d.ts","sourceRoot":"","sources":["vat-ibc.js"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;GAmBC"}
|
package/src/vat-localchain.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export function buildRootObject(_vatPowers: any, _args: any, baggage: any): {
|
|
|
14
14
|
executeTx<MT extends {
|
|
15
15
|
'@type': string;
|
|
16
16
|
}[]>(messages: MT): Promise<{ [K in keyof MT]: import("@agoric/cosmic-proto").JsonSafe<import("@agoric/cosmic-proto").ResponseTo<MT[K]>>; }>;
|
|
17
|
+
monitorTransfers(tap: any): Promise<any>;
|
|
17
18
|
}>>;
|
|
18
19
|
query(request: import("@agoric/cosmic-proto").TypedJson): Promise<{
|
|
19
20
|
'@type': string;
|
|
@@ -41,6 +42,7 @@ export function buildRootObject(_vatPowers: any, _args: any, baggage: any): {
|
|
|
41
42
|
executeTx<MT extends {
|
|
42
43
|
'@type': string;
|
|
43
44
|
}[]>(messages: MT): Promise<{ [K in keyof MT]: import("@agoric/cosmic-proto").JsonSafe<import("@agoric/cosmic-proto").ResponseTo<MT[K]>>; }>;
|
|
45
|
+
monitorTransfers(tap: any): Promise<any>;
|
|
44
46
|
}>>;
|
|
45
47
|
query(request: import("@agoric/cosmic-proto").TypedJson): Promise<{
|
|
46
48
|
'@type': string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vat-localchain.d.ts","sourceRoot":"","sources":["vat-localchain.js"],"names":[],"mappings":"AAMO;IAKH;;;;;OAKG;2BADQ,OAAO,iBAAiB,EAAE,gBAAgB;;;
|
|
1
|
+
{"version":3,"file":"vat-localchain.d.ts","sourceRoot":"","sources":["vat-localchain.js"],"names":[],"mappings":"AAMO;IAKH;;;;;OAKG;2BADQ,OAAO,iBAAiB,EAAE,gBAAgB;;;8BASs1B,MAAM,KAAK,CAAC;6BAA8b,QAAQ,KAAK,CAAC,mBAA2B,OAAO;6BAAwhB,OAAO,KAAK,CAAC;;;2BAAgiB,EAAE;;;uBAAg0E,OAAO,sBAAsB,EAAE,SAAS;;;4BAAyqB,OAAO,sBAAsB,EAAE,SAAS,EAAE;;;;;;;;IAbvgL;;;;;OAKG;2BADQ,OAAO,iBAAiB,EAAE,gBAAgB;;;;;;;;;;;sDASsvJ,SAAS;;;2DAAwsB,SAAS;;;;;;;GAHxgL;4BAEa,UAAU,CAAC,OAAO,eAAe,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export function buildRootObject(_vatPowers: any, _args: any, baggage: any): {
|
|
2
|
+
/**
|
|
3
|
+
* @template {import('@agoric/internal').BridgeIdValue} T
|
|
4
|
+
* @param {import('./types').ScopedBridgeManager<T>} manager
|
|
5
|
+
* @param {string} [inboundType]
|
|
6
|
+
* @param {import('./bridge-target').AppTransformer} [appTransformer]
|
|
7
|
+
*/
|
|
8
|
+
provideBridgeTargetKit<T extends import("@agoric/internal").BridgeIdValue>(manager: import("./types").ScopedBridgeManager<T>, inboundType?: string | undefined, appTransformer?: import("./bridge-target.js").AppTransformer | undefined): import("@endo/exo").GuardedKit<{
|
|
9
|
+
bridgeHandler: {
|
|
10
|
+
fromBridge(obj: any): Promise<any>;
|
|
11
|
+
};
|
|
12
|
+
targetHost: {
|
|
13
|
+
sendDowncall(obj: any): Promise<any>;
|
|
14
|
+
};
|
|
15
|
+
targetRegistry: {
|
|
16
|
+
register(target: string, app: TargetApp, args?: unknown[] | undefined): Promise<import("./bridge-target.js").TargetRegistration>;
|
|
17
|
+
reregister(target: string, app: TargetApp, args?: unknown[] | undefined): Promise<void>;
|
|
18
|
+
unregister(target: string): Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Create middleware for exposing IBC messages to and from the underlying
|
|
23
|
+
* vtransfer port as data with embedded `action` ocaps where safe.
|
|
24
|
+
*/
|
|
25
|
+
makeTransferMiddlewareKit: () => import("@endo/exo").GuardedKit<{
|
|
26
|
+
finisher: {
|
|
27
|
+
useRegistry(registry: import("./bridge-target.js").TargetRegistry): void;
|
|
28
|
+
};
|
|
29
|
+
interceptorFactory: {
|
|
30
|
+
wrapApp: (tap: globalThis.ERef<import("./bridge-target.js").TargetApp>, targetHost: globalThis.ERef<import("./bridge-target.js").TargetHost>, isActiveTap?: boolean | undefined) => import("@endo/exo").Guarded<{
|
|
31
|
+
receiveUpcall(obj: any): Promise<import("@agoric/vow").Vow<unknown> | undefined>;
|
|
32
|
+
}>;
|
|
33
|
+
};
|
|
34
|
+
transferMiddleware: {
|
|
35
|
+
registerTap(target: string, tap: ERef<import("./bridge-target.js").TargetApp>): any;
|
|
36
|
+
registerActiveTap(target: string, tap: ERef<import("./bridge-target.js").TargetApp>): any;
|
|
37
|
+
unregisterTap(target: string): Promise<void>;
|
|
38
|
+
};
|
|
39
|
+
}>;
|
|
40
|
+
} & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {
|
|
41
|
+
/**
|
|
42
|
+
* @template {import('@agoric/internal').BridgeIdValue} T
|
|
43
|
+
* @param {import('./types').ScopedBridgeManager<T>} manager
|
|
44
|
+
* @param {string} [inboundType]
|
|
45
|
+
* @param {import('./bridge-target').AppTransformer} [appTransformer]
|
|
46
|
+
*/
|
|
47
|
+
provideBridgeTargetKit<T extends import("@agoric/internal").BridgeIdValue>(manager: import("./types").ScopedBridgeManager<T>, inboundType?: string | undefined, appTransformer?: import("./bridge-target.js").AppTransformer | undefined): import("@endo/exo").GuardedKit<{
|
|
48
|
+
bridgeHandler: {
|
|
49
|
+
fromBridge(obj: any): Promise<any>;
|
|
50
|
+
};
|
|
51
|
+
targetHost: {
|
|
52
|
+
sendDowncall(obj: any): Promise<any>;
|
|
53
|
+
};
|
|
54
|
+
targetRegistry: {
|
|
55
|
+
register(target: string, app: TargetApp, args?: unknown[] | undefined): Promise<import("./bridge-target.js").TargetRegistration>;
|
|
56
|
+
reregister(target: string, app: TargetApp, args?: unknown[] | undefined): Promise<void>;
|
|
57
|
+
unregister(target: string): Promise<void>;
|
|
58
|
+
};
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* Create middleware for exposing IBC messages to and from the underlying
|
|
62
|
+
* vtransfer port as data with embedded `action` ocaps where safe.
|
|
63
|
+
*/
|
|
64
|
+
makeTransferMiddlewareKit: () => import("@endo/exo").GuardedKit<{
|
|
65
|
+
finisher: {
|
|
66
|
+
useRegistry(registry: import("./bridge-target.js").TargetRegistry): void;
|
|
67
|
+
};
|
|
68
|
+
interceptorFactory: {
|
|
69
|
+
wrapApp: (tap: globalThis.ERef<import("./bridge-target.js").TargetApp>, targetHost: globalThis.ERef<import("./bridge-target.js").TargetHost>, isActiveTap?: boolean | undefined) => import("@endo/exo").Guarded<{
|
|
70
|
+
receiveUpcall(obj: any): Promise<import("@agoric/vow").Vow<unknown> | undefined>;
|
|
71
|
+
}>;
|
|
72
|
+
};
|
|
73
|
+
transferMiddleware: {
|
|
74
|
+
registerTap(target: string, tap: ERef<import("./bridge-target.js").TargetApp>): any;
|
|
75
|
+
registerActiveTap(target: string, tap: ERef<import("./bridge-target.js").TargetApp>): any;
|
|
76
|
+
unregisterTap(target: string): Promise<void>;
|
|
77
|
+
};
|
|
78
|
+
}>;
|
|
79
|
+
}>;
|
|
80
|
+
export type TransferVat = ReturnType<typeof buildRootObject>;
|
|
81
|
+
//# sourceMappingURL=vat-transfer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vat-transfer.d.ts","sourceRoot":"","sources":["vat-transfer.js"],"names":[],"mappings":"AASO;IAyBH;;;;;OAKG;2BAH8C,CAAC,4DAAvC,OAAO,SAAS,EAAE,mBAAmB,CAAC,CAAC,CAAC;;;;;;;;0CA2B05K,SAAS;4CAA66C,SAAS;;;;IAT54N;;;OAGG;;;kCAMq+J,OAAO,oBAAiB,EAAE,cAAc;;;;;;;;6CAA97C,KAAK,OAAO,oBAAoB,EAAE,SAAS,CAAC;mDAA5C,KAAK,OAAO,oBAAoB,EAAE,SAAS,CAAC;;;;;IA7B9nH;;;;;OAKG;2BAH8C,CAAC,4DAAvC,OAAO,SAAS,EAAE,mBAAmB,CAAC,CAAC,CAAC;;;;;;;;;;;;;IAkBnD;;;OAGG;;;+DAM+/J,cAAc;;;;;;;;+EAA55C,SAAS;qFAAT,SAAS;;;;GAHhoH;0BAEa,UAAU,CAAC,OAAO,eAAe,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { Far } from '@endo/far';
|
|
3
|
+
import { makeDurableZone } from '@agoric/zone/durable.js';
|
|
4
|
+
|
|
5
|
+
import { provideLazy } from '@agoric/store';
|
|
6
|
+
import { prepareVowTools } from '@agoric/vat-data/vow.js';
|
|
7
|
+
import { prepareBridgeTargetModule } from './bridge-target.js';
|
|
8
|
+
import { prepareTransferTools } from './transfer.js';
|
|
9
|
+
|
|
10
|
+
export const buildRootObject = (_vatPowers, _args, baggage) => {
|
|
11
|
+
const zone = makeDurableZone(baggage);
|
|
12
|
+
|
|
13
|
+
const { makeBridgeTargetKit } = prepareBridgeTargetModule(
|
|
14
|
+
zone.subZone('bridge'),
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const vowTools = prepareVowTools(zone.subZone('vow'));
|
|
18
|
+
|
|
19
|
+
const { makeTransferMiddlewareKit } = prepareTransferTools(
|
|
20
|
+
zone.subZone('transfer'),
|
|
21
|
+
vowTools,
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* This 2-level structure is to avoid holding the bridge managers strongly, as
|
|
26
|
+
* well as accommodate the lack of complex keys.
|
|
27
|
+
*
|
|
28
|
+
* @type {WeakMapStore<
|
|
29
|
+
* import('./types').ScopedBridgeManager<any>,
|
|
30
|
+
* MapStore<string, ReturnType<typeof makeBridgeTargetKit>>
|
|
31
|
+
* >}
|
|
32
|
+
*/
|
|
33
|
+
const managerToKits = zone.weakMapStore('managerToHandler');
|
|
34
|
+
return Far('TransferVat', {
|
|
35
|
+
/**
|
|
36
|
+
* @template {import('@agoric/internal').BridgeIdValue} T
|
|
37
|
+
* @param {import('./types').ScopedBridgeManager<T>} manager
|
|
38
|
+
* @param {string} [inboundType]
|
|
39
|
+
* @param {import('./bridge-target').AppTransformer} [appTransformer]
|
|
40
|
+
*/
|
|
41
|
+
provideBridgeTargetKit(
|
|
42
|
+
manager,
|
|
43
|
+
inboundType = 'IBC_EVENT',
|
|
44
|
+
appTransformer = undefined,
|
|
45
|
+
) {
|
|
46
|
+
/** @type {MapStore<string, ReturnType<typeof makeBridgeTargetKit>>} */
|
|
47
|
+
const inboundTypeToKit = provideLazy(managerToKits, manager, () =>
|
|
48
|
+
zone.detached().mapStore('inboundTypeToKit'),
|
|
49
|
+
);
|
|
50
|
+
const kit = provideLazy(inboundTypeToKit, inboundType, () =>
|
|
51
|
+
makeBridgeTargetKit(manager, inboundType, appTransformer),
|
|
52
|
+
);
|
|
53
|
+
return kit;
|
|
54
|
+
},
|
|
55
|
+
/**
|
|
56
|
+
* Create middleware for exposing IBC messages to and from the underlying
|
|
57
|
+
* vtransfer port as data with embedded `action` ocaps where safe.
|
|
58
|
+
*/
|
|
59
|
+
makeTransferMiddlewareKit,
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** @typedef {ReturnType<typeof buildRootObject>} TransferVat */
|
package/tools/fake-bridge.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export function makeFakeBankBridge(zone: import("@agoric/zone").Zone, opts?: {
|
|
|
6
6
|
export function makeFakeIbcBridge(zone: import("@agoric/zone").Zone, onToBridge: (obj: any) => void): ScopedBridgeManager<"dibc">;
|
|
7
7
|
export const LOCALCHAIN_DEFAULT_ADDRESS: "agoric1fakeLCAAddress";
|
|
8
8
|
export function makeFakeLocalchainBridge(zone: import("@agoric/zone").Zone, onToBridge?: ((obj: any) => void) | undefined): ScopedBridgeManager<"vlocalchain">;
|
|
9
|
+
export function makeFakeTransferBridge(zone: import("@agoric/zone").Zone, onToBridge?: ((obj: any) => void) | undefined): ScopedBridgeManager<"vtransfer">;
|
|
9
10
|
export type Balances = {
|
|
10
11
|
[address: string]: {
|
|
11
12
|
[denom: string]: bigint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake-bridge.d.ts","sourceRoot":"","sources":["fake-bridge.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fake-bridge.d.ts","sourceRoot":"","sources":["fake-bridge.js"],"names":[],"mappings":"AAiBA,6EAA6E;AAE7E,sCAAuC;AAchC,yCANI,OAAO,cAAc,EAAE,IAAI;IAEZ,QAAQ,EAAvB,QAAQ;gCAyFlB;AAOM,wCAJI,OAAO,cAAc,EAAE,IAAI,cAC3B,CAAC,GAAG,KAAA,KAAK,IAAI,+BA+BvB;AAED,iEAAkE;AAO3D,+CAJI,OAAO,cAAc,EAAE,IAAI,8BAClB,IAAI,mDAiEvB;AAOM,6CAJI,OAAO,cAAc,EAAE,IAAI,8BAClB,IAAI,iDAwCvB;uBA3Pa;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;CAAE;yCAPX,iBAAiB"}
|
package/tools/fake-bridge.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { assert, Fail } from '@agoric/assert';
|
|
2
3
|
import { makeTracer, VBankAccount } from '@agoric/internal';
|
|
3
4
|
import { E } from '@endo/far';
|
|
@@ -222,3 +223,47 @@ export const makeFakeLocalchainBridge = (zone, onToBridge = () => {}) => {
|
|
|
222
223
|
},
|
|
223
224
|
});
|
|
224
225
|
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* @param {import('@agoric/zone').Zone} zone
|
|
229
|
+
* @param {(obj) => void} [onToBridge]
|
|
230
|
+
* @returns {ScopedBridgeManager<'vtransfer'>}
|
|
231
|
+
*/
|
|
232
|
+
export const makeFakeTransferBridge = (zone, onToBridge = () => {}) => {
|
|
233
|
+
/** @type {Remote<BridgeHandler>} */
|
|
234
|
+
let hndlr;
|
|
235
|
+
const registered = zone.setStore('registered');
|
|
236
|
+
return zone.exo('Fake Transfer Bridge Manager', undefined, {
|
|
237
|
+
getBridgeId: () => 'vtransfer',
|
|
238
|
+
toBridge: async obj => {
|
|
239
|
+
onToBridge(obj);
|
|
240
|
+
const { type, ...params } = obj;
|
|
241
|
+
trace('toBridge', type, params);
|
|
242
|
+
switch (type) {
|
|
243
|
+
case 'BRIDGE_TARGET_REGISTER': {
|
|
244
|
+
registered.add(params.target);
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
case 'BRIDGE_TARGET_UNREGISTER': {
|
|
248
|
+
registered.delete(params.target);
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
default:
|
|
252
|
+
Fail`unknown type ${type}`;
|
|
253
|
+
}
|
|
254
|
+
return undefined;
|
|
255
|
+
},
|
|
256
|
+
fromBridge: async obj => {
|
|
257
|
+
if (!hndlr) throw Error('no handler!');
|
|
258
|
+
return when(E(hndlr).fromBridge(obj));
|
|
259
|
+
},
|
|
260
|
+
initHandler: h => {
|
|
261
|
+
if (hndlr) throw Error('already init');
|
|
262
|
+
hndlr = h;
|
|
263
|
+
},
|
|
264
|
+
setHandler: h => {
|
|
265
|
+
if (!hndlr) throw Error('must init first');
|
|
266
|
+
hndlr = h;
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
};
|