Broadcast payment

This commit is contained in:
Mark Spanbroek 2021-04-08 10:33:40 +02:00 committed by markspanbroek
parent 6e7220efbb
commit 0897e615e6
2 changed files with 22 additions and 0 deletions

View File

@ -217,6 +217,15 @@ proc broadcastPricing*(network: BitswapNetwork,
let message = Message(pricing: PricingMessage.init(pricing))
asyncSpawn network.peers[id].send(message)
proc broadcastPayment*(network: BitswapNetwork,
id: PeerId,
payment: SignedState) =
if id notin network.peers:
return
let message = Message(payment: StateChannelUpdate.init(payment))
asyncSpawn network.peers[id].send(message)
proc handlePayment(network: BitswapNetwork,
peer: NetworkPeer,
payment: SignedState) =

View File

@ -238,3 +238,16 @@ suite "Bitswap Network - e2e":
network1.broadcastPricing(switch2.peerInfo.peerId, pricing)
await done.wait(100.millis)
test "broadcasts payment":
let payment = SignedState.example
proc handlePayment(peer: PeerID, received: SignedState) =
check received == payment
done.complete()
network2.handlers.onPayment = handlePayment
network1.broadcastPayment(switch2.peerInfo.peerId, payment)
await done.wait(100.millis)