11import { Constants , Payload } from '@0xsequence/wallet-primitives'
2- import { AbiFunction , Address , Bytes , Hex } from 'ox'
2+ import { AbiFunction , Address , Bytes , Hex , TransactionReceipt } from 'ox'
33import { FeeOption , FeeQuote , OperationStatus , Relayer } from './relayer.js'
44
5+ type GenericProviderTransactionReceipt = 'success' | 'failed' | 'unknown'
6+
57export interface GenericProvider {
68 sendTransaction ( args : { to : string ; data : string } ) : Promise < string >
9+ getTransactionReceipt ( txHash : string ) : Promise < GenericProviderTransactionReceipt >
710}
811
912export class LocalRelayer implements Relayer {
@@ -39,6 +42,18 @@ export class LocalRelayer implements Relayer {
3942 } )
4043 return tx
4144 } ,
45+ getTransactionReceipt : async ( txHash ) => {
46+ const rpcReceipt = await eth . request ( { method : 'eth_getTransactionReceipt' , params : [ txHash ] } )
47+ if ( rpcReceipt ) {
48+ const receipt = TransactionReceipt . fromRpc ( rpcReceipt )
49+ if ( receipt ?. status === 'success' ) {
50+ return 'success'
51+ } else if ( receipt ?. status === 'reverted' ) {
52+ return 'failed'
53+ }
54+ }
55+ return 'unknown'
56+ } ,
4257 } )
4358 }
4459
@@ -65,17 +80,23 @@ export class LocalRelayer implements Relayer {
6580 }
6681
6782 async relay ( to : Address . Address , data : Hex . Hex , chainId : bigint , _ ?: FeeQuote ) : Promise < { opHash : Hex . Hex } > {
68- const hash = Payload . hash ( to , chainId , this . decodeCalls ( data ) )
69-
70- await this . provider . sendTransaction ( {
83+ const txHash = await this . provider . sendTransaction ( {
7184 to,
7285 data,
7386 } )
87+ Hex . assert ( txHash )
7488
75- return { opHash : Hex . fromBytes ( hash ) }
89+ return { opHash : txHash }
7690 }
7791
78- status ( opHash : Hex . Hex , chainId : bigint ) : Promise < OperationStatus > {
79- throw new Error ( 'Method not implemented.' )
92+ async status ( opHash : Hex . Hex , chainId : bigint ) : Promise < OperationStatus > {
93+ const receipt = await this . provider . getTransactionReceipt ( opHash )
94+ if ( receipt === 'unknown' ) {
95+ // Could be pending but we don't know
96+ return { status : 'unknown' }
97+ }
98+ return receipt === 'success'
99+ ? { status : 'confirmed' , transactionHash : opHash }
100+ : { status : 'failed' , reason : 'failed' }
80101 }
81102}
0 commit comments