diff --git a/Swift/BRCore/BREthereum.swift b/Swift/BRCore/BREthereum.swift index f43b6a757..4b0e79d8e 100644 --- a/Swift/BRCore/BREthereum.swift +++ b/Swift/BRCore/BREthereum.swift @@ -610,7 +610,7 @@ public protocol EthereumClient : class { func getBlocks (ewm: EthereumWalletManager, address: String, - flags: Int32, + interests: Int32, blockStart: UInt64, blockStop: UInt64, rid: Int32) -> Void @@ -860,6 +860,12 @@ public class EthereumWalletManager { cTopics.forEach { free (UnsafeMutablePointer(mutating: $0)) } } + public func announceBlocks (rid: Int32, + blockNumbers: [UInt64]) { + // TODO: blocks must be BRArrayOf(uint64_t) - change to add `count` + ethereumClientAnnounceBlocks(core, rid, UnsafeMutablePointer(mutating: blockNumbers)) + } + public func announceToken (rid: Int32, address: String, symbol: String, @@ -947,12 +953,12 @@ public class EthereumWalletManager { rid: rid) }}, - funcGetBlocks: { (coreClient, coreEWM, address, flags, blockStart, blockStop, rid) in + funcGetBlocks: { (coreClient, coreEWM, address, interests, blockStart, blockStop, rid) in if let client = coreClient.map ({ Unmanaged.fromOpaque($0).takeUnretainedValue() }), let ewm = EthereumWalletManager.lookup(core: coreEWM) { client.getBlocks (ewm: ewm, address: asUTF8String (address!), - flags: flags, + interests: interests, blockStart: blockStart, blockStop: blockStop, rid: rid) @@ -1241,8 +1247,8 @@ class AnyEthereumClient : EthereumClient { base.getLogs(ewm: ewm, address: address, event: event, rid: rid) } - func getBlocks (ewm: EthereumWalletManager, address: String, flags: Int32, blockStart: UInt64, blockStop: UInt64, rid: Int32) { - base.getBlocks (ewm: ewm, address: address, flags: flags, blockStart: blockStart, blockStop: blockStop, rid: rid) + func getBlocks (ewm: EthereumWalletManager, address: String, interests: Int32, blockStart: UInt64, blockStop: UInt64, rid: Int32) { + base.getBlocks (ewm: ewm, address: address, interests: interests, blockStart: blockStart, blockStop: blockStop, rid: rid) } func getTokens (ewm: EthereumWalletManager, rid: Int32) { diff --git a/Swift/CoreDemo/CoreDemoEthereumClient.swift b/Swift/CoreDemo/CoreDemoEthereumClient.swift index 84e333a9b..040a72ab5 100644 --- a/Swift/CoreDemo/CoreDemoEthereumClient.swift +++ b/Swift/CoreDemo/CoreDemoEthereumClient.swift @@ -98,6 +98,49 @@ class CoreDemoEthereumClient : EthereumClient { return } + func getBlocks(ewm: EthereumWalletManager, address: String, interests: Int32, blockStart: UInt64, blockStop: UInt64, rid: Int32) { + var blockNumbers : [UInt64] = [] + if "0xb302B06FDB1348915599D21BD54A06832637E5E8" == address { + if 0 != interests & Int32 (1 << 3) /* CLIENT_GET_BLOCKS_LOGS_AS_TARGET */ { + blockNumbers += [4847049, + 4847152, + 4894677, + 4965538, + 4999850, + 5029844] + } + + if 0 != interests & Int32 (1 << 2) /* CLIENT_GET_BLOCKS_LOGS_AS_SOURCE */ { + blockNumbers += [5705175] + } + + if 0 != interests & Int32 (1 << 1) /* CLIENT_GET_BLOCKS_TRANSACTIONS_AS_TARGET */ { + blockNumbers += [4894027, + 4908682, + 4991227] + } + + if 0 != interests & Int32 (1 << 0) /* CLIENT_GET_BLOCKS_TRANSACTIONS_AS_SOURCE */ { + blockNumbers += [4894330, + 4894641, + 4894677, + 4903993, + 4906377, + 4997449, + 4999850, + 4999875, + 5000000, + 5705175] + } + } + else { + blockNumbers.append(contentsOf: [blockStart, + (blockStart + blockStop) / 2, + blockStop]) + } + ewm.announceBlocks(rid: rid, blockNumbers: blockNumbers) + } + func getTokens(ewm: EthereumWalletManager, rid: Int32) { ewm.announceToken (rid: rid, address: (ewm.network == EthereumNetwork.mainnet