-
Notifications
You must be signed in to change notification settings - Fork 0
/
codecs.ts
84 lines (66 loc) · 1.82 KB
/
codecs.ts
1
2
3
4
5
6
7
8
9
10
11
12
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import {
decodeBool,
decodeCompact,
decodeI128,
decodeI16,
decodeI32,
decodeI64,
decodeI8,
decodeStr,
decodeU128,
decodeU16,
decodeU32,
decodeU64,
decodeU8,
decodeUint8Vec,
decodeUnit,
encodeBool,
encodeCompact,
encodeI128,
encodeI16,
encodeI32,
encodeI64,
encodeI8,
encodeStr,
encodeU128,
encodeU16,
encodeU32,
encodeU64,
encodeU8,
encodeUint8Vec,
encodeUnit,
} from '@scale-codec/core'
import { trackableCodec } from './core'
// Integers
type U8 = number
const U8 = trackableCodec<I8>('u8', encodeU8, decodeU8)
type I8 = number
const I8 = trackableCodec<I8>('i8', encodeI8, decodeI8)
type U16 = number
const U16 = trackableCodec<U16>('u16', encodeU16, decodeU16)
type I16 = number
const I16 = trackableCodec<I16>('i16', encodeI16, decodeI16)
type U32 = number
const U32 = trackableCodec<U32>('u32', encodeU32, decodeU32)
type I32 = number
const I32 = trackableCodec<I32>('i32', encodeI32, decodeI32)
type U64 = bigint
const U64 = trackableCodec<U64>('u64', encodeU64, decodeU64)
type I64 = bigint
const I64 = trackableCodec<I64>('i64', encodeI64, decodeI64)
type U128 = bigint
const U128 = trackableCodec<U128>('u128', encodeU128, decodeU128)
type I128 = bigint
const I128 = trackableCodec<I128>('i128', encodeI128, decodeI128)
// Others
type Str = string
const Str = trackableCodec<Str>('str', encodeStr, decodeStr)
type Bool = boolean
const Bool = trackableCodec<Bool>('bool', encodeBool, decodeBool)
type Unit = null
const Unit = trackableCodec<Unit>('()', encodeUnit, decodeUnit)
type VecU8 = Uint8Array
const VecU8 = trackableCodec<VecU8>('VecU8', encodeUint8Vec, decodeUint8Vec)
type Compact = bigint
const Compact = trackableCodec<Compact>('compact', encodeCompact, decodeCompact)
export { U8, I8, U16, I16, U32, I32, U64, I64, U128, I128, Str, Unit, VecU8, Bool, Compact }