Skip to content
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

fix: parsing tuples and lists in stack + multisig send mode #42

Merged
merged 2 commits into from
Jun 11, 2024
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
35 changes: 17 additions & 18 deletions src/client/TonClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,18 +338,24 @@ export class TonClient {
}
}

function parseStackEntry(s: any): TupleItem {
switch (s["@type"]) {
case "tvm.stackEntryNumber":
return { type: 'int', value: BigInt(s.number.number) };
case "tvm.stackEntryCell":
return { type: 'cell', cell: Cell.fromBase64(s.cell) };
function parseObject(x: any): any {
const typeName = x['@type'];
switch(typeName) {
case 'tvm.list':
case 'tvm.tuple':
return x.elements.map(parseObject);
case 'tvm.cell':
return Cell.fromBoc(Buffer.from(x.bytes, 'base64'))[0];
case 'tvm.stackEntryCell':
return parseObject(x.cell);
case 'tvm.stackEntryTuple':
return { type: 'tuple', items: s.tuple.elements.map(parseStackEntry) };
case 'tvm.stackEntryList':
return { type: 'list', items: s.list.elements.map(parseStackEntry) };
return parseObject(x.tuple);
case 'tvm.stackEntryNumber':
return parseObject(x.number);
case 'tvm.numberDecimal':
return BigInt(x.number);
default:
throw Error("Unsupported item type: " + s["@type"]);
throw Error('Unsupported item type: ' + typeName);
}
}

Expand All @@ -370,14 +376,7 @@ function parseStackItem(s: any): TupleItem {
} else if (s[0] === 'builder') {
return { type: 'builder', cell: Cell.fromBoc(Buffer.from(s[1].bytes, 'base64'))[0] };
} else if (s[0] === 'tuple' || s[0] === 'list') {
// toncenter.com missbehaviour
if (s[1].elements.length === 0) {
return { type: 'null' };
}
return {
type: s[0],
items: s[1].elements.map(parseStackEntry)
};
return { type: 'tuple', items: s[1].elements.map(parseObject) };
} else {
throw Error('Unsupported stack item type: ' + s[0])
}
Expand Down
3 changes: 2 additions & 1 deletion src/multisig/MultisigWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ContractProvider,
Dictionary,
Sender,
SendMode,
Slice,
StateInit,
} from '@ton/core';
Expand Down Expand Up @@ -128,7 +129,7 @@ export class MultisigWallet {

public async deployInternal(sender: Sender, value: bigint = 1000000000n) {
await sender.send({
sendMode: 3,
sendMode: SendMode.PAY_GAS_SEPARATELY + SendMode.IGNORE_ERRORS,
to: this.address,
value: value,
init: this.init,
Expand Down