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: as coins map value serialization type now generates correct code #987

Merged
merged 10 commits into from
Nov 5, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Prevent inline code snippets from changing their background color: PR [#935](https://github.com/tact-lang/tact/pull/935)
- Docs: correctly handle next and previous page links at the bottom of the pages when there's a separator item in the sidebar: PR [#949](https://github.com/tact-lang/tact/pull/949)
- Docs: compilation of examples in `data-structures.mdx` and across Cookbook: PR [#917](https://github.com/tact-lang/tact/pull/917)
- `as coins` map value serialization type is now handled correctly: PR [#987](https://github.com/tact-lang/tact/pull/987)

### Release contributors

Expand Down
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"uintptr",
"uninit",
"unixfs",
"varuint",
"workchain",
"xffff",
"привет"
Expand Down
16 changes: 16 additions & 0 deletions src/abi/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ export const MapFunctions: Map<string, AbiFunction> = new Map([
} else if (self.valueAs?.startsWith("uint")) {
vBits = parseInt(self.valueAs.slice(4), 10);
vKind = "uint";
} else if (self.valueAs?.startsWith("coins")) {
vKind = "coins";
ctx.used(`__tact_dict_set_${kind}_${vKind}`);
return `${resolved[0]}~__tact_dict_set_${kind}_${vKind}(${bits}, ${resolved[1]}, ${resolved[2]})`;
}
ctx.used(`__tact_dict_set_${kind}_${vKind}`);
return `${resolved[0]}~__tact_dict_set_${kind}_${vKind}(${bits}, ${resolved[1]}, ${resolved[2]}, ${vBits})`;
Expand Down Expand Up @@ -226,6 +230,10 @@ export const MapFunctions: Map<string, AbiFunction> = new Map([
} else if (self.valueAs?.startsWith("uint")) {
vBits = parseInt(self.valueAs.slice(4), 10);
vKind = "uint";
} else if (self.valueAs?.startsWith("coins")) {
vKind = "coins";
ctx.used(`__tact_dict_get_${kind}_${vKind}`);
return `__tact_dict_get_${kind}_${vKind}(${resolved[0]}, ${bits}, ${resolved[1]})`;
}
ctx.used(`__tact_dict_get_${kind}_${vKind}`);
return `__tact_dict_get_${kind}_${vKind}(${resolved[0]}, ${bits}, ${resolved[1]}, ${vBits})`;
Expand Down Expand Up @@ -571,6 +579,10 @@ export const MapFunctions: Map<string, AbiFunction> = new Map([
} else if (self.valueAs?.startsWith("uint")) {
vBits = parseInt(self.valueAs.slice(4), 10);
vKind = "uint";
} else if (self.valueAs?.startsWith("coins")) {
vKind = "coins";
ctx.used(`__tact_dict_replace_${kind}_${vKind}`);
return `${resolved[0]}~__tact_dict_replace_${kind}_${vKind}(${bits}, ${resolved[1]}, ${resolved[2]})`;
}
ctx.used(`__tact_dict_replace_${kind}_${vKind}`);
return `${resolved[0]}~__tact_dict_replace_${kind}_${vKind}(${bits}, ${resolved[1]}, ${resolved[2]}, ${vBits})`;
Expand Down Expand Up @@ -649,6 +661,10 @@ export const MapFunctions: Map<string, AbiFunction> = new Map([
} else if (self.valueAs?.startsWith("uint")) {
vBits = parseInt(self.valueAs.slice(4), 10);
vKind = "uint";
} else if (self.valueAs?.startsWith("coins")) {
vKind = "coins";
ctx.used(`__tact_dict_replaceget_${kind}_${vKind}`);
return `${resolved[0]}~__tact_dict_replaceget_${kind}_${vKind}(${bits}, ${resolved[1]}, ${resolved[2]})`;
}
ctx.used(`__tact_dict_replaceget_${kind}_${vKind}`);
return `${resolved[0]}~__tact_dict_replaceget_${kind}_${vKind}(${bits}, ${resolved[1]}, ${resolved[2]}, ${vBits})`;
Expand Down
10 changes: 9 additions & 1 deletion src/bindings/typescript/serializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ type MapSerializerDescrKey =
| { kind: "address" };
type MapSerializerDescrValue =
| { kind: "int" | "uint"; bits: number }
| { kind: "varuint"; length: number }
| { kind: "boolean" }
| { kind: "address" }
| { kind: "cell" }
Expand Down Expand Up @@ -665,6 +666,9 @@ function getValueParser(src: MapSerializerDescrValue) {
return `Dictionary.Values.BigUint(${src.bits})`;
}
}
case "varuint": {
return `Dictionary.Values.BigVarUint(${src.length})`;
}
case "address": {
return "Dictionary.Values.Address()";
}
Expand Down Expand Up @@ -739,7 +743,7 @@ const map: Serializer<MapSerializerDescr> = {
) {
value = { kind: "uint", bits: 256 };
} else if (src.valueFormat === "coins") {
value = { kind: "uint", bits: 124 };
value = { kind: "varuint", length: 4 };
}
}
if (src.value === "address") {
Expand Down Expand Up @@ -809,6 +813,10 @@ const map: Serializer<MapSerializerDescr> = {
}
}
break;
case "varuint": {
valueT = `bigint`;
break;
}
case "boolean":
{
valueT = `boolean`;
Expand Down
Loading
Loading