Navigation Menu

Skip to content

Commit

Permalink
Update tonlib
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali committed Apr 23, 2020
1 parent fb07f06 commit 69fb8c7
Show file tree
Hide file tree
Showing 734 changed files with 23,432 additions and 164,869 deletions.
31 changes: 22 additions & 9 deletions Wallet/Sources/AppDelegate.swift
Expand Up @@ -757,15 +757,28 @@ final class AppDelegate: NSObject, UIApplicationDelegate {
|> deliverOnMainQueue).start(next: { records, publicKey in
if let record = records.first {
if let publicKey = publicKey {
if record.info.encryptedSecret.publicKey == publicKey {
if record.exportCompleted {
let _ = (walletAddress(publicKey: record.info.publicKey, tonInstance: walletContext.tonInstance)
|> deliverOnMainQueue).start(next: { address in
let infoScreen = WalletInfoScreen(context: walletContext, walletInfo: record.info, address: address, enableDebugActions: false)
beginWithController(infoScreen)
})
} else {
let createdScreen = WalletSplashScreen(context: walletContext, mode: .created(walletInfo: record.info, words: nil), walletCreatedPreloadState: nil)
let recordPublicKey: Data
switch record.info {
case let .ready(info, _, _):
recordPublicKey = info.encryptedSecret.publicKey
case let .imported(info):
recordPublicKey = info.encryptedSecret.publicKey
}
if recordPublicKey == publicKey {
switch record.info {
case let .ready(info, exportCompleted, _):
if exportCompleted {
let _ = (walletAddress(walletInfo: info, tonInstance: walletContext.tonInstance)
|> deliverOnMainQueue).start(next: { address in
let infoScreen = WalletInfoScreen(context: walletContext, walletInfo: info, address: address, enableDebugActions: false)
beginWithController(infoScreen)
})
} else {
let createdScreen = WalletSplashScreen(context: walletContext, mode: .created(walletInfo: info, words: nil), walletCreatedPreloadState: nil)
beginWithController(createdScreen)
}
case let .imported(info):
let createdScreen = WalletSplashScreen(context: walletContext, mode: .successfullyImported(importedInfo: info), walletCreatedPreloadState: nil)
beginWithController(createdScreen)
}
} else {
Expand Down
2 changes: 2 additions & 0 deletions submodules/PeerInfoUI/Sources/ChannelAdminController.swift
Expand Up @@ -1004,6 +1004,8 @@ public func channelAdminController(context: AccountContext, peerId: PeerId, admi
if let peer = adminView.peers[adminView.peerId] {
text = presentationData.strings.Privacy_GroupsAndChannels_InviteToGroupError(peer.compactDisplayTitle, peer.compactDisplayTitle).0
}
case .notMutualContact:
text = presentationData.strings.GroupInfo_AddUserLeftError
default:
break
}
Expand Down
2 changes: 2 additions & 0 deletions submodules/PeerInfoUI/Sources/ChannelMembersController.swift
Expand Up @@ -396,6 +396,8 @@ public func channelMembersController(context: AccountContext, peerId: PeerId) ->
text = presentationData.strings.Login_UnknownError
case .restricted:
text = presentationData.strings.Channel_ErrorAddBlocked
case .notMutualContact:
text = presentationData.strings.GroupInfo_AddUserLeftError
case let .bot(memberId):
let _ = (context.account.postbox.transaction { transaction in
return transaction.getPeer(peerId)
Expand Down
2 changes: 1 addition & 1 deletion submodules/PeerInfoUI/Sources/GroupInfoController.swift
Expand Up @@ -1750,7 +1750,7 @@ public func groupInfoController(context: AccountContext, peerId originalPeerId:
return state.withUpdatedTemporaryParticipants(temporaryParticipants).withUpdatedSuccessfullyAddedParticipantIds(successfullyAddedParticipantIds)
}
return .complete()
case .privacy:
case .privacy, .notMutualContact:
let _ = (context.account.postbox.loadedPeerWithId(memberId)
|> deliverOnMainQueue).start(next: { peer in
presentControllerImpl?(textAlertController(context: context, title: nil, text: presentationData.strings.Privacy_GroupsAndChannels_InviteToGroupError(peer.compactDisplayTitle, peer.compactDisplayTitle).0, actions: [TextAlertAction(type: .genericAction, title: presentationData.strings.Common_OK, action: {})]), nil)
Expand Down
12 changes: 10 additions & 2 deletions submodules/TelegramCore/Sources/AddPeerMember.swift
Expand Up @@ -10,6 +10,7 @@ public enum AddGroupMemberError {
case generic
case groupFull
case privacy
case notMutualContact
case tooManyChannels
}

Expand All @@ -26,6 +27,8 @@ public func addGroupMember(account: Account, peerId: PeerId, memberId: PeerId) -
return .privacy
case "USER_CHANNELS_TOO_MUCH":
return .tooManyChannels
case "USER_NOT_MUTUAL_CONTACT":
return .notMutualContact
default:
return .generic
}
Expand Down Expand Up @@ -68,6 +71,7 @@ public func addGroupMember(account: Account, peerId: PeerId, memberId: PeerId) -
public enum AddChannelMemberError {
case generic
case restricted
case notMutualContact
case limitExceeded
case tooMuchJoined
case bot(PeerId)
Expand Down Expand Up @@ -98,8 +102,10 @@ public func addChannelMember(account: Account, peerId: PeerId, memberId: PeerId)
return .fail(.tooMuchJoined)
case "USERS_TOO_MUCH":
return .fail(.limitExceeded)
case "USER_PRIVACY_RESTRICTED", "USER_NOT_MUTUAL_CONTACT":
case "USER_PRIVACY_RESTRICTED":
return .fail(.restricted)
case "USER_NOT_MUTUAL_CONTACT":
return .fail(.notMutualContact)
case "USER_BOT":
return .fail(.bot(memberId))
case "BOT_GROUPS_BLOCKED":
Expand Down Expand Up @@ -194,8 +200,10 @@ public func addChannelMembers(account: Account, peerId: PeerId, memberIds: [Peer
switch error.errorDescription {
case "CHANNELS_TOO_MUCH":
return .tooMuchJoined
case "USER_PRIVACY_RESTRICTED", "USER_NOT_MUTUAL_CONTACT":
case "USER_PRIVACY_RESTRICTED":
return .restricted
case "USER_NOT_MUTUAL_CONTACT":
return .notMutualContact
case "USERS_TOO_MUCH":
return .limitExceeded
default:
Expand Down
10 changes: 9 additions & 1 deletion submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift
Expand Up @@ -3342,6 +3342,12 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
self?.controller?.present(textAlertController(context: context, title: nil, text: presentationData.strings.Privacy_GroupsAndChannels_InviteToGroupError(peer.compactDisplayTitle, peer.compactDisplayTitle).0, actions: [TextAlertAction(type: .genericAction, title: presentationData.strings.Common_OK, action: {})]), in: .window(.root))
})
return .complete()
case .notMutualContact:
let _ = (context.account.postbox.loadedPeerWithId(memberId)
|> deliverOnMainQueue).start(next: { peer in
self?.controller?.present(textAlertController(context: context, title: nil, text: presentationData.strings.GroupInfo_AddUserLeftError, actions: [TextAlertAction(type: .genericAction, title: presentationData.strings.Common_OK, action: {})]), in: .window(.root))
})
return .complete()
case .tooManyChannels:
let _ = (context.account.postbox.loadedPeerWithId(memberId)
|> deliverOnMainQueue).start(next: { peer in
Expand Down Expand Up @@ -3399,7 +3405,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
return context.account.postbox.multiplePeersView(memberIds)
|> take(1)
|> deliverOnMainQueue
|> castError(AddChannelMemberError.self)
|> castError(AddChannelMemberError.self)
|> mapToSignal { view -> Signal<Void, AddChannelMemberError> in
if memberIds.count == 1 {
return context.peerChannelMemberCategoriesContextsManager.addMember(account: context.account, peerId: groupPeer.id, memberId: memberIds[0])
Expand Down Expand Up @@ -3479,6 +3485,8 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
default:
break
}
} else if peers.count == 1, case .notMutualContact = error {
self?.controller?.present(textAlertController(context: context, title: nil, text: presentationData.strings.GroupInfo_AddUserLeftError, actions: [TextAlertAction(type: .genericAction, title: presentationData.strings.Common_OK, action: {})]), in: .window(.root))
} else if case .tooMuchJoined = error {
self?.controller?.present(textAlertController(context: context, title: nil, text: presentationData.strings.Invite_ChannelsTooMuch, actions: [TextAlertAction(type: .genericAction, title: presentationData.strings.Common_OK, action: {})]), in: .window(.root))
}
Expand Down
7 changes: 5 additions & 2 deletions submodules/TonBinding/Sources/TON.h
Expand Up @@ -30,12 +30,15 @@ NS_ASSUME_NONNULL_BEGIN
@interface TONAccountState : NSObject

@property (nonatomic, readonly) bool isInitialized;
@property (nonatomic, readonly) bool isRWallet;
@property (nonatomic, readonly) int64_t balance;
@property (nonatomic, readonly) int64_t unlockedBalance;

@property (nonatomic, readonly) int32_t seqno;
@property (nonatomic, strong, readonly) TONTransactionId * _Nullable lastTransactionId;
@property (nonatomic, readonly) int64_t syncUtime;

- (instancetype)initWithIsInitialized:(bool)isInitialized balance:(int64_t)balance seqno:(int32_t)seqno lastTransactionId:(TONTransactionId * _Nullable)lastTransactionId syncUtime:(int64_t)syncUtime;
- (instancetype)initWithIsInitialized:(bool)isInitialized isRWallet:(bool)isRWallet balance:(int64_t)balance unlockedBalance:(int64_t)unlockedBalance seqno:(int32_t)seqno lastTransactionId:(TONTransactionId * _Nullable)lastTransactionId syncUtime:(int64_t)syncUtime;

@end

Expand Down Expand Up @@ -166,7 +169,7 @@ NS_ASSUME_NONNULL_BEGIN
- (SSignal *)validateConfig:(NSString *)config blockchainName:(NSString *)blockchainName;

- (SSignal *)createKeyWithLocalPassword:(NSData *)localPassword mnemonicPassword:(NSData *)mnemonicPassword;
- (SSignal *)getWalletAccountAddressWithPublicKey:(NSString *)publicKey initialWalletId:(int64_t)initialWalletId;
- (SSignal *)getWalletAccountAddressWithPublicKey:(NSString *)publicKey initialWalletId:(int64_t)initialWalletId rwalletInitialPublicKey:(NSString * _Nullable)rwalletInitialPublicKey;
- (SSignal *)getAccountStateWithAddress:(NSString *)accountAddress;
- (SSignal *)generateSendGramsQueryFromKey:(TONKey *)key localPassword:(NSData *)localPassword fromAddress:(NSString *)fromAddress toAddress:(NSString *)address amount:(int64_t)amount comment:(NSData *)comment encryptComment:(bool)encryptComment forceIfDestinationNotInitialized:(bool)forceIfDestinationNotInitialized timeout:(int32_t)timeout randomId:(int64_t)randomId;
- (SSignal *)generateFakeSendGramsQueryFromAddress:(NSString *)fromAddress toAddress:(NSString *)address amount:(int64_t)amount comment:(NSData *)comment encryptComment:(bool)encryptComment forceIfDestinationNotInitialized:(bool)forceIfDestinationNotInitialized timeout:(int32_t)timeout;
Expand Down
57 changes: 46 additions & 11 deletions submodules/TonBinding/Sources/TON.mm
Expand Up @@ -98,11 +98,13 @@ - (instancetype)initWithPublicKey:(NSString *)publicKey secret:(NSData *)secret

@implementation TONAccountState

- (instancetype)initWithIsInitialized:(bool)isInitialized balance:(int64_t)balance seqno:(int32_t)seqno lastTransactionId:(TONTransactionId * _Nullable)lastTransactionId syncUtime:(int64_t)syncUtime {
- (instancetype)initWithIsInitialized:(bool)isInitialized isRWallet:(bool)isRWallet balance:(int64_t)balance unlockedBalance:(int64_t)unlockedBalance seqno:(int32_t)seqno lastTransactionId:(TONTransactionId * _Nullable)lastTransactionId syncUtime:(int64_t)syncUtime {
self = [super init];
if (self != nil) {
_isInitialized = isInitialized;
_isRWallet = isRWallet;
_balance = balance;
_unlockedBalance = unlockedBalance;
_seqno = seqno;
_lastTransactionId = lastTransactionId;
_syncUtime = syncUtime;
Expand Down Expand Up @@ -632,14 +634,23 @@ - (SSignal *)createKeyWithLocalPassword:(NSData *)localPassword mnemonicPassword
}] startOn:[SQueue mainQueue]] deliverOn:[SQueue mainQueue]];
}

- (SSignal *)getWalletAccountAddressWithPublicKey:(NSString *)publicKey initialWalletId:(int64_t)initialWalletId {
- (SSignal *)getWalletAccountAddressWithPublicKey:(NSString *)publicKey initialWalletId:(int64_t)initialWalletId rwalletInitialPublicKey:(NSString * _Nullable)rwalletInitialPublicKey {
return [[[[SSignal alloc] initWithGenerator:^id<SDisposable>(SSubscriber *subscriber) {
NSData *publicKeyData = [publicKey dataUsingEncoding:NSUTF8StringEncoding];
if (publicKeyData == nil) {
[subscriber putError:[[TONError alloc] initWithText:@"Error encoding UTF8 string in getWalletAccountAddressWithPublicKey"]];
return [[SBlockDisposable alloc] initWithBlock:^{}];
}

NSData *rwalletInitialPublicKeyData = nil;
if (rwalletInitialPublicKey != nil) {
rwalletInitialPublicKeyData = [rwalletInitialPublicKey dataUsingEncoding:NSUTF8StringEncoding];
if (rwalletInitialPublicKeyData == nil) {
[subscriber putError:[[TONError alloc] initWithText:@"Error encoding UTF8 string for rwalletInitialPublicKey in getWalletAccountAddressWithPublicKey"]];
return [[SBlockDisposable alloc] initWithBlock:^{}];
}
}

uint64_t requestId = _nextRequestId;
_nextRequestId += 1;

Expand All @@ -656,14 +667,27 @@ - (SSignal *)getWalletAccountAddressWithPublicKey:(NSString *)publicKey initialW
}
}];

auto initialAccountState = make_object<tonlib_api::wallet_v3_initialAccountState>(
makeString(publicKeyData),
initialWalletId
);
tonlib_api::object_ptr<tonlib_api::InitialAccountState> initialAccountState;

std::int32_t revision;
if (rwalletInitialPublicKey != nil) {
initialAccountState = make_object<tonlib_api::rwallet_initialAccountState>(
makeString(rwalletInitialPublicKeyData),
makeString(publicKeyData),
initialWalletId
);
revision = -1;
} else {
initialAccountState = tonlib_api::move_object_as<tonlib_api::InitialAccountState>(make_object<tonlib_api::wallet_v3_initialAccountState>(
makeString(publicKeyData),
initialWalletId
));
revision = 1;
}

auto query = make_object<tonlib_api::getAccountAddress>(
tonlib_api::move_object_as<tonlib_api::InitialAccountState>(initialAccountState),
1
revision
);
_client->send({ requestId, std::move(query) });

Expand All @@ -684,12 +708,21 @@ - (SSignal *)getAccountStateWithAddress:(NSString *)accountAddress {
} else if (object->get_id() == tonlib_api::fullAccountState::ID) {
auto fullAccountState = tonlib_api::move_object_as<tonlib_api::fullAccountState>(object);
int32_t seqNo = -1;

bool isRWallet = false;
int64_t unlockedBalance = INT64_MAX;

if (fullAccountState->account_state_->get_id() == tonlib_api::uninited_accountState::ID) {
seqNo = -1;
} else if (fullAccountState->account_state_->get_id() == tonlib_api::wallet_v3_accountState::ID) {
auto v3AccountState = tonlib_api::move_object_as<tonlib_api::wallet_v3_accountState>(fullAccountState->account_state_);
seqNo = v3AccountState->seqno_;
} else {
} else if (fullAccountState->account_state_->get_id() == tonlib_api::rwallet_accountState::ID) {
auto rwalletAccountState = tonlib_api::move_object_as<tonlib_api::rwallet_accountState>(fullAccountState->account_state_);
isRWallet = true;
unlockedBalance = rwalletAccountState->unlocked_balance_;
seqNo = rwalletAccountState->seqno_;
}else {
[subscriber putError:[[TONError alloc] initWithText:@"Unknown type"]];
return;
}
Expand All @@ -698,7 +731,7 @@ - (SSignal *)getAccountStateWithAddress:(NSString *)accountAddress {
if (fullAccountState->last_transaction_id_ != nullptr) {
lastTransactionId = [[TONTransactionId alloc] initWithLt:fullAccountState->last_transaction_id_->lt_ transactionHash:makeData(fullAccountState->last_transaction_id_->hash_)];
}
[subscriber putNext:[[TONAccountState alloc] initWithIsInitialized:false balance:fullAccountState->balance_ seqno:-1 lastTransactionId:lastTransactionId syncUtime:fullAccountState->sync_utime_]];
[subscriber putNext:[[TONAccountState alloc] initWithIsInitialized:false isRWallet:isRWallet balance:fullAccountState->balance_ unlockedBalance:unlockedBalance seqno:-1 lastTransactionId:lastTransactionId syncUtime:fullAccountState->sync_utime_]];
[subscriber putCompletion];
} else {
assert(false);
Expand Down Expand Up @@ -785,7 +818,8 @@ - (SSignal *)generateSendGramsQueryFromKey:(TONKey *)key localPassword:(NSData *
),
make_object<tonlib_api::accountAddress>(fromAddress.UTF8String),
timeout,
tonlib_api::move_object_as<tonlib_api::Action>(inputAction)
tonlib_api::move_object_as<tonlib_api::Action>(inputAction),
nil
);
_client->send({ requestId, std::move(query) });

Expand Down Expand Up @@ -840,7 +874,8 @@ - (SSignal *)generateFakeSendGramsQueryFromAddress:(NSString *)fromAddress toAdd
make_object<tonlib_api::inputKeyFake>(),
make_object<tonlib_api::accountAddress>(fromAddress.UTF8String),
timeout,
tonlib_api::move_object_as<tonlib_api::Action>(inputAction)
tonlib_api::move_object_as<tonlib_api::Action>(inputAction),
nil
);
_client->send({ requestId, std::move(query) });

Expand Down

0 comments on commit 69fb8c7

Please sign in to comment.