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

[Ton]: add bounceable field to set it manually #3117

Merged
merged 2 commits into from
Apr 25, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class TestTheOpenNetworkSigner {
.setSequenceNumber(6)
.setMode(TheOpenNetwork.SendMode.PAY_FEES_SEPARATELY_VALUE or TheOpenNetwork.SendMode.IGNORE_ACTION_PHASE_ERRORS_VALUE)
.setExpireAt(1671132440)
.setBounceable(true)
.build()

val input = TheOpenNetwork.SigningInput.newBuilder()
Expand Down
16 changes: 10 additions & 6 deletions src/TheOpenNetwork/Address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ bool Address::isValid(const std::string& string) noexcept {
return true;
}

Address::Address(const std::string& string) {
Address::Address(const std::string& string, std::optional<bool> bounceable) {
if (!Address::isValid(string)) {
throw std::invalid_argument("Invalid address string");
}
Expand All @@ -83,12 +83,16 @@ Address::Address(const std::string& string) {
Data decoded = decodeUserFriendlyAddress(string);
addressData.workchainId = decoded[1];

byte tag = decoded[0];
if (tag & AddressTag::TEST_ONLY) {
isTestOnly = true;
tag ^= AddressTag::TEST_ONLY;
if (!bounceable.has_value()) {
Milerius marked this conversation as resolved.
Show resolved Hide resolved
byte tag = decoded[0];
if (tag & AddressTag::TEST_ONLY) {
isTestOnly = true;
tag ^= AddressTag::TEST_ONLY;
}
isBounceable = (tag == AddressTag::BOUNCEABLE);
} else {
isBounceable = *bounceable;
}
isBounceable = (tag == AddressTag::BOUNCEABLE);

std::copy(decoded.begin() + 2, decoded.end() - 2, addressData.hash.begin());
}
Expand Down
3 changes: 2 additions & 1 deletion src/TheOpenNetwork/Address.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "PublicKey.h"

#include "Everscale/CommonTON/RawAddress.h"
#include <optional>

#include <string>

Expand Down Expand Up @@ -44,7 +45,7 @@ class Address {
[[nodiscard]] static bool isValid(const std::string& string) noexcept;

/// Initializes an address with a string representation.
explicit Address(const std::string& string);
explicit Address(const std::string& string, std::optional<bool> bounceable = std::nullopt);

/// Initializes an address with its parts
explicit Address(
Expand Down
2 changes: 1 addition & 1 deletion src/TheOpenNetwork/Signer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace TW::TheOpenNetwork {
Data Signer::createTransferMessage(std::shared_ptr<Wallet> wallet, const PrivateKey& privateKey, const Proto::Transfer& transfer) {
const auto msg = wallet->createTransferMessage(
privateKey,
Address(transfer.dest()),
Address(transfer.dest(), transfer.bounceable()),
transfer.amount(),
transfer.sequence_number(),
static_cast<uint8_t>(transfer.mode()),
Expand Down
3 changes: 3 additions & 0 deletions src/proto/TheOpenNetwork.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ message Transfer {

// Transfer comment message (optional, empty by default)
string comment = 7;

// If the address is bounceable
bool bounceable = 8;
}

message SigningInput {
Expand Down
1 change: 1 addition & 0 deletions swift/Tests/Blockchains/TheOpenNetworkTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class TheOpenNetworkTests: XCTestCase {
$0.sequenceNumber = 6
$0.mode = UInt32(TheOpenNetworkSendMode.payFeesSeparately.rawValue | TheOpenNetworkSendMode.ignoreActionPhaseErrors.rawValue)
$0.expireAt = 1671132440
$0.bounceable = true
}

let input = TheOpenNetworkSigningInput.with {
Expand Down
7 changes: 7 additions & 0 deletions tests/chains/TheOpenNetwork/SignerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ TEST(TheOpenNetworkSigner, TransferAndDeploy) {
transfer.set_amount(10);
transfer.set_mode(Proto::SendMode::PAY_FEES_SEPARATELY | Proto::SendMode::IGNORE_ACTION_PHASE_ERRORS);
transfer.set_expire_at(1671135440);
transfer.set_bounceable(true);

const auto privateKey = parse_hex("63474e5fe9511f1526a50567ce142befc343e71a49b865ac3908f58667319cb8");
input.set_private_key(privateKey.data(), privateKey.size());
Expand All @@ -44,6 +45,7 @@ TEST(TheOpenNetworkSigner, TransferOrdinary) {
transfer.set_sequence_number(6);
transfer.set_mode(Proto::SendMode::PAY_FEES_SEPARATELY | Proto::SendMode::IGNORE_ACTION_PHASE_ERRORS);
transfer.set_expire_at(1671132440);
transfer.set_bounceable(true);

const auto privateKey = parse_hex("c38f49de2fb13223a9e7d37d5d0ffbdd89a5eb7c8b0ee4d1c299f2cefe7dc4a0");
input.set_private_key(privateKey.data(), privateKey.size());
Expand All @@ -66,6 +68,7 @@ TEST(TheOpenNetworkSigner, TransferAllBalance) {
transfer.set_sequence_number(7);
transfer.set_mode(Proto::SendMode::ATTACH_ALL_CONTRACT_BALANCE | Proto::SendMode::IGNORE_ACTION_PHASE_ERRORS);
transfer.set_expire_at(1681102222);
transfer.set_bounceable(true);

const auto privateKey = parse_hex("c38f49de2fb13223a9e7d37d5d0ffbdd89a5eb7c8b0ee4d1c299f2cefe7dc4a0");
input.set_private_key(privateKey.data(), privateKey.size());
Expand All @@ -88,6 +91,7 @@ TEST(TheOpenNetworkSigner, TransferAllBalanceNonBounceable) {
transfer.set_sequence_number(8);
transfer.set_mode(Proto::SendMode::ATTACH_ALL_CONTRACT_BALANCE | Proto::SendMode::IGNORE_ACTION_PHASE_ERRORS);
transfer.set_expire_at(1681102222);
transfer.set_bounceable(false);

const auto privateKey = parse_hex("c38f49de2fb13223a9e7d37d5d0ffbdd89a5eb7c8b0ee4d1c299f2cefe7dc4a0");
input.set_private_key(privateKey.data(), privateKey.size());
Expand All @@ -111,6 +115,7 @@ TEST(TheOpenNetworkSigner, TransferWithASCIIComment) {
transfer.set_mode(Proto::SendMode::PAY_FEES_SEPARATELY | Proto::SendMode::IGNORE_ACTION_PHASE_ERRORS);
transfer.set_expire_at(1681102222);
transfer.set_comment("test comment");
transfer.set_bounceable(true);

const auto privateKey = parse_hex("c38f49de2fb13223a9e7d37d5d0ffbdd89a5eb7c8b0ee4d1c299f2cefe7dc4a0");
input.set_private_key(privateKey.data(), privateKey.size());
Expand All @@ -134,6 +139,7 @@ TEST(TheOpenNetworkSigner, TransferWithUTF8Comment) {
transfer.set_mode(Proto::SendMode::PAY_FEES_SEPARATELY | Proto::SendMode::IGNORE_ACTION_PHASE_ERRORS);
transfer.set_expire_at(1681102222);
transfer.set_comment("тестовый комментарий");
transfer.set_bounceable(true);

const auto privateKey = parse_hex("c38f49de2fb13223a9e7d37d5d0ffbdd89a5eb7c8b0ee4d1c299f2cefe7dc4a0");
input.set_private_key(privateKey.data(), privateKey.size());
Expand All @@ -155,6 +161,7 @@ TEST(TheOpenNetworkSigner, InvalidWalletVersion) {
transfer.set_amount(10);
transfer.set_mode(Proto::SendMode::PAY_FEES_SEPARATELY | Proto::SendMode::IGNORE_ACTION_PHASE_ERRORS);
transfer.set_expire_at(1671135440);
transfer.set_bounceable(true);

const auto privateKey = parse_hex("63474e5fe9511f1526a50567ce142befc343e71a49b865ac3908f58667319cb8");
input.set_private_key(privateKey.data(), privateKey.size());
Expand Down
1 change: 1 addition & 0 deletions tests/chains/TheOpenNetwork/TWAnySignerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ TEST(TWAnySignerTheOpenNetwork, SingMessageToTransferAndDeployWallet) {
transfer.set_amount(10);
transfer.set_mode(Proto::SendMode::PAY_FEES_SEPARATELY | Proto::SendMode::IGNORE_ACTION_PHASE_ERRORS);
transfer.set_expire_at(1671135440);
transfer.set_bounceable(true);

const auto privateKey = parse_hex("63474e5fe9511f1526a50567ce142befc343e71a49b865ac3908f58667319cb8");
input.set_private_key(privateKey.data(), privateKey.size());
Expand Down
3 changes: 2 additions & 1 deletion wasm/tests/Blockchain/TheOpenNetwork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ describe("TheOpenNetwork", () => {
amount: new Long(10),
sequenceNumber: 6,
mode: (TW.TheOpenNetwork.Proto.SendMode.PAY_FEES_SEPARATELY | TW.TheOpenNetwork.Proto.SendMode.IGNORE_ACTION_PHASE_ERRORS),
expireAt: 1671132440
expireAt: 1671132440,
bounceable: true
});

let input = TW.TheOpenNetwork.Proto.SigningInput.create({
Expand Down