-
Notifications
You must be signed in to change notification settings - Fork 39
/
StorageInto.ts
38 lines (33 loc) · 1.14 KB
/
StorageInto.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
/**
* 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";
import { Maybe } from "../utils/maybe";
import { loadStorageUsed, StorageUsed, storeStorageUsed } from "./StorageUsed"
// Source: https://github.com/ton-blockchain/ton/blob/24dc184a2ea67f9c47042b4104bbb4d82289fac1/crypto/block/block.tlb#L228
// storage_info$_ used:StorageUsed last_paid:uint32
// due_payment:(Maybe Grams) = StorageInfo;
export type StorageInfo = {
used: StorageUsed;
lastPaid: number;
duePayment?: Maybe<bigint>;
}
export function loadStorageInfo(slice: Slice): StorageInfo {
return {
used: loadStorageUsed(slice),
lastPaid: slice.loadUint(32),
duePayment: slice.loadMaybeCoins()
};
}
export function storeStorageInfo(src: StorageInfo) {
return (builder: Builder) => {
builder.store(storeStorageUsed(src.used));
builder.storeUint(src.lastPaid, 32);
builder.storeMaybeCoins(src.duePayment);
};
}