Skip to content

Commit

Permalink
fix: storeMessageRelaxed support exotic
Browse files Browse the repository at this point in the history
  • Loading branch information
dvlkv committed Jan 29, 2024
1 parent 63cbe8d commit c6bab51
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/types/MessageRelaxed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,20 @@ describe('MessageRelaxed', () => {
.endCell();
expect(stored.equals(cell)).toBe(true);
});

it('should store exotic message relaxed', () => {
let boc = 'te6cckEBBgEApwAJRgMNtncFfUUJSR6XK02Y/bjHpB1pj8VtOlnKAxgDtajfKgACASIFgZABAwIoSAEBN4Yioo+yQnBEkgpN5SV1lnSGuoJhL3ShCi0dcMHbuFcAACIBIAUEAE2/fOtFTZyY8zlmFJ8dch//XZQ4QApiXOGPZXvjFv5j0LSgZ7ckWPAoSAEBr+h0Em3TbCgl+CpPMKKoQskNFu4vLU/8w4Zuaz7PRP8AAOG0rdg=';
let cell = Cell.fromBase64(boc);

let payload = beginCell().store(storeMessageRelaxed({
body: cell,
info: {
createdAt: 0,
createdLt: 0n,
type: 'external-out',
dest: null,
src: null,
}
})).endCell();
});
});
12 changes: 10 additions & 2 deletions src/types/MessageRelaxed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,16 @@ export function storeMessageRelaxed(message: MessageRelaxed, opts?: { forceRef?:
if (opts && opts.forceRef) {
needRef = true;
} else {
if (builder.availableBits - 1 /* At least on byte for ref flag */ >= message.body.bits.length &&
builder.refs + message.body.refs.length <= 4) {

/*
1. If at least one bit for ref flag
2. If enough space for refs
3. If not exotic
*/

if (builder.availableBits - 1 >= message.body.bits.length &&
builder.refs + message.body.refs.length <= 4 &&
!message.body.isExotic) {
needRef = false;
} else {
needRef = true;
Expand Down

0 comments on commit c6bab51

Please sign in to comment.