nansen-cli 2.1.0 → 2.2.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.
@@ -104,6 +104,36 @@ export async function getWalletConnectAddress(chainType, chainId) {
104
104
  }
105
105
  }
106
106
 
107
+ /**
108
+ * Run a wallet send and mark anything that goes wrong as an ambiguous handoff.
109
+ *
110
+ * Once the wallet has been asked to send, no failure here proves the
111
+ * transaction stayed put. `wcExec` collapses a user rejection, a 120s approval
112
+ * timeout and a failure to launch the binary into the same bare
113
+ * `Error(err.message)`, and the timeout is precisely the case where the user DID
114
+ * approve and the wallet DID broadcast while the subprocess gave up waiting. A
115
+ * reply we cannot parse, or one carrying neither a hash nor signed bytes, says
116
+ * just as little about what the wallet did.
117
+ *
118
+ * Callers must therefore never read one of these as "nothing was sent" and go on
119
+ * to send something else. Marking it here, at the boundary, is what makes that
120
+ * hold for every call site — including ones added later — instead of depending
121
+ * on each `catch` to remember. `isFatalBroadcastError` in trading.js treats the
122
+ * flag as terminal; it is deliberately distinct from `broadcastRuledOut`, which
123
+ * is the opposite claim (the backend stated nothing was sent).
124
+ *
125
+ * @param {() => Promise<T>} fn - the send, from the wallet call through parsing
126
+ * @returns {Promise<T>}
127
+ * @template T
128
+ */
129
+ async function markBroadcastAmbiguous(fn) {
130
+ try {
131
+ return await fn();
132
+ } catch (err) {
133
+ throw Object.assign(err, { broadcastAmbiguous: true });
134
+ }
135
+ }
136
+
107
137
  /**
108
138
  * Send a transaction via WalletConnect.
109
139
  *
@@ -128,14 +158,16 @@ export async function sendTransactionViaWalletConnect(txData, timeoutMs = 120000
128
158
  chainId,
129
159
  };
130
160
 
131
- const output = await wcExec('walletconnect', ['send-transaction', JSON.stringify(payload)], timeoutMs);
132
- const result = parseWcJson(output);
161
+ return markBroadcastAmbiguous(async () => {
162
+ const output = await wcExec('walletconnect', ['send-transaction', JSON.stringify(payload)], timeoutMs);
163
+ const result = parseWcJson(output);
133
164
 
134
- if (result.transactionHash) return { txHash: result.transactionHash };
135
- if (result.txHash) return { txHash: result.txHash };
136
- if (result.signedTransaction) return { signedTransaction: result.signedTransaction };
165
+ if (result.transactionHash) return { txHash: result.transactionHash };
166
+ if (result.txHash) return { txHash: result.txHash };
167
+ if (result.signedTransaction) return { signedTransaction: result.signedTransaction };
137
168
 
138
- throw new Error('Unexpected response from walletconnect send-transaction');
169
+ throw new Error('Unexpected response from walletconnect send-transaction');
170
+ });
139
171
  }
140
172
 
141
173
  /**
@@ -186,15 +218,20 @@ export async function sendSolanaTransactionViaWalletConnect(txBase58, timeoutMs
186
218
  chainId: SOLANA_MAINNET_CHAIN,
187
219
  };
188
220
 
189
- const output = await wcExec('walletconnect', ['send-transaction', JSON.stringify(payload)], timeoutMs);
190
- const result = parseWcJson(output);
221
+ // Marked ambiguous for the same reason as the EVM send: this goes out over the
222
+ // CLI's `send-transaction` verb, so a wallet that signs-and-sends has already
223
+ // broadcast by the time a timeout or an unreadable reply reaches us.
224
+ return markBroadcastAmbiguous(async () => {
225
+ const output = await wcExec('walletconnect', ['send-transaction', JSON.stringify(payload)], timeoutMs);
226
+ const result = parseWcJson(output);
191
227
 
192
- if (result.signedTransaction) return { signedTransaction: result.signedTransaction };
193
- if (result.signature) return { signature: result.signature };
194
- // Some wallets (e.g. Phantom) return 'transaction' instead of 'signedTransaction'
195
- if (result.transaction) return { signedTransaction: result.transaction };
228
+ if (result.signedTransaction) return { signedTransaction: result.signedTransaction };
229
+ if (result.signature) return { signature: result.signature };
230
+ // Some wallets (e.g. Phantom) return 'transaction' instead of 'signedTransaction'
231
+ if (result.transaction) return { signedTransaction: result.transaction };
196
232
 
197
- throw new Error('Unexpected response from walletconnect Solana sign');
233
+ throw new Error('Unexpected response from walletconnect Solana sign');
234
+ });
198
235
  }
199
236
 
200
237
  /**