This commit is contained in:
Peter 2019-07-18 21:30:26 +01:00
parent 1ad0c6585f
commit ebabc783cd
3 changed files with 66 additions and 1 deletions

View File

@ -41,6 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
- (MTSignal *)exportKey:(TONKey *)key localPassword:(NSString *)localPassword;
- (MTSignal *)importKeyWithLocalPassword:(NSString *)localPassword mnemonicPassword:(NSString *)mnemonicPassword wordList:(NSArray<NSString *> *)wordList;
- (MTSignal *)deleteKeyWithPublicKey:(NSString *)publicKey;
- (MTSignal *)makeWalletInitialized:(TONKey *)key localPassword:(NSString *)localPassword;
@end

View File

@ -366,6 +366,37 @@ using tonlib_api::make_object;
}] startOn:[MTQueue mainQueue]] deliverOn:[MTQueue mainQueue]];
}
- (MTSignal *)makeWalletInitialized:(TONKey *)key localPassword:(NSString *)localPassword {
return [[[[MTSignal alloc] initWithGenerator:^id<MTDisposable>(MTSubscriber *subscriber) {
uint64_t requestId = _nextRequestId;
_nextRequestId += 1;
_requestHandlers[@(requestId)] = [[TONRequestHandler alloc] initWithCompletion:^(tonlib_api::object_ptr<tonlib_api::Object> &object) {
if (object->get_id() == tonlib_api::error::ID) {
auto error = tonlib_api::move_object_as<tonlib_api::error>(object);
[subscriber putError:[[TONError alloc] initWithText:[[NSString alloc] initWithUTF8String:error->message_.c_str()]]];
} else {
[subscriber putCompletion];
}
}];
NSData *publicKeyData = [[NSData alloc] initWithBase64EncodedString:key.publicKey options:0];
std::string publicKeyString((uint8_t *)publicKeyData.bytes, (uint8_t *)publicKeyData.bytes + publicKeyData.length);
NSData *secretData = [[NSData alloc] initWithBase64EncodedString:key.secret options:0];
std::string secretString((uint8_t *)secretData.bytes, (uint8_t *)secretData.bytes + secretData.length);
NSData *localPasswordData = [localPassword dataUsingEncoding:NSUTF8StringEncoding];
std::string localPasswordString((uint8_t *)localPasswordData.bytes, (uint8_t *)localPasswordData.bytes + localPasswordData.length);
auto query = make_object<tonlib_api::testWallet_init>(make_object<tonlib_api::inputKey>(make_object<tonlib_api::key>(publicKeyString, secretString), localPasswordString));
_client->send({ requestId, std::move(query) });
return [[MTBlockDisposable alloc] initWithBlock:^{
}];
}] startOn:[MTQueue mainQueue]] deliverOn:[MTQueue mainQueue]];
}
- (MTSignal *)importKeyWithLocalPassword:(NSString *)localPassword mnemonicPassword:(NSString *)mnemonicPassword wordList:(NSArray<NSString *> *)wordList {
return [[[[MTSignal alloc] initWithGenerator:^id<MTDisposable>(MTSubscriber *subscriber) {
uint64_t requestId = _nextRequestId;

View File

@ -2406,7 +2406,7 @@ public final class ChatController: TelegramController, GalleryHiddenMediaTarget,
}
let timestamp = strongSelf.context.account.network.getApproximateRemoteTimestamp()
let _ = (strongSelf.context.account.postbox.transaction { transaction in
let message1 = StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: nil, groupingKey: nil, timestamp: timestamp, flags: [.Incoming], tags: [], globalTags: [], localTags: [], forwardInfo: nil, authorId: peerId, text: "balance: \(state.balance)", attributes: [], media: [])
let message1 = StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: nil, groupingKey: nil, timestamp: timestamp, flags: [.Incoming], tags: [], globalTags: [], localTags: [], forwardInfo: nil, authorId: peerId, text: "balance: \(state.balance), seqno: \(state.seqno)", attributes: [], media: [])
let _ = transaction.addMessages([message1], location: .UpperHistoryBlock)
}).start()
})
@ -2444,6 +2444,15 @@ public final class ChatController: TelegramController, GalleryHiddenMediaTarget,
guard let localAddress = localAddress as? String else {
return
}
let _ = strongSelf.context.ton?.getAccountState(withAddress: localAddress).start(next: { state in
guard let state = state as? TONAccountState else {
return
}
let _ = (strongSelf.context.account.postbox.transaction { transaction in
let message1 = StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: nil, groupingKey: nil, timestamp: timestamp, flags: [.Incoming], tags: [], globalTags: [], localTags: [], forwardInfo: nil, authorId: peerId, text: "balance: \(state.balance), seqno: \(state.seqno)", attributes: [], media: [])
let _ = transaction.addMessages([message1], location: .UpperHistoryBlock)
}).start()
})
let _ = strongSelf.context.ton?.sendGrams(from: TONKey(publicKey: components[2], secret: components[3]), localPassword: components[4], fromAddress: localAddress, toAddress: components[5], amount: amount).start(next: nil, error: { error in
guard let error = error as? TONError else {
return
@ -2496,6 +2505,30 @@ public final class ChatController: TelegramController, GalleryHiddenMediaTarget,
}).start()
}, completed: nil)
}
} else if components[1] == "initwallet" {
if components.count >= 5 {
let timestamp = strongSelf.context.account.network.getApproximateRemoteTimestamp()
let _ = (strongSelf.context.account.postbox.transaction { transaction in
let message = StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: nil, groupingKey: nil, timestamp: timestamp, flags: [], tags: [], globalTags: [], localTags: [], forwardInfo: nil, authorId: strongSelf.context.account.peerId, text: message.text, attributes: [], media: [])
let _ = transaction.addMessages([message], location: .UpperHistoryBlock)
}).start()
let _ = strongSelf.context.ton?.makeWalletInitialized(TONKey(publicKey: components[2], secret: components[3]), localPassword: components[4]).start(next: nil, error: { error in
guard let error = error as? TONError else {
return
}
let _ = (strongSelf.context.account.postbox.transaction { transaction in
let message1 = StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: nil, groupingKey: nil, timestamp: timestamp, flags: [.Incoming], tags: [], globalTags: [], localTags: [], forwardInfo: nil, authorId: peerId, text: "error: \(error.text)", attributes: [], media: [])
let _ = transaction.addMessages([message1], location: .UpperHistoryBlock)
}).start()
}, completed: {
let timestamp = strongSelf.context.account.network.getApproximateRemoteTimestamp()
let _ = (strongSelf.context.account.postbox.transaction { transaction in
let message1 = StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: nil, groupingKey: nil, timestamp: timestamp, flags: [.Incoming], tags: [], globalTags: [], localTags: [], forwardInfo: nil, authorId: peerId, text: "done", attributes: [], media: [])
let _ = transaction.addMessages([message1], location: .UpperHistoryBlock)
}).start()
})
}
} else if components[1] == "importkey" {
if components.count >= 4 {
let timestamp = strongSelf.context.account.network.getApproximateRemoteTimestamp()