Skip to content

Commit

Permalink
WIP #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Gamble committed Sep 29, 2018
1 parent f936c83 commit 7d1cfb2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
16 changes: 11 additions & 5 deletions Swift/BRCore/BREthereum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<UInt64>(mutating: blockNumbers))
}

public func announceToken (rid: Int32,
address: String,
symbol: String,
Expand Down Expand Up @@ -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<AnyEthereumClient>.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)
Expand Down Expand Up @@ -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) {
Expand Down
43 changes: 43 additions & 0 deletions Swift/CoreDemo/CoreDemoEthereumClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7d1cfb2

Please sign in to comment.