-
Notifications
You must be signed in to change notification settings - Fork 39
/
AccountStatusChange.ts
43 lines (38 loc) · 1.2 KB
/
AccountStatusChange.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
/**
* Copyright (c) Whales Corp.
* All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { Builder } from "../boc/Builder";
import { Slice } from "../boc/Slice";
// acst_unchanged$0 = AccStatusChange; // x -> x
// acst_frozen$10 = AccStatusChange; // init -> frozen
// acst_deleted$11 = AccStatusChange; // frozen -> deleted
export type AccountStatusChange = 'unchanged' | 'frozen' | 'deleted';
export function loadAccountStatusChange(slice: Slice): AccountStatusChange {
if (!slice.loadBit()) {
return 'unchanged';
}
if (slice.loadBit()) {
return 'frozen';
} else {
return 'deleted';
}
}
export function storeAccountStatusChange(src: AccountStatusChange) {
return (builder: Builder) => {
if (src == 'unchanged') {
builder.storeBit(0);
} else if (src === 'frozen') {
builder.storeBit(1);
builder.storeBit(0);
} else if (src === 'deleted') {
builder.storeBit(1);
builder.storeBit(1);
} else {
throw Error('Invalid account status change');
}
};
}