Skip to content

Commit

Permalink
chore: limit unnecessary allocation to watcher ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Jun 30, 2024
1 parent 194ac48 commit 100e0a3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
8 changes: 4 additions & 4 deletions packages/orchestration/src/exos/agoric-names-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const makeResumableAgoricNamesHack = (
}),
vbankAssetEntriesWatcher: M.interface('vbankAssetEntriesWatcher', {
onFulfilled: M.call(M.arrayOf(M.record()))
.optional({ brand: BrandShape })
.optional(BrandShape)
.returns(VowShape),
}),
},
Expand All @@ -55,9 +55,9 @@ export const makeResumableAgoricNamesHack = (
vbankAssetEntriesWatcher: {
/**
* @param {AssetInfo[]} assets
* @param {{ brand: Brand<'nat'> }} ctx
* @param {Brand<'nat'>} brand
*/
onFulfilled(assets, { brand }) {
onFulfilled(assets, brand) {
return asVow(() => {
const { vbankAssetsByBrand } = this.state;
vbankAssetsByBrand.addAll(
Expand Down Expand Up @@ -96,7 +96,7 @@ export const makeResumableAgoricNamesHack = (
return watch(
vbankAssetEntriesP,
this.facets.vbankAssetEntriesWatcher,
{ brand },
brand,
);
});
},
Expand Down
20 changes: 9 additions & 11 deletions packages/orchestration/src/exos/local-orchestration-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const prepareLocalOrchestrationAccountKit = (
}),
getChainInfoWatcher: M.interface('getChainInfoWatcher', {
onFulfilled: M.call(M.record()) // agoric chain info
.optional({ destination: ChainAddressShape })
.optional(ChainAddressShape)
.returns(Vow$(M.record())), // connection info
}),
transferWatcher: M.interface('transferWatcher', {
Expand All @@ -116,9 +116,7 @@ export const prepareLocalOrchestrationAccountKit = (
}),
getBalanceWatcher: M.interface('getBalanceWatcher', {
onFulfilled: M.call(AmountShape)
.optional({
denom: DenomShape,
})
.optional(DenomShape)
.returns(DenomAmountShape),
}),
invitationMakers: M.interface('invitationMakers', {
Expand Down Expand Up @@ -196,9 +194,9 @@ export const prepareLocalOrchestrationAccountKit = (
getChainInfoWatcher: {
/**
* @param {ChainInfo} agoricChainInfo
* @param {{ destination: ChainAddress }} ctx
* @param {ChainAddress} destination
*/
onFulfilled(agoricChainInfo, { destination }) {
onFulfilled(agoricChainInfo, destination) {
return chainHub.getConnectionInfo(
agoricChainInfo.chainId,
destination.chainId,
Expand Down Expand Up @@ -263,7 +261,7 @@ export const prepareLocalOrchestrationAccountKit = (
*/
returnVoidWatcher: {
/**
* @param {any} _result
* @param {unknown} _result
*/
onFulfilled(_result) {
return undefined;
Expand All @@ -276,10 +274,10 @@ export const prepareLocalOrchestrationAccountKit = (
getBalanceWatcher: {
/**
* @param {Amount<'nat'>} natAmount
* @param {{ denom: DenomAmount['denom'] }} ctx
* @param {DenomAmount['denom']} denom
* @returns {DenomAmount}
*/
onFulfilled(natAmount, { denom }) {
onFulfilled(natAmount, denom) {
return harden({ denom, value: natAmount.value });
},
},
Expand All @@ -300,7 +298,7 @@ export const prepareLocalOrchestrationAccountKit = (
return watch(
E(this.state.account).getBalance(brand),
this.facets.getBalanceWatcher,
{ denom },
denom,
);
},
getBalances() {
Expand Down Expand Up @@ -413,7 +411,7 @@ export const prepareLocalOrchestrationAccountKit = (
const connectionInfoV = watch(
chainHub.getChainInfo('agoric'),
this.facets.getChainInfoWatcher,
{ destination },
destination,
);

// set a `timeoutTimestamp` if caller does not supply either `timeoutHeight` or `timeoutTimestamp`
Expand Down
10 changes: 4 additions & 6 deletions packages/orchestration/src/exos/remote-chain-facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const prepareRemoteChainFacadeKit = (
public: ChainFacadeI,
makeAccountWatcher: M.interface('makeAccountWatcher', {
onFulfilled: M.call(M.remotable())
.optional({ stakingDenom: M.string() })
.optional(M.string())
.returns(VowShape),
}),
getAddressWatcher: M.interface('makeAccountWatcher', {
Expand Down Expand Up @@ -95,19 +95,17 @@ const prepareRemoteChainFacadeKit = (
connectionInfo.counterparty.connection_id,
),
this.facets.makeAccountWatcher,
{
stakingDenom,
},
stakingDenom,
);
});
},
},
makeAccountWatcher: {
/**
* @param {IcaAccount} account
* @param {{ stakingDenom: Denom }} ctx
* @param {Denom} stakingDenom
*/
onFulfilled(account, { stakingDenom }) {
onFulfilled(account, stakingDenom) {
return watch(E(account).getAddress(), this.facets.getAddressWatcher, {
stakingDenom,
account,
Expand Down

0 comments on commit 100e0a3

Please sign in to comment.