@asyncswap/eth-rpc 0.4.9 → 0.4.11
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.
- package/CHANGELOG.md +16 -0
- package/package.json +2 -2
- package/src/eth-api.ts +8 -9
- package/src/index.ts +0 -1
- package/src/base.ts +0 -49
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @asyncswap/eth-rpc
|
|
2
2
|
|
|
3
|
+
## 0.4.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 69a2d7e: patch types updates
|
|
8
|
+
- Updated dependencies [69a2d7e]
|
|
9
|
+
- @asyncswap/jsonrpc@0.4.10
|
|
10
|
+
|
|
11
|
+
## 0.4.10
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- dc792b1: (refactor): change to `withHeaders` option and update BaseClient source
|
|
16
|
+
- Updated dependencies [dc792b1]
|
|
17
|
+
- @asyncswap/jsonrpc@0.4.9
|
|
18
|
+
|
|
3
19
|
## 0.4.9
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@asyncswap/eth-rpc",
|
|
3
3
|
"description": "A library for ethereum execution clients apis.",
|
|
4
4
|
"author": "Meek Msaki",
|
|
5
|
-
"version": "0.4.
|
|
5
|
+
"version": "0.4.11",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/index.js",
|
|
@@ -40,6 +40,6 @@
|
|
|
40
40
|
"typescript": "^5"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@asyncswap/jsonrpc": "^0.4.
|
|
43
|
+
"@asyncswap/jsonrpc": "^0.4.10"
|
|
44
44
|
}
|
|
45
45
|
}
|
package/src/eth-api.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseClient } from "
|
|
1
|
+
import { BaseClient } from "@asyncswap/jsonrpc";
|
|
2
2
|
|
|
3
3
|
export class ExecutionClient extends BaseClient<EthMethodsSpec> {
|
|
4
4
|
constructor(url: string) {
|
|
@@ -7,15 +7,14 @@ export class ExecutionClient extends BaseClient<EthMethodsSpec> {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export type EthRpcMethods<
|
|
10
|
-
|
|
10
|
+
MethodsSpec extends Record<
|
|
11
|
+
string,
|
|
12
|
+
{ params: readonly unknown[]; result: unknown }
|
|
13
|
+
>,
|
|
11
14
|
> = {
|
|
12
|
-
[
|
|
15
|
+
[Method in keyof MethodsSpec]: (
|
|
16
|
+
...params: MethodsSpec[Method]["params"]
|
|
17
|
+
) => Promise<MethodsSpec[Method]["result"]>;
|
|
13
18
|
};
|
|
14
19
|
|
|
15
20
|
export interface ExecutionClient extends EthRpcMethods<EthMethodsSpec> { }
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @deprecated Use `ExecutionClient` instead.
|
|
19
|
-
* This method will be removed in v0.5.0.
|
|
20
|
-
*/
|
|
21
|
-
export class EthExecutionClient extends ExecutionClient { }
|
package/src/index.ts
CHANGED
package/src/base.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { JsonRpcClient } from "@asyncswap/jsonrpc";
|
|
2
|
-
|
|
3
|
-
export type RpcMethodSpec = {
|
|
4
|
-
params: readonly unknown[];
|
|
5
|
-
result: unknown;
|
|
6
|
-
};
|
|
7
|
-
export type RpcSpecBase = Record<string, RpcMethodSpec>;
|
|
8
|
-
|
|
9
|
-
export abstract class BaseClient<MethodsSpec extends RpcSpecBase> {
|
|
10
|
-
rpc: JsonRpcClient<MethodsSpec>;
|
|
11
|
-
protected headers: Record<string, string> = {};
|
|
12
|
-
|
|
13
|
-
constructor(url: string) {
|
|
14
|
-
this.rpc = new JsonRpcClient(url);
|
|
15
|
-
|
|
16
|
-
return new Proxy(this, {
|
|
17
|
-
get: (target: this, prop: string | symbol, receiver) => {
|
|
18
|
-
// let real properties / methods through
|
|
19
|
-
if (prop in target) {
|
|
20
|
-
const value = Reflect.get(target, prop, receiver);
|
|
21
|
-
if (typeof value === "function") {
|
|
22
|
-
return (...args: any[]) => {
|
|
23
|
-
const result = value.apply(target, args);
|
|
24
|
-
// if method returns target, return proxy instead
|
|
25
|
-
return result === target ? receiver : result;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
return value;
|
|
29
|
-
}
|
|
30
|
-
// dynamic rpc
|
|
31
|
-
if (typeof prop !== "string") return undefined;
|
|
32
|
-
|
|
33
|
-
const method = prop as keyof MethodsSpec;
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
...params: MethodsSpec[typeof method]["params"]
|
|
37
|
-
): MethodsSpec[typeof method]["result"] =>
|
|
38
|
-
this.rpc.call(this.rpc.buildRequest(method, params), this.headers);
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
setHeaders(headers: Record<string, string>) {
|
|
44
|
-
this.headers = {
|
|
45
|
-
...headers,
|
|
46
|
-
};
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
}
|