@atomiqlabs/chain-starknet 4.0.0-dev.15 → 4.0.0-dev.17

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.
@@ -49,7 +49,18 @@ class StarknetChainEventsBrowser {
49
49
  */
50
50
  getSwapDataGetter(event, claimHandler) {
51
51
  return async () => {
52
- const trace = await this.provider.getTransactionTrace(event.txHash);
52
+ let trace;
53
+ try {
54
+ trace = await this.provider.getTransactionTrace(event.txHash);
55
+ }
56
+ catch (e) {
57
+ this.logger.warn("getSwapDataGetter(): getter: starknet_traceTransaction not supported by the RPC: ", e);
58
+ const blockTraces = await this.provider.getBlockTransactionsTraces(event.blockHash);
59
+ const foundTrace = blockTraces.find(val => (0, Utils_1.toHex)(val.transaction_hash) === (0, Utils_1.toHex)(event.txHash));
60
+ if (foundTrace == null)
61
+ throw new Error(`Cannot find ${event.txHash} in the block traces, block: ${event.blockHash}`);
62
+ trace = foundTrace.trace_root;
63
+ }
53
64
  if (trace == null)
54
65
  return null;
55
66
  if (trace.execute_invocation.revert_reason != null)
@@ -12,6 +12,8 @@ class Rpc08ChannelWithRetries extends starknet_1.RPC08.RpcChannel {
12
12
  return (0, Utils_1.tryWithRetries)(() => super.fetchEndpoint(method, params), this.retryPolicy, e => {
13
13
  if (!e.message.startsWith("RPC: "))
14
14
  return false;
15
+ if (e.message.includes("Unsupported method"))
16
+ return true;
15
17
  const arr = e.message.split("\n");
16
18
  const errorCode = parseInt(arr[arr.length - 1]);
17
19
  if (isNaN(errorCode))
@@ -32,6 +34,8 @@ class Rpc09ChannelWithRetries extends starknet_1.RPC09.RpcChannel {
32
34
  return (0, Utils_1.tryWithRetries)(() => super.fetchEndpoint(method, params), this.retryPolicy, e => {
33
35
  if (!e.message.startsWith("RPC: "))
34
36
  return false;
37
+ if (e.message.includes("Unsupported method"))
38
+ return true;
35
39
  const arr = e.message.split("\n");
36
40
  const errorCode = parseInt(arr[arr.length - 1]);
37
41
  if (isNaN(errorCode))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/chain-starknet",
3
- "version": "4.0.0-dev.15",
3
+ "version": "4.0.0-dev.17",
4
4
  "description": "Starknet specific base implementation",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -100,7 +100,16 @@ export class StarknetChainEventsBrowser implements ChainEvents<StarknetSwapData>
100
100
  claimHandler: IClaimHandler<any, any>
101
101
  ): () => Promise<StarknetSwapData> {
102
102
  return async () => {
103
- const trace: any = await this.provider.getTransactionTrace(event.txHash);
103
+ let trace: any;
104
+ try {
105
+ trace = await this.provider.getTransactionTrace(event.txHash);
106
+ } catch (e) {
107
+ this.logger.warn("getSwapDataGetter(): getter: starknet_traceTransaction not supported by the RPC: ", e);
108
+ const blockTraces: any[] = await this.provider.getBlockTransactionsTraces(event.blockHash);
109
+ const foundTrace = blockTraces.find(val => toHex(val.transaction_hash)===toHex(event.txHash));
110
+ if(foundTrace==null) throw new Error(`Cannot find ${event.txHash} in the block traces, block: ${event.blockHash}`);
111
+ trace = foundTrace.trace_root;
112
+ }
104
113
  if(trace==null) return null;
105
114
  if(trace.execute_invocation.revert_reason!=null) return null;
106
115
  return this.findInitSwapData(trace.execute_invocation as any, event.params.escrow_hash, claimHandler);
@@ -21,6 +21,7 @@ export class Rpc08ChannelWithRetries extends RPC08.RpcChannel {
21
21
  protected fetchEndpoint(method: any, params?: any): Promise<any> {
22
22
  return tryWithRetries(() => super.fetchEndpoint(method, params), this.retryPolicy, e => {
23
23
  if(!e.message.startsWith("RPC: ")) return false;
24
+ if(e.message.includes("Unsupported method")) return true;
24
25
  const arr = e.message.split("\n");
25
26
  const errorCode = parseInt(arr[arr.length-1]);
26
27
  if(isNaN(errorCode)) return false;
@@ -47,6 +48,7 @@ export class Rpc09ChannelWithRetries extends RPC09.RpcChannel {
47
48
  protected fetchEndpoint(method: any, params?: any): Promise<any> {
48
49
  return tryWithRetries(() => super.fetchEndpoint(method, params), this.retryPolicy, e => {
49
50
  if(!e.message.startsWith("RPC: ")) return false;
51
+ if(e.message.includes("Unsupported method")) return true;
50
52
  const arr = e.message.split("\n");
51
53
  const errorCode = parseInt(arr[arr.length-1]);
52
54
  if(isNaN(errorCode)) return false;