-
Notifications
You must be signed in to change notification settings - Fork 9
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
IOS-7392 Refactor tron to use raw data #799
Changes from all commits
ccb091e
365d1a7
287f2c5
016b81b
2149b00
ff3db26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// TronFunction.swift | ||
// BlockchainSdk | ||
// | ||
// Created by Alexander Osokin on 12.08.2024. | ||
// Copyright © 2024 Tangem AG. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import CryptoSwift | ||
|
||
enum TronFunction: String { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Собрал с разных файлов. в одном месте |
||
case transfer = "transfer(address,uint256)" | ||
case approve = "approve(address,uint256)" | ||
case balanceOf = "balanceOf(address)" | ||
|
||
var prefix: Data { | ||
Data(rawValue.bytes).sha3(.keccak256).prefix(4) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ struct TronTarget: TargetType { | |
case getAccountResource(address: String) | ||
case getNowBlock | ||
case broadcastHex(data: Data) | ||
case tokenBalance(address: String, contractAddress: String) | ||
case tokenBalance(address: String, contractAddress: String, parameter: String) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Энкодинг с этого уровня перенес в walletManager There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Что-то мне не понятно, зачем "энкодед адрес" тащить через все функции, когда рядом у нас лежит тот же адрес в другой форме? Вроде здесь хорошее место, что бы это конвертить. Ну и название "параметр" странное, когда речь идёт о конкретном запросе, где мы знаем, что этот параметр - енкодед адрес There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Потому что функция энкодинга может выбрасывать ошибки, а глубого в сетевом слое эту ошибку нормально не обработать, да и не правильно это там делать. Поэтому пришлось поднять наверх. Параметром я назвал по двум причинам - по аналогии с соседним методом, и потому что в самой модели называется "параметр". В целом переименовать не проблема, но тогда придется еще соседние методы затронуть, а пулл и так стал большой |
||
case contractEnergyUsage(sourceAddress: String, contractAddress: String, parameter: String) | ||
case getTransactionInfoById(transactionID: String) | ||
} | ||
|
@@ -68,22 +68,20 @@ struct TronTarget: TargetType { | |
case .broadcastHex(let data): | ||
let request = TronBroadcastRequest(transaction: data.hexString.lowercased()) | ||
return .requestJSONEncodable(request) | ||
case .tokenBalance(let address, let contractAddress): | ||
let hexAddress = TronAddressService.toHexForm(address, length: 64) ?? "" | ||
|
||
case .tokenBalance(let address, let contractAddress, let parameter): | ||
let request = TronTriggerSmartContractRequest( | ||
owner_address: address, | ||
contract_address: contractAddress, | ||
function_selector: "balanceOf(address)", | ||
parameter: hexAddress, | ||
function_selector: TronFunction.balanceOf.rawValue, | ||
parameter: parameter, | ||
visible: true | ||
) | ||
return .requestJSONEncodable(request) | ||
case .contractEnergyUsage(let sourceAddress, let contractAddress, let parameter): | ||
let request = TronTriggerSmartContractRequest( | ||
owner_address: sourceAddress, | ||
contract_address: contractAddress, | ||
function_selector: "transfer(address,uint256)", | ||
function_selector: TronFunction.transfer.rawValue, | ||
parameter: parameter, | ||
visible: true | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Перенесено в TronUtils/WalletManager с рефакторингом на throws