Skip to content

Commit

Permalink
Merge pull request #42 from aSpite/master
Browse files Browse the repository at this point in the history
fix: parsing tuples and lists in stack + multisig send mode
  • Loading branch information
dvlkv authored Jun 11, 2024
2 parents b334233 + 74a7cb5 commit 8ec017a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
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

0 comments on commit 8ec017a

Please sign in to comment.