Skip to content

Commit

Permalink
Merge pull request #95 from matterinc/2.0
Browse files Browse the repository at this point in the history
introduce a fix for invalid value in gas estimation, call and send transactions
  • Loading branch information
shamatar authored Nov 20, 2018
2 parents 5708ea4 + 601d091 commit 46018b7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
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

0 comments on commit 46018b7

Please sign in to comment.