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

Add toString for Address type #224

Merged
merged 5 commits into from
Apr 2, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- JSON Schema for `tact.config.json`: PR [#194](https://github.com/tact-lang/tact/pull/194)
- Display an error for integer overflow at compile-time: PR [#200](https://github.com/tact-lang/tact/pull/200)
- Non-modifying `StringBuilder`'s `concat` method for chained string concatenations: PR [#217](https://github.com/tact-lang/tact/pull/217)
- `toString` extension function for `Address` type: PR [#224](https://github.com/tact-lang/tact/pull/224)

### Changed
- Update the `dump` function to handle addresses: PR [#175](https://github.com/tact-lang/tact/pull/175)
Expand Down
3 changes: 2 additions & 1 deletion src/imports/stdlib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ files['std/text.tact'] =
'bHNlIHsKICAgICAgICAgICAgdGhyb3coMTM0KTsKICAgICAgICB9CiAgICB9CgogICAgLy8gUGFkZGluZwogICAgbGV0IHRvdGFsOiBJbnQgPSByZXN1bHQuYml0cygp' +
'OwogICAgbGV0IHBhZGRpbmc6IEludCA9IHRvdGFsICUgODsKICAgIGlmIChwYWRkaW5nICE9IDApIHsKICAgICAgICBsZXQgczogU2xpY2UgPSByZXN1bHQuYXNTbGlj' +
'ZSgpOwogICAgICAgIHJldHVybiBzLmxvYWRCaXRzKHRvdGFsIC0gcGFkZGluZyk7CiAgICB9IGVsc2UgewogICAgICAgIHJldHVybiByZXN1bHQuYXNTbGljZSgpOwog' +
'ICAgfQp9';
'ICAgfQp9CgovLwovLyBBZGRyZXNzIGNvbnZlcnNpb24KLy8KCkBuYW1lKF9fdGFjdF9hZGRyZXNzX3RvX3VzZXJmcmllbmRseSkKZXh0ZW5kcyBuYXRpdmUgdG9TdHJp' +
'bmcoc2VsZjogQWRkcmVzcyk6IFN0cmluZzs=';
files['stdlib_ex.fc'] =
'Zm9yYWxsIFggLT4gdHVwbGUgX190YWN0X3NldCh0dXBsZSB4LCBYIHYsIGludCBpKSBhc20gIlNFVElOREVYVkFSUSI7CigpIF9fdGFjdF9ub3AoKSBhc20gIk5PUCI7' +
'CnNsaWNlIF9fdGFjdF9zdHJfdG9fc2xpY2Uoc2xpY2UgcykgYXNtICJOT1AiOwpzbGljZSBfX3RhY3Rfc2xpY2VfdG9fc3RyKHNsaWNlIHMpIGFzbSAiTk9QIjsKc2xp' +
Expand Down
2 changes: 2 additions & 0 deletions src/test/feature-strings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@ describe('feature-strings', () => {
expect(await contract.getStringWithEscapedChars4()).toEqual(
"\u{2028}\u{2029} \u0044 \x41\x42\x43"
);

expect(await contract.getStringWithAddress()).toEqual('EQBKgXCNLPexWhs2L79kiARR1phGH1LwXxRbNsCFF9doc2lN');
});
});
4 changes: 4 additions & 0 deletions src/test/features/strings.tact
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,8 @@ contract StringsTester {
get fun stringWithEscapedChars4(): String {
return "\u{2028}\u{2029} \u0044 \x41\x42\x43";
}

get fun stringWithAddress(): String {
return address("EQBKgXCNLPexWhs2L79kiARR1phGH1LwXxRbNsCFF9doc2lN").toString();
}
}
9 changes: 8 additions & 1 deletion stdlib/std/text.tact
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,11 @@ extends fun fromBase64(self: Slice): Slice {
} else {
return result.asSlice();
}
}
}

//
// Address conversion
//

@name(__tact_address_to_userfriendly)
extends native toString(self: Address): String;
Loading