@apibara/beaconchain 2.1.0-beta.3 → 2.1.0-beta.30
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/dist/index.cjs +431 -410
- package/dist/index.d.cts +488 -1143
- package/dist/index.d.mts +488 -1143
- package/dist/index.d.ts +488 -1143
- package/dist/index.mjs +427 -404
- package/package.json +2 -3
- package/src/block.ts +114 -103
- package/src/common.ts +162 -88
- package/src/filter.ts +69 -72
- package/src/index.ts +1 -0
- package/src/common.test.ts +0 -21
package/src/filter.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
ArrayCodec,
|
|
3
|
+
BooleanCodec,
|
|
4
|
+
type Codec,
|
|
5
|
+
type CodecType,
|
|
6
|
+
MessageCodec,
|
|
7
|
+
NumberCodec,
|
|
8
|
+
OptionalCodec,
|
|
9
|
+
} from "@apibara/protocol/codec";
|
|
3
10
|
import { Address, ValidatorStatus } from "./common";
|
|
4
11
|
import * as proto from "./proto";
|
|
5
12
|
|
|
@@ -9,37 +16,36 @@ import * as proto from "./proto";
|
|
|
9
16
|
* - `on_data`: receive headers only if any other filter matches.
|
|
10
17
|
* - `on_data_or_on_new_block`: receive headers only if any other filter matches and for "live" blocks.
|
|
11
18
|
*/
|
|
12
|
-
export const HeaderFilter
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
},
|
|
19
|
+
export const HeaderFilter: Codec<
|
|
20
|
+
"always" | "on_data" | "on_data_or_on_new_block" | "unknown",
|
|
21
|
+
proto.filter.HeaderFilter
|
|
22
|
+
> = {
|
|
23
|
+
encode(x) {
|
|
24
|
+
switch (x) {
|
|
25
|
+
case "always":
|
|
26
|
+
return proto.filter.HeaderFilter.ALWAYS;
|
|
27
|
+
case "on_data":
|
|
28
|
+
return proto.filter.HeaderFilter.ON_DATA;
|
|
29
|
+
case "on_data_or_on_new_block":
|
|
30
|
+
return proto.filter.HeaderFilter.ON_DATA_OR_ON_NEW_BLOCK;
|
|
31
|
+
default:
|
|
32
|
+
return proto.filter.HeaderFilter.UNSPECIFIED;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
decode(p) {
|
|
36
|
+
const enumMap = {
|
|
37
|
+
[proto.filter.HeaderFilter.ALWAYS]: "always",
|
|
38
|
+
[proto.filter.HeaderFilter.ON_DATA]: "on_data",
|
|
39
|
+
[proto.filter.HeaderFilter.ON_DATA_OR_ON_NEW_BLOCK]:
|
|
40
|
+
"on_data_or_on_new_block",
|
|
41
|
+
[proto.filter.HeaderFilter.UNSPECIFIED]: "unknown",
|
|
42
|
+
[proto.filter.HeaderFilter.UNRECOGNIZED]: "unknown",
|
|
43
|
+
} as const;
|
|
44
|
+
return enumMap[p] ?? "unknown";
|
|
39
45
|
},
|
|
40
|
-
|
|
46
|
+
};
|
|
41
47
|
|
|
42
|
-
export type HeaderFilter = typeof HeaderFilter
|
|
48
|
+
export type HeaderFilter = CodecType<typeof HeaderFilter>;
|
|
43
49
|
|
|
44
50
|
/** Filter transactions.
|
|
45
51
|
*
|
|
@@ -47,73 +53,64 @@ export type HeaderFilter = typeof HeaderFilter.Type;
|
|
|
47
53
|
* @prop to Filter transactions by the target address.
|
|
48
54
|
* @prop includeBlob Include any blob posted by the transaction..
|
|
49
55
|
*/
|
|
50
|
-
export const TransactionFilter =
|
|
51
|
-
id:
|
|
52
|
-
from:
|
|
53
|
-
to:
|
|
54
|
-
create:
|
|
55
|
-
includeBlob:
|
|
56
|
+
export const TransactionFilter = MessageCodec({
|
|
57
|
+
id: OptionalCodec(NumberCodec),
|
|
58
|
+
from: OptionalCodec(Address),
|
|
59
|
+
to: OptionalCodec(Address),
|
|
60
|
+
create: OptionalCodec(BooleanCodec),
|
|
61
|
+
includeBlob: OptionalCodec(BooleanCodec),
|
|
56
62
|
});
|
|
57
63
|
|
|
58
|
-
export type TransactionFilter = typeof TransactionFilter
|
|
64
|
+
export type TransactionFilter = CodecType<typeof TransactionFilter>;
|
|
59
65
|
|
|
60
66
|
/** Filter validators.
|
|
61
67
|
*
|
|
62
68
|
* @prop validatorIndex Filter validators by their index.
|
|
63
69
|
* @prop status Filter validators by their status.
|
|
64
70
|
*/
|
|
65
|
-
export const ValidatorFilter =
|
|
66
|
-
id:
|
|
67
|
-
validatorIndex:
|
|
68
|
-
status:
|
|
71
|
+
export const ValidatorFilter = MessageCodec({
|
|
72
|
+
id: OptionalCodec(NumberCodec),
|
|
73
|
+
validatorIndex: OptionalCodec(NumberCodec),
|
|
74
|
+
status: OptionalCodec(ValidatorStatus),
|
|
69
75
|
});
|
|
70
76
|
|
|
71
|
-
export type ValidatorFilter = typeof ValidatorFilter
|
|
77
|
+
export type ValidatorFilter = CodecType<typeof ValidatorFilter>;
|
|
72
78
|
|
|
73
79
|
/** Filter blobs.
|
|
74
80
|
*
|
|
75
81
|
* @prop includeTransaction Include the transaction that posted the blob.
|
|
76
82
|
*/
|
|
77
|
-
export const BlobFilter =
|
|
78
|
-
id:
|
|
79
|
-
includeTransaction:
|
|
83
|
+
export const BlobFilter = MessageCodec({
|
|
84
|
+
id: OptionalCodec(NumberCodec),
|
|
85
|
+
includeTransaction: OptionalCodec(BooleanCodec),
|
|
80
86
|
});
|
|
81
87
|
|
|
82
|
-
export type BlobFilter = typeof BlobFilter
|
|
88
|
+
export type BlobFilter = CodecType<typeof BlobFilter>;
|
|
83
89
|
|
|
84
90
|
/** Filter block data.
|
|
85
91
|
*
|
|
86
92
|
* @prop header Change how block headers are returned.
|
|
87
93
|
* @prop validators Filter validators.
|
|
88
94
|
*/
|
|
89
|
-
export const Filter =
|
|
90
|
-
header:
|
|
91
|
-
transactions:
|
|
92
|
-
validators:
|
|
93
|
-
blobs:
|
|
95
|
+
export const Filter = MessageCodec({
|
|
96
|
+
header: OptionalCodec(HeaderFilter),
|
|
97
|
+
transactions: OptionalCodec(ArrayCodec(TransactionFilter)),
|
|
98
|
+
validators: OptionalCodec(ArrayCodec(ValidatorFilter)),
|
|
99
|
+
blobs: OptionalCodec(ArrayCodec(BlobFilter)),
|
|
94
100
|
});
|
|
95
101
|
|
|
96
|
-
export type Filter = typeof Filter
|
|
97
|
-
|
|
98
|
-
export const filterToProto = Schema.encodeSync(Filter);
|
|
99
|
-
export const filterFromProto = Schema.decodeSync(Filter);
|
|
100
|
-
|
|
101
|
-
export const FilterFromBytes = Schema.transform(
|
|
102
|
-
Schema.Uint8ArrayFromSelf,
|
|
103
|
-
Filter,
|
|
104
|
-
{
|
|
105
|
-
strict: false,
|
|
106
|
-
decode(value) {
|
|
107
|
-
return proto.filter.Filter.decode(value);
|
|
108
|
-
},
|
|
109
|
-
encode(value) {
|
|
110
|
-
return proto.filter.Filter.encode(value).finish();
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
);
|
|
102
|
+
export type Filter = CodecType<typeof Filter>;
|
|
114
103
|
|
|
115
|
-
export const
|
|
116
|
-
|
|
104
|
+
export const FilterFromBytes: Codec<Filter, Uint8Array> = {
|
|
105
|
+
encode(value) {
|
|
106
|
+
const filter = Filter.encode(value);
|
|
107
|
+
return proto.filter.Filter.encode(filter).finish();
|
|
108
|
+
},
|
|
109
|
+
decode(value) {
|
|
110
|
+
const filter = proto.filter.Filter.decode(value);
|
|
111
|
+
return Filter.decode(filter);
|
|
112
|
+
},
|
|
113
|
+
};
|
|
117
114
|
|
|
118
115
|
export function mergeFilter(a: Filter, b: Filter): Filter {
|
|
119
116
|
const header = mergeHeaderFilter(a.header, b.header);
|
package/src/index.ts
CHANGED
package/src/common.test.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { Schema } from "@effect/schema";
|
|
4
|
-
import { pad } from "viem";
|
|
5
|
-
|
|
6
|
-
import { B384 } from "./common";
|
|
7
|
-
|
|
8
|
-
describe("B384", () => {
|
|
9
|
-
const encode = Schema.encodeSync(B384);
|
|
10
|
-
const decode = Schema.decodeSync(B384);
|
|
11
|
-
|
|
12
|
-
it("should convert from and to proto", () => {
|
|
13
|
-
const value =
|
|
14
|
-
"0x9df92d765b5aa041fd4bbe8d5878eb89290efa78e444c1a603eecfae2ea05fa4";
|
|
15
|
-
|
|
16
|
-
const message = encode(value);
|
|
17
|
-
|
|
18
|
-
const back = decode(message);
|
|
19
|
-
expect(back).toEqual(pad(value, { size: 48 }));
|
|
20
|
-
});
|
|
21
|
-
});
|