Skip to content

Commit

Permalink
feat(types): generic return for executeTx
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed May 9, 2024
1 parent 981b7bf commit dfc830b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
24 changes: 24 additions & 0 deletions packages/orchestration/test/types.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
* @file pure types types, no runtime, ignored by Ava
*/
import { expectNotType, expectType } from 'tsd';
import { typedJson } from '@agoric/cosmic-proto';
import type { MsgDelegateResponse } from '@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js';
import type { QueryAllBalancesResponse } from '@agoric/cosmic-proto/cosmos/bank/v1beta1/query.js';
import type { ChainAddress, CosmosValidatorAddress } from '../src/types.js';
import type { LocalchainAccountKit } from '../src/exos/localchainAccountKit.js';

const validatorAddr = {
chainId: 'agoric3',
Expand All @@ -24,3 +28,23 @@ expectNotType<CosmosValidatorAddress>(chainAddr);
// @ts-expect-error
const notVa: CosmosValidatorAddress = chainAddr;
}

{
const lcak: LocalchainAccountKit = null as any;
const lca = lcak.helper.owned();
const results = await lca.executeTx([
typedJson('/cosmos.staking.v1beta1.MsgDelegate', {
amount: {
amount: '1',
denom: 'ubld',
},
validatorAddress: 'agoric1valoperhello',
delegatorAddress: 'agoric1pleab',
}),
typedJson('/cosmos.bank.v1beta1.QueryAllBalancesRequest', {
address: 'agoric1pleab',
}),
] as const);
expectType<MsgDelegateResponse>(results[0]);
expectType<QueryAllBalancesResponse>(results[1]);
}
11 changes: 9 additions & 2 deletions packages/vats/src/localchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { AmountShape } from '@agoric/ertp';

const { Fail, bare } = assert;

/** @import {TypedJson, ResponseTo} from '@agoric/cosmic-proto'; */

/**
* @typedef {{
* system: import('./types.js').ScopedBridgeManager;
Expand Down Expand Up @@ -68,8 +70,13 @@ const prepareLocalChainAccount = zone =>
return E(allegedPurse).deposit(payment);
},
/**
* @param {import('@agoric/cosmic-proto').TypedJson<unknown>[]} messages
* @returns {Promise<import('@agoric/cosmic-proto').TypedJson[]>}
* Execute a batch of transactions and return the responses. Use
* `typedJson()` on the arguments to get typed return values.
*
* @template {TypedJson[]} MT messages tuple (use const with multiple
* elements or it will be a mixed array)
* @param {MT} messages
* @returns {Promise<{ [K in keyof MT]: ResponseTo<MT[K]> }>}
*/
async executeTx(messages) {
const { address, powers } = this.state;
Expand Down

0 comments on commit dfc830b

Please sign in to comment.