Skip to content

Commit 7d1cfb2

Browse files
author
Ed Gamble
committed
WIP #3
1 parent f936c83 commit 7d1cfb2

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

Swift/BRCore/BREthereum.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ public protocol EthereumClient : class {
610610

611611
func getBlocks (ewm: EthereumWalletManager,
612612
address: String,
613-
flags: Int32,
613+
interests: Int32,
614614
blockStart: UInt64,
615615
blockStop: UInt64,
616616
rid: Int32) -> Void
@@ -860,6 +860,12 @@ public class EthereumWalletManager {
860860
cTopics.forEach { free (UnsafeMutablePointer(mutating: $0)) }
861861
}
862862

863+
public func announceBlocks (rid: Int32,
864+
blockNumbers: [UInt64]) {
865+
// TODO: blocks must be BRArrayOf(uint64_t) - change to add `count`
866+
ethereumClientAnnounceBlocks(core, rid, UnsafeMutablePointer<UInt64>(mutating: blockNumbers))
867+
}
868+
863869
public func announceToken (rid: Int32,
864870
address: String,
865871
symbol: String,
@@ -947,12 +953,12 @@ public class EthereumWalletManager {
947953
rid: rid)
948954
}},
949955

950-
funcGetBlocks: { (coreClient, coreEWM, address, flags, blockStart, blockStop, rid) in
956+
funcGetBlocks: { (coreClient, coreEWM, address, interests, blockStart, blockStop, rid) in
951957
if let client = coreClient.map ({ Unmanaged<AnyEthereumClient>.fromOpaque($0).takeUnretainedValue() }),
952958
let ewm = EthereumWalletManager.lookup(core: coreEWM) {
953959
client.getBlocks (ewm: ewm,
954960
address: asUTF8String (address!),
955-
flags: flags,
961+
interests: interests,
956962
blockStart: blockStart,
957963
blockStop: blockStop,
958964
rid: rid)
@@ -1241,8 +1247,8 @@ class AnyEthereumClient : EthereumClient {
12411247
base.getLogs(ewm: ewm, address: address, event: event, rid: rid)
12421248
}
12431249

1244-
func getBlocks (ewm: EthereumWalletManager, address: String, flags: Int32, blockStart: UInt64, blockStop: UInt64, rid: Int32) {
1245-
base.getBlocks (ewm: ewm, address: address, flags: flags, blockStart: blockStart, blockStop: blockStop, rid: rid)
1250+
func getBlocks (ewm: EthereumWalletManager, address: String, interests: Int32, blockStart: UInt64, blockStop: UInt64, rid: Int32) {
1251+
base.getBlocks (ewm: ewm, address: address, interests: interests, blockStart: blockStart, blockStop: blockStop, rid: rid)
12461252
}
12471253

12481254
func getTokens (ewm: EthereumWalletManager, rid: Int32) {

Swift/CoreDemo/CoreDemoEthereumClient.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,49 @@ class CoreDemoEthereumClient : EthereumClient {
9898
return
9999
}
100100

101+
func getBlocks(ewm: EthereumWalletManager, address: String, interests: Int32, blockStart: UInt64, blockStop: UInt64, rid: Int32) {
102+
var blockNumbers : [UInt64] = []
103+
if "0xb302B06FDB1348915599D21BD54A06832637E5E8" == address {
104+
if 0 != interests & Int32 (1 << 3) /* CLIENT_GET_BLOCKS_LOGS_AS_TARGET */ {
105+
blockNumbers += [4847049,
106+
4847152,
107+
4894677,
108+
4965538,
109+
4999850,
110+
5029844]
111+
}
112+
113+
if 0 != interests & Int32 (1 << 2) /* CLIENT_GET_BLOCKS_LOGS_AS_SOURCE */ {
114+
blockNumbers += [5705175]
115+
}
116+
117+
if 0 != interests & Int32 (1 << 1) /* CLIENT_GET_BLOCKS_TRANSACTIONS_AS_TARGET */ {
118+
blockNumbers += [4894027,
119+
4908682,
120+
4991227]
121+
}
122+
123+
if 0 != interests & Int32 (1 << 0) /* CLIENT_GET_BLOCKS_TRANSACTIONS_AS_SOURCE */ {
124+
blockNumbers += [4894330,
125+
4894641,
126+
4894677,
127+
4903993,
128+
4906377,
129+
4997449,
130+
4999850,
131+
4999875,
132+
5000000,
133+
5705175]
134+
}
135+
}
136+
else {
137+
blockNumbers.append(contentsOf: [blockStart,
138+
(blockStart + blockStop) / 2,
139+
blockStop])
140+
}
141+
ewm.announceBlocks(rid: rid, blockNumbers: blockNumbers)
142+
}
143+
101144
func getTokens(ewm: EthereumWalletManager, rid: Int32) {
102145
ewm.announceToken (rid: rid,
103146
address: (ewm.network == EthereumNetwork.mainnet

0 commit comments

Comments
 (0)