mirror of
https://github.com/lil-org/tokenary.git
synced 2024-12-03 06:25:10 +03:00
Fix gas estimation for zero value transaction
This commit is contained in:
parent
82bba0d2bd
commit
e74de03c2d
@ -150,24 +150,44 @@ struct Ethereum {
|
||||
private func getGas(chain: EthereumChain, from: String, to: String, gasPrice: String, weiAmount: EthNumber, data: String, completion: @escaping (String?) -> Void) {
|
||||
let network = EthereumNetwork.forChain(chain)
|
||||
queue.async {
|
||||
let gas = try? EthGasEstimate(
|
||||
network: network,
|
||||
senderAddress: EthAddress(hex: from),
|
||||
recipientAddress: EthAddress(hex: to),
|
||||
gasEstimate: EthGasEstimate(
|
||||
if (try? weiAmount.value().hexString == "0x") == true {
|
||||
let gas = try? EthGasEstimate(
|
||||
network: network,
|
||||
senderAddress: EthAddress(hex: from),
|
||||
recipientAddress: EthAddress(hex: to),
|
||||
gasEstimate: EthGasEstimate(
|
||||
network: network,
|
||||
senderAddress: EthAddress(hex: from),
|
||||
recipientAddress: EthAddress(hex: to),
|
||||
gasPrice: EthNumber(hex: gasPrice),
|
||||
contractCall: BytesFromHexString(hex: data)
|
||||
),
|
||||
gasPrice: EthNumber(hex: gasPrice),
|
||||
contractCall: BytesFromHexString(hex: data)
|
||||
).value().toHexString()
|
||||
DispatchQueue.main.async {
|
||||
completion(gas)
|
||||
}
|
||||
} else {
|
||||
let gas = try? EthGasEstimate(
|
||||
network: network,
|
||||
senderAddress: EthAddress(hex: from),
|
||||
recipientAddress: EthAddress(hex: to),
|
||||
gasEstimate: EthGasEstimate(
|
||||
network: network,
|
||||
senderAddress: EthAddress(hex: from),
|
||||
recipientAddress: EthAddress(hex: to),
|
||||
gasPrice: EthNumber(hex: gasPrice),
|
||||
weiAmount: weiAmount,
|
||||
contractCall: BytesFromHexString(hex: data)
|
||||
),
|
||||
gasPrice: EthNumber(hex: gasPrice),
|
||||
weiAmount: weiAmount,
|
||||
contractCall: BytesFromHexString(hex: data)
|
||||
),
|
||||
gasPrice: EthNumber(hex: gasPrice),
|
||||
weiAmount: weiAmount,
|
||||
contractCall: BytesFromHexString(hex: data)
|
||||
).value().toHexString()
|
||||
DispatchQueue.main.async {
|
||||
completion(gas)
|
||||
).value().toHexString()
|
||||
DispatchQueue.main.async {
|
||||
completion(gas)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user