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

introduce a fix for invalid value in gas estimation, call and send transactions #95

Merged
merged 1 commit into from
Nov 20, 2018
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
2 changes: 1 addition & 1 deletion web3swift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "web3swift"
s.version = "2.0.1"
s.version = "2.0.4"
s.summary = "Web3 implementation in vanilla Swift for iOS ans macOS"

s.description = <<-DESC
Expand Down
7 changes: 2 additions & 5 deletions web3swift/Transaction/Classes/EthereumTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,10 @@ public struct EthereumTransaction: CustomStringConvertible {
static func createRequest(method: JSONRPCmethod, transaction: EthereumTransaction, transactionOptions: TransactionOptions?) -> JSONRPCrequest? {
let onBlock = transactionOptions?.callOnBlock?.stringValue
var request = JSONRPCrequest()
var tx = transaction
// var tx = transaction
request.method = method
let from = transactionOptions?.from
if transactionOptions != nil, transactionOptions!.value != nil {
tx.value = transactionOptions!.value!
}
guard var txParams = tx.encodeAsDictionary(from: from) else {return nil}
guard var txParams = transaction.encodeAsDictionary(from: from) else {return nil}
if method == .estimateGas || transactionOptions?.gasLimit == nil {
txParams.gas = nil
}
Expand Down
4 changes: 3 additions & 1 deletion web3swift/Web3/Classes/Web3+MutatingTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public class WriteTransaction: ReadTransaction {
}

var mergedOptions = self.transactionOptions.merge(transactionOptions)

if mergedOptions.value != nil {
assembledTransaction.value = mergedOptions.value!
}
var forAssemblyPipeline : (EthereumTransaction, EthereumContract, TransactionOptions) = (assembledTransaction, self.contract, mergedOptions)

for hook in self.web3.preAssemblyHooks {
Expand Down
10 changes: 8 additions & 2 deletions web3swift/Web3/Classes/Web3+ReadingTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ReadTransaction {
}

public func callPromise(transactionOptions: TransactionOptions? = nil) -> Promise<[String: Any]> {
let assembledTransaction : EthereumTransaction = self.transaction
var assembledTransaction : EthereumTransaction = self.transaction
let queue = self.web3.requestDispatcher.queue
let returnPromise = Promise<[String:Any]> { seal in
let mergedOptions = self.transactionOptions.merge(transactionOptions)
Expand All @@ -39,6 +39,9 @@ public class ReadTransaction {
optionsForCall.to = mergedOptions.to
optionsForCall.value = mergedOptions.value
optionsForCall.callOnBlock = mergedOptions.callOnBlock
if mergedOptions.value != nil {
assembledTransaction.value = mergedOptions.value!
}
let callPromise : Promise<Data> = self.web3.eth.callPromise(assembledTransaction, transactionOptions: optionsForCall)
callPromise.done(on: queue) {(data:Data) throws in
do {
Expand All @@ -63,7 +66,7 @@ public class ReadTransaction {
}

public func estimateGasPromise(transactionOptions: TransactionOptions? = nil) -> Promise<BigUInt>{
let assembledTransaction : EthereumTransaction = self.transaction
var assembledTransaction : EthereumTransaction = self.transaction
let queue = self.web3.requestDispatcher.queue
let returnPromise = Promise<BigUInt> { seal in
let mergedOptions = self.transactionOptions.merge(transactionOptions)
Expand All @@ -72,6 +75,9 @@ public class ReadTransaction {
optionsForGasEstimation.to = mergedOptions.to
optionsForGasEstimation.value = mergedOptions.value
optionsForGasEstimation.callOnBlock = mergedOptions.callOnBlock
if mergedOptions.value != nil {
assembledTransaction.value = mergedOptions.value!
}
let promise = self.web3.eth.estimateGasPromise(assembledTransaction, transactionOptions: optionsForGasEstimation)
promise.done(on: queue) {(estimate: BigUInt) in
seal.fulfill(estimate)
Expand Down