Refactor: waku_types separation of concern (trial with waku_swap) (#282)

* waku_types refactor: Accounting types to waku_swap

* waku_types refactor: Separate waku_swap_types file

* Fix import path for waku_swap
This commit is contained in:
Oskar Thorén 2020-11-23 10:27:45 +08:00 committed by GitHub
parent f8aff5756c
commit 54ac399f5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 30 deletions

View File

@ -11,7 +11,8 @@ import
libp2p/transports/transport,
libp2p/transports/tcptransport,
eth/keys,
../../waku/v2/protocol/[waku_store, message_notifier, waku_swap],
../../waku/v2/protocol/[waku_store, message_notifier],
../../waku/v2/protocol/waku_swap/waku_swap,
../../waku/v2/node/message_store,
../../waku/v2/node/wakunode2,
../test_helpers, ./utils,

View File

@ -10,7 +10,8 @@ import
libp2p/protocols/pubsub/pubsub,
libp2p/peerinfo,
libp2p/standard_setup,
../protocol/[waku_relay, waku_store, waku_filter, waku_swap, message_notifier],
../protocol/[waku_relay, waku_store, waku_filter, message_notifier],
../protocol/waku_swap/waku_swap,
../waku_types,
./message_store

View File

@ -9,6 +9,7 @@ import
libp2p/stream/connection,
./message_notifier,
../node/message_store,
waku_swap/waku_swap,
../waku_types
logScope:

View File

@ -30,10 +30,10 @@ import
libp2p/protocols/protocol,
libp2p/protobuf/minprotobuf,
libp2p/stream/connection,
./message_notifier,
../waku_types
../message_notifier,
waku_swap_types
export waku_types
export waku_swap_types
logScope:
topics = "wakuswap"

View File

@ -0,0 +1,28 @@
import
std/tables,
bearssl,
libp2p/protocols/protocol,
libp2p/switch,
libp2p/peerinfo
type
Beneficiary* = seq[byte]
# TODO Consider adding payment threshhold and terms field
Handshake* = object
beneficiary*: Beneficiary
Cheque* = object
beneficiary*: Beneficiary
date*: uint32
amount*: uint32
AccountHandler* = proc (peerId: PeerId, amount: int) {.gcsafe, closure.}
WakuSwap* = ref object of LPProtocol
switch*: Switch
rng*: ref BrHmacDrbgContext
#peers*: seq[PeerInfo]
text*: string
accounting*: Table[PeerId, int]
accountFor*: AccountHandler

View File

@ -11,6 +11,7 @@ import
libp2p/switch,
libp2p/stream/connection,
libp2p/protocols/pubsub/[pubsub, gossipsub],
protocol/waku_swap/waku_swap_types,
nimcrypto/sha2,
sqlite3_abi
@ -40,7 +41,6 @@ type
QueryHandlerFunc* = proc(response: HistoryResponse) {.gcsafe, closure.}
Index* = object
## This type contains the description of an Index used in the pagination of WakuMessages
digest*: MDigest[256]
@ -134,16 +134,6 @@ type
# @TODO MAYBE MORE INFO?
Filters* = Table[string, Filter]
AccountHandler* = proc (peerId: PeerId, amount: int) {.gcsafe, closure.}
WakuSwap* = ref object of LPProtocol
switch*: Switch
rng*: ref BrHmacDrbgContext
#peers*: seq[PeerInfo]
text*: string
accounting*: Table[PeerId, int]
accountFor*: AccountHandler
# NOTE based on Eth2Node in NBC eth2_network.nim
WakuNode* = ref object of RootObj
switch*: Switch
@ -169,20 +159,6 @@ type
WakuResult*[T] = Result[T, cstring]
Beneficiary* = seq[byte]
# TODO Consider adding payment threshhold and terms field
Handshake* = object
beneficiary*: Beneficiary
Cheque* = object
beneficiary*: Beneficiary
date*: uint32
amount*: uint32
AccountUpdateFunc* = proc(peerId: PeerId, amount: int) {.gcsafe.}
# Encoding and decoding -------------------------------------------------------
# TODO Move out to to waku_message module
# Possibly same with util functions