+
Skip to content

fix: for backward compatibility in previous schemes storageExtra may … #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/types/StorageExtraInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) Whales Corp.
* Copyright (c) Whales Corp.
* All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
Expand Down Expand Up @@ -32,11 +32,11 @@ export function loadStorageExtraInfo(slice: Slice): StorageExtraInfo | null {

export function storeStorageExtraInfo(src: StorageExtraInfo | null) {
return (builder: Builder) => {
if (src === null) {
if (src === null || typeof src === 'undefined') {
builder.storeUint(0, 3);
} else {
builder.storeUint(1, 3);
builder.storeUint(src.dictHash, 256);
}
};
}
}
42 changes: 40 additions & 2 deletions src/types/StorageInfo.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Cell } from '../boc/Cell';
import { loadStorageInfo } from './StorageInfo';
import {loadStorageInfo, StorageInfo, storeStorageInfo} from './StorageInfo';
import {Builder} from "../boc/Builder";


describe('StorageInfo', () => {
Expand All @@ -18,4 +19,41 @@ describe('StorageInfo', () => {
duePayment: null
});
});
});

it.each([
['9c7b98a341201e6492f2bcf144215e1ddbef6774126caa57784fbce25597d4f7', {
used: { cells: 22n, bits: 5705n },
storageExtra: null,
lastPaid: 1748811232,
duePayment: null,
}],
['7672b3010077582fa477bf2b070183412aa0d1a9b98ba8c437b9d90b37b6a559', {
used: { cells: 22n, bits: 5705n },
storageExtra: {
dictHash: 0n,
},
lastPaid: 1748811232,
duePayment: null,
}],
])('should store and store storage info %s', (hash: string, data: StorageInfo) => {
const builder = new Builder();
storeStorageInfo(data)(builder);
const c = builder.endCell();
expect(c.hash().toString('hex')).toEqual(hash);
});

// Source: https://github.com/ton-blockchain/ton/blob/b3b2bd1c3c645a931a9aa6cbfc915c258c9012cc/crypto/block/block.tlb#L256-L257
// storage_info$_ used:StorageUsed last_paid:uint32
// due_payment:(Maybe Grams) = StorageInfo;
it('should store and store storage info (old)', () => {
const builder = new Builder();
// @ts-ignore
storeStorageInfo({
used: { cells: 22n, bits: 5705n },
lastPaid: 1748811232,
duePayment: null,
})(builder);
const c = builder.endCell();
expect(c.hash().toString('hex')).toEqual('9c7b98a341201e6492f2bcf144215e1ddbef6774126caa57784fbce25597d4f7');
});
});
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载