1 |
|
2 |
|
3 | import { U8aFixed } from '@polkadot/types-codec';
|
4 | import { hexToU8a, isHex, isString, isU8a, u8aToU8a } from '@polkadot/util';
|
5 | import { ethereumEncode, isEthereumAddress } from '@polkadot/util-crypto';
|
6 |
|
7 |
|
8 | function decodeAccountId(value) {
|
9 | if (isU8a(value) || Array.isArray(value)) {
|
10 | return u8aToU8a(value);
|
11 | } else if (isHex(value) || isEthereumAddress(value.toString())) {
|
12 | return hexToU8a(value.toString());
|
13 | } else if (isString(value)) {
|
14 | return u8aToU8a(value);
|
15 | }
|
16 |
|
17 | return value;
|
18 | }
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | export class GenericEthereumAccountId extends U8aFixed {
|
29 | constructor(registry, value = new Uint8Array()) {
|
30 | super(registry, decodeAccountId(value), 160);
|
31 | }
|
32 | |
33 |
|
34 |
|
35 |
|
36 |
|
37 | eq(other) {
|
38 | return super.eq(decodeAccountId(other));
|
39 | }
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 | toHuman() {
|
46 | return this.toJSON();
|
47 | }
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 | toJSON() {
|
54 | return this.toString();
|
55 | }
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 | toString() {
|
62 | return ethereumEncode(this);
|
63 | }
|
64 | |
65 |
|
66 |
|
67 |
|
68 |
|
69 | toRawType() {
|
70 | return 'AccountId';
|
71 | }
|
72 |
|
73 | } |
\ | No newline at end of file |