From 5f47257b6be813045c6665682700c4de7d9ffb04 Mon Sep 17 00:00:00 2001 From: Ed Gamble Date: Thu, 27 Sep 2018 09:57:00 -0700 Subject: [PATCH] CORE-66: In Core Ethereum, clean up compiler warnings, update to Swift 4.2 --- Swift/BRCore.xcodeproj/project.pbxproj | 20 ++++++++++------- Swift/BRCore/BREthereum.swift | 6 +++++ Swift/BRCoreTests/BRCoreTests.swift | 4 +++- Swift/CoreDemo/AppDelegate.swift | 2 +- Swift/CoreDemo/SummaryViewController.swift | 2 +- Swift/CoreDemo/TransferCreateController.swift | 6 ++--- ethereum/bcs/BREthereumBCS.c | 2 +- ethereum/bcs/BREthereumBCSSync.c | 3 --- ethereum/blockchain/BREthereumBlock.c | 2 +- ethereum/blockchain/BREthereumTransaction.c | 4 ---- ethereum/contract/testContract.c | 4 ++-- ethereum/les/BREthereumLES.c | 6 ----- ethereum/les/BREthereumLESFrameCoder.c | 2 ++ ethereum/les/BREthereumNode.c | 22 +------------------ ethereum/les/msg/BREthereumMessageDIS.c | 2 +- 15 files changed, 34 insertions(+), 53 deletions(-) diff --git a/Swift/BRCore.xcodeproj/project.pbxproj b/Swift/BRCore.xcodeproj/project.pbxproj index ad921a330..b4c45df2c 100644 --- a/Swift/BRCore.xcodeproj/project.pbxproj +++ b/Swift/BRCore.xcodeproj/project.pbxproj @@ -1057,18 +1057,22 @@ }; 3C902601210A30F100143B69 = { CreatedOnToolsVersion = 9.4.1; + LastSwiftMigration = 1000; }; 3CAB609A20AF8C5D00810CE4 = { CreatedOnToolsVersion = 9.3.1; }; 3CAB60A520AF8C8500810CE4 = { CreatedOnToolsVersion = 9.3.1; + LastSwiftMigration = 1000; }; 3CAB60EE20AF936200810CE4 = { CreatedOnToolsVersion = 9.3.1; + LastSwiftMigration = 1000; }; 3CAB60F620AF936200810CE4 = { CreatedOnToolsVersion = 9.3.1; + LastSwiftMigration = 1000; }; }; }; @@ -1604,7 +1608,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.breadwallet.CoreDemo; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -1624,7 +1628,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.breadwallet.CoreDemo; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -1693,7 +1697,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.breadwallet.CoreTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "CoreTests/CoreTests-Bridging-Header.h"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -1715,7 +1719,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.breadwallet.CoreTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "CoreTests/CoreTests-Bridging-Header.h"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -1742,7 +1746,7 @@ PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; SWIFT_INCLUDE_PATHS = "$(SRCROOT)/Core/"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -1769,7 +1773,7 @@ PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; SWIFT_INCLUDE_PATHS = "$(SRCROOT)/Core/"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -1789,7 +1793,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.breadwallet.BRCoreTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -1809,7 +1813,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.breadwallet.BRCoreTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/Swift/BRCore/BREthereum.swift b/Swift/BRCore/BREthereum.swift index 6a88723cf..e4d45b5fa 100644 --- a/Swift/BRCore/BREthereum.swift +++ b/Swift/BRCore/BREthereum.swift @@ -133,6 +133,12 @@ public struct EthereumNetwork : EthereumPointer { static public let rinkeby = EthereumNetwork (core: ethereumRinkeby) } +extension EthereumNetwork : Equatable { + static public func == (lhs: EthereumNetwork, rhs: EthereumNetwork) -> Bool { + return lhs.core == rhs.core + } +} + // MARK: - Token /// diff --git a/Swift/BRCoreTests/BRCoreTests.swift b/Swift/BRCoreTests/BRCoreTests.swift index 90c186bdd..98d58b8c8 100644 --- a/Swift/BRCoreTests/BRCoreTests.swift +++ b/Swift/BRCoreTests/BRCoreTests.swift @@ -139,7 +139,9 @@ class TestLightClient : EthereumClient { func getTokens(ewm: EthereumWalletManager, rid: Int32) { ewm.announceToken (rid: rid, - address: "0x558ec3152e2eb2174905cd19aea4e34a23de9ad6", + address: (ewm.network == EthereumNetwork.mainnet + ? "0x558ec3152e2eb2174905cd19aea4e34a23de9ad6" + : "0x7108ca7c4718efa810457f228305c9c71390931a"), symbol: "BRD", name: "BRD Token", description: "The BRD Token", diff --git a/Swift/CoreDemo/AppDelegate.swift b/Swift/CoreDemo/AppDelegate.swift index 5c9b2e420..116d20a7d 100644 --- a/Swift/CoreDemo/AppDelegate.swift +++ b/Swift/CoreDemo/AppDelegate.swift @@ -26,7 +26,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele var client : CoreDemoEthereumClient! - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. let splitViewController = window!.rootViewController as! UISplitViewController diff --git a/Swift/CoreDemo/SummaryViewController.swift b/Swift/CoreDemo/SummaryViewController.swift index 61588deeb..d5027e4fe 100644 --- a/Swift/CoreDemo/SummaryViewController.swift +++ b/Swift/CoreDemo/SummaryViewController.swift @@ -75,7 +75,7 @@ class SummaryViewController: UITableViewController, WalletListener { return true } - override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { + override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { wallets.remove(at: indexPath.row) tableView.deleteRows(at: [indexPath], with: .fade) diff --git a/Swift/CoreDemo/TransferCreateController.swift b/Swift/CoreDemo/TransferCreateController.swift index ebf6b0701..abd73df56 100644 --- a/Swift/CoreDemo/TransferCreateController.swift +++ b/Swift/CoreDemo/TransferCreateController.swift @@ -47,8 +47,8 @@ class TransferCreateController: UIViewController, UITextViewDelegate { @IBAction func submit(_ sender: UIBarButtonItem) { NSLog ("Want to submit") - let alert = UIAlertController (title: "Submit Transaction", message: "Are you sure?", preferredStyle: UIAlertControllerStyle.actionSheet) - alert.addAction(UIAlertAction (title: "Yes", style: UIAlertActionStyle.destructive) { (action) in + let alert = UIAlertController (title: "Submit Transaction", message: "Are you sure?", preferredStyle: UIAlertController.Style.actionSheet) + alert.addAction(UIAlertAction (title: "Yes", style: UIAlertAction.Style.destructive) { (action) in let transfer = self.wallet.createTransfer (recvAddress: self.recvField.text!, amount: self.amountSlider.value.description, unit: EthereumAmountUnit.defaultUnitEther); @@ -59,7 +59,7 @@ class TransferCreateController: UIViewController, UITextViewDelegate { // Notify, close self.dismiss(animated: true) {} }) - alert.addAction(UIAlertAction (title: "No", style: UIAlertActionStyle.cancel) { (action) in + alert.addAction(UIAlertAction (title: "No", style: UIAlertAction.Style.cancel) { (action) in NSLog ("Will Cancel" ) }) self.present(alert, animated: true) {} diff --git a/ethereum/bcs/BREthereumBCS.c b/ethereum/bcs/BREthereumBCS.c index a867e30a1..5d9d908c1 100644 --- a/ethereum/bcs/BREthereumBCS.c +++ b/ethereum/bcs/BREthereumBCS.c @@ -399,7 +399,7 @@ bcsHandleAnnounce (BREthereumBCS bcs, (BREthereumLESProvisionContext) bcs, (BREthereumLESProvisionCallback) bcsSignalProvision, headNumber - reorgDepth, - 1 + reorgDepth, + (uint32_t) (1 + reorgDepth), 0, ETHEREUM_BOOLEAN_FALSE); } diff --git a/ethereum/bcs/BREthereumBCSSync.c b/ethereum/bcs/BREthereumBCSSync.c index a7cee2d09..1c3050825 100644 --- a/ethereum/bcs/BREthereumBCSSync.c +++ b/ethereum/bcs/BREthereumBCSSync.c @@ -39,9 +39,6 @@ computeOptimalStep (uint64_t numberOfBlocks, uint64_t *optimalStep, uint64_t *optimalCount); -static inline uint64_t minimum (uint64_t x, uint64_t y ) { return x <= y ? x : y; } -static inline uint64_t maximum (uint64_t x, uint64_t y ) { return x >= y ? x : y; } - /** * The BCS Sync Type represents the types of nodes in an N-ary tree. We sync Ethereum blocks based * on a N-ary search for regions of blocks where the account state of the desired address changed. diff --git a/ethereum/blockchain/BREthereumBlock.c b/ethereum/blockchain/BREthereumBlock.c index 88f64d431..71a20abb0 100644 --- a/ethereum/blockchain/BREthereumBlock.c +++ b/ethereum/blockchain/BREthereumBlock.c @@ -254,7 +254,7 @@ blockHeaderCanonicalDifficulty (BREthereumBlockHeader header, uint64_t y = parentOmmersCount == 0 ? 1 : 2; int64_t sigma_2 = max (y - delay_scaled, -99); assert (sigma_2 <= INT32_MAX && INT32_MIN <= sigma_2); - UInt256 x_sigma = mulUInt256_Small(x, (uint64_t) (sigma_2 < 0 ? -sigma_2 : sigma_2), &overflow); + UInt256 x_sigma = mulUInt256_Small(x, (uint32_t) (sigma_2 < 0 ? -sigma_2 : sigma_2), &overflow); assert (0 == overflow); uint64_t fake_block_number = header->number > 3000000 ? (header->number - 3000000) : 0; diff --git a/ethereum/blockchain/BREthereumTransaction.c b/ethereum/blockchain/BREthereumTransaction.c index 3aa67eef7..4367fb721 100644 --- a/ethereum/blockchain/BREthereumTransaction.c +++ b/ethereum/blockchain/BREthereumTransaction.c @@ -36,10 +36,6 @@ static unsigned int transactionAllocCount = 0; #endif -// Forward Declarations -static void -provideData (BREthereumTransaction transaction); - /** * An Ethereum Transaction ... * diff --git a/ethereum/contract/testContract.c b/ethereum/contract/testContract.c index d995afbde..1417d4682 100644 --- a/ethereum/contract/testContract.c +++ b/ethereum/contract/testContract.c @@ -13,9 +13,9 @@ #include "BREthereumToken.h" #if defined (BITCOIN_TESTNET) && 1 == BITCOIN_TESTNET -extern const char *tokenBRDAddress = "0x7108ca7c4718efa810457f228305c9c71390931a"; // testnet +const char *tokenBRDAddress = "0x7108ca7c4718efa810457f228305c9c71390931a"; // testnet #else -extern const char *tokenBRDAddress = "0x558ec3152e2eb2174905cd19aea4e34a23de9ad6"; // mainnet +const char *tokenBRDAddress = "0x558ec3152e2eb2174905cd19aea4e34a23de9ad6"; // mainnet #endif #if defined (BITCOIN_DEBUG) diff --git a/ethereum/les/BREthereumLES.c b/ethereum/les/BREthereumLES.c index dd9e80b72..c89a5003c 100644 --- a/ethereum/les/BREthereumLES.c +++ b/ethereum/les/BREthereumLES.c @@ -53,12 +53,6 @@ lesHandleProvision (BREthereumLES les, BREthereumNode node, BREthereumProvisionResult result); -static void -lesHandleNodeState (BREthereumLES les, - BREthereumNode node, - BREthereumNodeEndpointRoute route, - BREthereumNodeState state); - static void lesHandleStatus (BREthereumLES les, BREthereumNode node, diff --git a/ethereum/les/BREthereumLESFrameCoder.c b/ethereum/les/BREthereumLESFrameCoder.c index 66ff06687..a96cfd4f5 100644 --- a/ethereum/les/BREthereumLESFrameCoder.c +++ b/ethereum/les/BREthereumLESFrameCoder.c @@ -175,6 +175,7 @@ static void _BRAES256ECBEncrypt(const void *key32, void *buf16) memcpy(buf16, buf, sizeof(buf)); mem_clean(buf, sizeof(buf)); } + static void _BRAES256ECBDecrypt(const void *key32, void *buf16) { size_t i, j; @@ -221,6 +222,7 @@ static void _BRAES256ECBDecrypt(const void *key32, void *buf16) memcpy(buf16, buf, sizeof(buf)); mem_clean(buf, sizeof(buf)); } + // // Public Functions // diff --git a/ethereum/les/BREthereumNode.c b/ethereum/les/BREthereumNode.c index 59362b5b0..981ebd52e 100644 --- a/ethereum/les/BREthereumNode.c +++ b/ethereum/les/BREthereumNode.c @@ -57,9 +57,6 @@ nodeStateAnnounce (BREthereumNode node, BREthereumNodeEndpointRoute route, BREthereumNodeState state); -static uint64_t -getEndpointChainId (BREthereumNodeEndpoint *endpoint); - static void showEndpointStatusMessage (BREthereumNodeEndpoint *endpoint); @@ -1066,7 +1063,7 @@ nodeUpdateTimeoutRecv (BREthereumNode node, static int nodeStatusIsSufficient (BREthereumNode node) { - BREthereumP2PMessageStatusValue remValue, locValue; + BREthereumP2PMessageStatusValue remValue; // Both LES or both PIP assert (node->remote.status.identifier == node->local.status.identifier); @@ -1838,23 +1835,6 @@ showEndpointStatusMessage (BREthereumNodeEndpoint *endpoint) { } } -static uint64_t -getEndpointChainId (BREthereumNodeEndpoint *endpoint) { - switch (endpoint->status.identifier) { - case MESSAGE_P2P: - case MESSAGE_DIS: - case MESSAGE_ETH: - assert (0); - - case MESSAGE_LES: - return endpoint->status.u.les.u.status.p2p.chainId; - - case MESSAGE_PIP: - return endpoint->status.u.pip.u.status.p2p.chainId; - break; - } -} - /// MARK: - Send / Recv static BREthereumNodeStatus diff --git a/ethereum/les/msg/BREthereumMessageDIS.c b/ethereum/les/msg/BREthereumMessageDIS.c index f1a5b31ee..0601bb81b 100644 --- a/ethereum/les/msg/BREthereumMessageDIS.c +++ b/ethereum/les/msg/BREthereumMessageDIS.c @@ -59,6 +59,7 @@ uint256Bitwise (BREthereumIntBitwiseType type, return z; } +#if 0 static int uint256BitOffset (UInt256 x) { for (unsigned int index = 0; index < 256; index++) @@ -67,7 +68,6 @@ uint256BitOffset (UInt256 x) { return -1; } -#if 0 static int uint64tBitCount (uint64_t val) { int count = 0;