@@ -55,13 +55,6 @@ const SwingsetMsgs = {
5555
5656/** @typedef {{owner: string, spendAction: string} } WalletSpendAction */
5757
58- const SwingsetRegistry = new Registry ( [
59- ...defaultRegistryTypes ,
60- // XXX should this list be "upstreamed" to @agoric/cosmic-proto?
61- [ SwingsetMsgs . MsgWalletSpendAction . typeUrl , MsgWalletSpendAction ] ,
62- [ SwingsetMsgs . MsgProvision . typeUrl , MsgProvision ] ,
63- ] ) ;
64-
6558/**
6659 * @returns {StdFee }
6760 */
@@ -127,19 +120,28 @@ const SwingsetConverters = {
127120 } ,
128121} ;
129122
123+ /**
124+ * @typedef {object } MakeInteractiveSignerOpts
125+ * @property {Array<[string, import('@cosmjs/proto-signing').GeneratedType]> } registryTypes
126+ * @property {import('@cosmjs/stargate').SigningStargateClientOptions['gasPrice'] } gasPrice
127+ * @property {AminoConverters } converters
128+ */
129+
130130/**
131131 * Use Keplr to sign offers and delegate object messaging to local storage key.
132132 * @param {string } chainId
133133 * @param {string } rpc
134134 * @param {Keplr } keplr
135135 * @param {typeof import('@cosmjs/stargate').SigningStargateClient.connectWithSigner } connectWithSigner
136+ * @param {MakeInteractiveSignerOpts } [opts]
136137 * Ref: https://docs.keplr.app/api/
137138 */
138139export const makeInteractiveSigner = async (
139140 chainId ,
140141 rpc ,
141142 keplr ,
142143 connectWithSigner ,
144+ opts ,
143145) => {
144146 await null ;
145147 try {
@@ -163,10 +165,19 @@ export const makeInteractiveSigner = async (
163165 ...SwingsetConverters ,
164166 ...createBankAminoConverters ( ) ,
165167 ...createAuthzAminoConverters ( ) ,
168+ ...( opts ?. converters || { } ) ,
166169 } ;
170+ const SwingsetRegistry = new Registry ( [
171+ ...defaultRegistryTypes ,
172+ // XXX should this list be "upstreamed" to @agoric/cosmic-proto?
173+ [ SwingsetMsgs . MsgWalletSpendAction . typeUrl , MsgWalletSpendAction ] ,
174+ [ SwingsetMsgs . MsgProvision . typeUrl , MsgProvision ] ,
175+ ...( opts ?. registryTypes || [ ] ) ,
176+ ] ) ;
167177 const signingClient = await connectWithSigner ( rpc , offlineSigner , {
168178 aminoTypes : new AminoTypes ( converters ) ,
169179 registry : SwingsetRegistry ,
180+ ...( opts ?. gasPrice ? { gasPrice : opts . gasPrice } : { } ) ,
170181 } ) ;
171182 console . debug ( 'InteractiveSigner' , { signingClient } ) ;
172183
@@ -240,6 +251,29 @@ export const makeInteractiveSigner = async (
240251 console . debug ( 'spend action result tx' , tx ) ;
241252 assertIsDeliverTxSuccess ( tx ) ;
242253
254+ return tx ;
255+ } ,
256+ /**
257+ * Sign and broadcast any Action
258+ *
259+ * @param {import('@cosmjs/proto-signing').EncodeObject } msg encoded msg
260+ * @throws if account does not exist on chain, user cancels,
261+ * RPC connection fails, RPC service fails to broadcast (
262+ * for example, if signature verification fails)
263+ */
264+ signAndBroadcast : async msg => {
265+ const { accountNumber, sequence } = await signingClient . getSequence (
266+ address ,
267+ ) ;
268+ console . debug ( { accountNumber, sequence } ) ;
269+
270+ const msgs = [ msg ] ;
271+ console . debug ( 'sign msg' , { address, msgs, fee } ) ;
272+
273+ const tx = await signingClient . signAndBroadcast ( address , msgs , fee ) ;
274+ console . debug ( 'msg result tx' , tx ) ;
275+ assertIsDeliverTxSuccess ( tx ) ;
276+
243277 return tx ;
244278 } ,
245279 } ) ;
0 commit comments