Skip to content

Commit 7ffcc6a

Browse files
author
Alex Vlasov
committed
fix skipping bip32 keystores in Keystore Manager
1 parent ab6a29b commit 7ffcc6a

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

Example/web3swiftExample/web3swiftExample/ViewController.swift

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ class ViewController: UIViewController {
7676
let encoding = eip67Data.toImage(scale: 10.0)
7777
self.imageView.image = UIImage(ciImage: encoding)
7878
self.imageView.contentMode = .scaleAspectFit
79-
//Send on Rinkeby
79+
80+
//Send on Rinkeby using normal keystore
8081

8182
let web3Rinkeby = Web3.InfuraRinkebyWeb3()
8283
web3Rinkeby.addKeystoreManager(keystoreManager)
8384
let coldWalletABI = "[{\"payable\":true,\"type\":\"fallback\"}]"
84-
8585
options = Web3Options.defaultOptions()
8686
options.gasLimit = BigUInt(21000)
8787
options.from = ks?.addresses?.first!
@@ -101,13 +101,24 @@ class ViewController: UIViewController {
101101
guard case .success(let sendingResult) = sendResult else {return}
102102
let txid = sendingResult["txhash"] as? String
103103
print("On Rinkeby TXid = " + txid!)
104-
104+
105+
//Send ETH on Rinkeby using BIP32 keystore. Should fail due to insufficient balance
106+
web3Rinkeby.addKeystoreManager(bip32keystoreManager)
107+
options.from = bip32ks?.addresses?.first!
108+
intermediateSend = web3Rinkeby.contract(coldWalletABI, at: coldWalletAddress, abiVersion: 2)!.method(options: options)!
109+
let sendResultBip32 = intermediateSend.send(password: "BANKEXFOUNDATION")
110+
switch sendResultBip32 {
111+
case .success(let r):
112+
print(r)
113+
case .failure(let err):
114+
print(err)
115+
}
116+
105117
//Balance on Rinkeby
106118
let balanceResult = web3Rinkeby.eth.getBalance(address: coldWalletAddress)
107119
guard case .success(let balance) = balanceResult else {return}
108120
print("Balance of " + coldWalletAddress.address + " = " + String(balance))
109-
110-
121+
111122
// Send mutating transaction taking parameters
112123
let testABIonRinkeby = "[{\"constant\":true,\"inputs\":[],\"name\":\"counter\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_value\",\"type\":\"uint8\"}],\"name\":\"increaseCounter\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]"
113124
let deployedTestAddress = EthereumAddress("0x1e528b190b6acf2d7c044141df775c7a79d68eba")

web3swift/KeystoreManager/Classes/KeystoreManager.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ public class KeystoreManager: AbstractKeystore {
5151
return keystore as AbstractKeystore?
5252
}
5353
}
54+
for keystore in _bip32keystores {
55+
guard let allAddresses = keystore.addresses else {continue}
56+
for addr in allAddresses {
57+
if addr == address && addr.isValid {
58+
return keystore as AbstractKeystore?
59+
}
60+
}
61+
}
5462
return nil
5563
}
5664

0 commit comments

Comments
 (0)