-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: upgrade web3 dependency to v4 in defender sdk (#601)
* deps: bump web3 js * fix: tests + provider API * fix: leftovers
- Loading branch information
1 parent
717ae25
commit 1a78fad
Showing
7 changed files
with
381 additions
and
2,207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,23 @@ | ||
import { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers'; | ||
import { JsonRpcRequest, JsonRpcResponseWithResult } from 'web3'; | ||
import { Relayer } from '../relayer'; | ||
import { RelayerParams } from '../models/relayer'; | ||
import { isRelayer } from '../ethers/utils'; | ||
|
||
type Web3Callback = (error: Error | null, result?: JsonRpcResponse) => void; | ||
|
||
export class DefenderRelayQueryProvider { | ||
protected relayer: Relayer; | ||
protected id = 1; | ||
|
||
constructor(relayerCredentials: RelayerParams | Relayer) { | ||
this.relayer = isRelayer(relayerCredentials) ? relayerCredentials : new Relayer(relayerCredentials); | ||
} | ||
public sendAsync(payload: JsonRpcPayload, callback: Web3Callback): void { | ||
return this.send(payload, callback); | ||
} | ||
|
||
public send(payload: JsonRpcPayload, callback: Web3Callback): void { | ||
const payloadId = typeof payload.id === 'string' ? parseInt(payload.id) : payload.id; | ||
this.relayer | ||
.call({ method: payload.method, params: payload.params ?? [] }) | ||
.then((response) => | ||
callback(null, { | ||
...response, | ||
id: payloadId ?? response.id ?? this.id++, | ||
}), | ||
) | ||
.catch((err) => callback(err, undefined)); | ||
private toJsonRpcResponse = <T>(payload: any): JsonRpcResponseWithResult<T> => ({ | ||
jsonrpc: '2.0', | ||
id: payload.id ?? this.id++, | ||
result: payload.result, | ||
}); | ||
|
||
public async request<T>(payload: JsonRpcRequest<string[]>): Promise<JsonRpcResponseWithResult<T>> { | ||
return this.relayer.call({ method: payload.method, params: payload.params ?? [] }).then(this.toJsonRpcResponse<T>); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.